< prev index next >

test/jdk/java/util/zip/zip.java

Print this page
rev 53034 : 8215472: Cleanups in implementation classes of jdk.zipfs and tests

*** 19,33 **** * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ ! import java.io.*; import java.nio.charset.Charset; - import java.util.*; - import java.util.zip.*; import java.text.MessageFormat; /** * A stripped-down version of Jar tool with a "-encoding" option to * support non-UTF8 encoidng for entry name and comment. */ --- 19,62 ---- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ ! import java.io.BufferedInputStream; ! import java.io.BufferedOutputStream; ! import java.io.BufferedReader; ! import java.io.File; ! import java.io.FileDescriptor; ! import java.io.FileInputStream; ! import java.io.FileNotFoundException; ! import java.io.FileOutputStream; ! import java.io.FileReader; ! import java.io.IOException; ! import java.io.InputStream; ! import java.io.OutputStream; ! import java.io.PrintStream; ! import java.io.Reader; ! import java.io.StreamTokenizer; import java.nio.charset.Charset; import java.text.MessageFormat; + import java.util.ArrayList; + import java.util.Date; + import java.util.Enumeration; + import java.util.HashMap; + import java.util.HashSet; + import java.util.LinkedHashSet; + import java.util.List; + import java.util.Map; + import java.util.MissingResourceException; + import java.util.ResourceBundle; + import java.util.Set; + import java.util.zip.CRC32; + import java.util.zip.ZipEntry; + import java.util.zip.ZipException; + import java.util.zip.ZipFile; + import java.util.zip.ZipInputStream; + import java.util.zip.ZipOutputStream; /** * A stripped-down version of Jar tool with a "-encoding" option to * support non-UTF8 encoidng for entry name and comment. */
*** 37,49 **** String fname; String zname = ""; String[] files; Charset cs = Charset.forName("UTF-8"); ! Map<String, File> entryMap = new HashMap<String, File>(); ! Set<File> entries = new LinkedHashSet<File>(); ! List<String> paths = new ArrayList<String>(); CRC32 crc32 = new CRC32(); /* * cflag: create * uflag: update --- 66,78 ---- String fname; String zname = ""; String[] files; Charset cs = Charset.forName("UTF-8"); ! Map<String, File> entryMap = new HashMap<>(); ! Set<File> entries = new LinkedHashSet<>(); ! List<String> paths = new ArrayList<>(); CRC32 crc32 = new CRC32(); /* * cflag: create * uflag: update
*** 328,346 **** addFile(zos, file); } } } ! boolean update(InputStream in, OutputStream out) throws IOException ! { try (ZipInputStream zis = new ZipInputStream(in, cs); ZipOutputStream zos = new ZipOutputStream(out, cs)) { ZipEntry e = null; byte[] buf = new byte[1024]; int n = 0; - boolean updateOk = true; // put the old entries first, replace if necessary while ((e = zis.getNextEntry()) != null) { String name = e.getName(); if (!entryMap.containsKey(name)) { // copy the old stuff --- 357,373 ---- addFile(zos, file); } } } ! boolean update(InputStream in, OutputStream out) throws IOException { try (ZipInputStream zis = new ZipInputStream(in, cs); ZipOutputStream zos = new ZipOutputStream(out, cs)) { ZipEntry e = null; byte[] buf = new byte[1024]; int n = 0; // put the old entries first, replace if necessary while ((e = zis.getNextEntry()) != null) { String name = e.getName(); if (!entryMap.containsKey(name)) { // copy the old stuff
*** 365,379 **** entries.remove(f); } } // add the remaining new files ! for (File f: entries) { addFile(zos, f); } } ! return updateOk; } private String entryName(String name) { name = name.replace(File.separatorChar, '/'); String matchPath = ""; --- 392,406 ---- entries.remove(f); } } // add the remaining new files ! for (File f : entries) { addFile(zos, f); } } ! return true; } private String entryName(String name) { name = name.replace(File.separatorChar, '/'); String matchPath = "";
*** 477,486 **** --- 504,515 ---- } } Set<ZipEntry> newDirSet() { return new HashSet<ZipEntry>() { + private static final long serialVersionUID = 4547977575248028254L; + public boolean add(ZipEntry e) { return (e == null || super.add(e)); }}; }
*** 518,528 **** try (ZipFile zf = new ZipFile(fname, cs)) { Set<ZipEntry> dirs = newDirSet(); Enumeration<? extends ZipEntry> zes = zf.entries(); while (zes.hasMoreElements()) { ZipEntry e = zes.nextElement(); - InputStream is; if (files == null) { dirs.add(extractFile(zf.getInputStream(e), e)); } else { String name = e.getName(); for (String file : files) { --- 547,556 ----
*** 531,542 **** break; } } } } } - updateLastModifiedTime(dirs); } ZipEntry extractFile(InputStream is, ZipEntry e) throws IOException { ZipEntry rc = null; String name = e.getName(); --- 559,570 ---- break; } } } } + updateLastModifiedTime(dirs); } } ZipEntry extractFile(InputStream is, ZipEntry e) throws IOException { ZipEntry rc = null; String name = e.getName();
*** 725,741 **** st.wordChars(' ', 255); st.whitespaceChars(0, ' '); st.commentChar('#'); st.quoteChar('"'); st.quoteChar('\''); ! while (st.nextToken() != st.TT_EOF) { args.add(st.sval); } r.close(); } public static void main(String args[]) { zip z = new zip(System.out, System.err, "zip"); System.exit(z.run(args) ? 0 : 1); } } - --- 753,768 ---- st.wordChars(' ', 255); st.whitespaceChars(0, ' '); st.commentChar('#'); st.quoteChar('"'); st.quoteChar('\''); ! while (st.nextToken() != StreamTokenizer.TT_EOF) { args.add(st.sval); } r.close(); } public static void main(String args[]) { zip z = new zip(System.out, System.err, "zip"); System.exit(z.run(args) ? 0 : 1); } }
< prev index next >