< prev index next >

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

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

*** 21,33 **** * 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. */ --- 21,38 ---- * questions. */ import java.io.*; import java.nio.charset.Charset; import java.text.MessageFormat; + import java.util.*; + 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 --- 42,54 ---- 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 --- 333,349 ---- 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 = ""; --- 368,382 ---- 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 **** --- 480,491 ---- } } 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) { --- 523,532 ----
*** 531,542 **** break; } } } } } - updateLastModifiedTime(dirs); } ZipEntry extractFile(InputStream is, ZipEntry e) throws IOException { ZipEntry rc = null; String name = e.getName(); --- 535,546 ---- 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); } } - --- 729,744 ---- 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 >