< 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,15 +19,44 @@
  * 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.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.util.*;
-import java.util.zip.*;
 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,13 +66,13 @@
     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>();
+    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,19 +357,17 @@
                 addFile(zos, file);
             }
         }
     }
 
-    boolean update(InputStream in, OutputStream out) throws IOException
-    {
+    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

@@ -365,15 +392,15 @@
                     entries.remove(f);
                 }
             }
 
             // add the remaining new files
-            for (File f: entries) {
+            for (File f : entries) {
                 addFile(zos, f);
             }
         }
-        return updateOk;
+        return true;
     }
 
     private String entryName(String name) {
         name = name.replace(File.separatorChar, '/');
         String matchPath = "";

@@ -477,10 +504,12 @@
         }
     }
 
     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,11 +547,10 @@
         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) {

@@ -531,12 +559,12 @@
                             break;
                         }
                     }
                 }
             }
+            updateLastModifiedTime(dirs);
         }
-        updateLastModifiedTime(dirs);
     }
 
     ZipEntry extractFile(InputStream is, ZipEntry e) throws IOException {
         ZipEntry rc = null;
         String name = e.getName();

@@ -725,17 +753,16 @@
         st.wordChars(' ', 255);
         st.whitespaceChars(0, ' ');
         st.commentChar('#');
         st.quoteChar('"');
         st.quoteChar('\'');
-        while (st.nextToken() != st.TT_EOF) {
+        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 >