< 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,13 +21,18 @@
* questions.
*/
import java.io.*;
import java.nio.charset.Charset;
-import java.util.*;
-import java.util.zip.*;
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,13 +42,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 +333,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 +368,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 +480,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 +523,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 +535,12 @@
break;
}
}
}
}
+ updateLastModifiedTime(dirs);
}
- updateLastModifiedTime(dirs);
}
ZipEntry extractFile(InputStream is, ZipEntry e) throws IOException {
ZipEntry rc = null;
String name = e.getName();
@@ -725,17 +729,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 >