# HG changeset patch # User clanger # Date 1545033677 0 # Mon Dec 17 08:01:17 2018 +0000 # Node ID 1017bb1182030915d3fe541bf72943d5b29515aa # Parent dcbb71b9e7c0d5294ab61e3bc34f2dea07388bdf 8215472: Cleanups in implementation classes of jdk.zipfs and tests diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/JarFileSystem.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/JarFileSystem.java --- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/JarFileSystem.java +++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/JarFileSystem.java @@ -48,7 +48,6 @@ * * @author Steve Drach */ - class JarFileSystem extends ZipFileSystem { private Function lookup; diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/JarFileSystemProvider.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/JarFileSystemProvider.java --- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/JarFileSystemProvider.java +++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/JarFileSystemProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,21 +25,13 @@ package jdk.nio.zipfs; -import java.nio.file.*; -import java.nio.file.spi.*; -import java.nio.file.attribute.*; -import java.nio.file.spi.FileSystemProvider; - import java.net.URI; -import java.io.IOException; import java.net.URISyntaxException; -import java.nio.channels.FileChannel; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; +import java.nio.file.FileSystem; +import java.nio.file.Path; +import java.nio.file.Paths; -class JarFileSystemProvider extends ZipFileSystemProvider -{ +class JarFileSystemProvider extends ZipFileSystemProvider { @Override public String getScheme() { diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipCoder.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipCoder.java --- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipCoder.java +++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipCoder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,6 +25,9 @@ package jdk.nio.zipfs; +import static java.nio.charset.StandardCharsets.ISO_8859_1; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; @@ -34,15 +37,11 @@ import java.nio.charset.CodingErrorAction; import java.util.Arrays; -import static java.nio.charset.StandardCharsets.UTF_8; -import static java.nio.charset.StandardCharsets.ISO_8859_1; - /** * Utility class for zipfile name and comment decoding and encoding * - * @author Xueming Shen + * @author Xueming Shen */ - class ZipCoder { static class UTF8 extends ZipCoder { diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipConstants.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipConstants.java --- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipConstants.java +++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipConstants.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,10 +26,8 @@ package jdk.nio.zipfs; /** - * * @author Xueming Shen */ - class ZipConstants { /* * Compression methods diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipDirectoryStream.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipDirectoryStream.java --- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipDirectoryStream.java +++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipDirectoryStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,19 +25,18 @@ package jdk.nio.zipfs; +import java.io.IOException; +import java.nio.file.ClosedDirectoryStreamException; import java.nio.file.DirectoryStream; -import java.nio.file.ClosedDirectoryStreamException; import java.nio.file.NotDirectoryException; import java.nio.file.Path; import java.util.Iterator; import java.util.NoSuchElementException; -import java.io.IOException; /** * - * @author Xueming Shen, Rajendra Gutupalli, Jaya Hangal + * @author Xueming Shen, Rajendra Gutupalli, Jaya Hangal */ - class ZipDirectoryStream implements DirectoryStream { private final ZipFileSystem zipfs; @@ -70,8 +69,8 @@ } catch (IOException e) { throw new IllegalStateException(e); } + return new Iterator() { - private Path next; @Override public boolean hasNext() { if (isClosed) @@ -97,5 +96,4 @@ public synchronized void close() throws IOException { isClosed = true; } - } diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileAttributeView.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileAttributeView.java --- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileAttributeView.java +++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileAttributeView.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,17 +25,17 @@ package jdk.nio.zipfs; -import java.nio.file.attribute.*; import java.io.IOException; +import java.nio.file.attribute.BasicFileAttributeView; +import java.nio.file.attribute.FileAttributeView; +import java.nio.file.attribute.FileTime; import java.util.LinkedHashMap; import java.util.Map; -/* - * @author Xueming Shen, Rajendra Gutupalli, Jaya Hangal +/** + * @author Xueming Shen, Rajendra Gutupalli, Jaya Hangal */ - -class ZipFileAttributeView implements BasicFileAttributeView -{ +class ZipFileAttributeView implements BasicFileAttributeView { private static enum AttrID { size, creationTime, @@ -85,8 +85,7 @@ return isZipView ? "zip" : "basic"; } - public ZipFileAttributes readAttributes() throws IOException - { + public ZipFileAttributes readAttributes() throws IOException { return path.getAttributes(); } @@ -104,11 +103,11 @@ { try { if (AttrID.valueOf(attribute) == AttrID.lastModifiedTime) - setTimes ((FileTime)value, null, null); + setTimes((FileTime)value, null, null); if (AttrID.valueOf(attribute) == AttrID.lastAccessTime) - setTimes (null, (FileTime)value, null); + setTimes(null, (FileTime)value, null); if (AttrID.valueOf(attribute) == AttrID.creationTime) - setTimes (null, null, (FileTime)value); + setTimes(null, null, (FileTime)value); return; } catch (IllegalArgumentException x) {} throw new UnsupportedOperationException("'" + attribute + diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileAttributes.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileAttributes.java --- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileAttributes.java +++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileAttributes.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,10 +28,10 @@ import java.nio.file.attribute.BasicFileAttributes; /** + * The attributes of a file stored in a zip file. * - * @author Xueming Shen, Rajendra Gutupalli,Jaya Hangal + * @author Xueming Shen, Rajendra Gutupalli,Jaya Hangal */ - interface ZipFileAttributes extends BasicFileAttributes { public long compressedSize(); public long crc(); diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileStore.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileStore.java --- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileStore.java +++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileStore.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,21 +26,17 @@ package jdk.nio.zipfs; import java.io.IOException; -import java.nio.file.Files; import java.nio.file.FileStore; import java.nio.file.FileSystems; +import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.attribute.BasicFileAttributes; +import java.nio.file.attribute.BasicFileAttributeView; import java.nio.file.attribute.FileAttributeView; import java.nio.file.attribute.FileStoreAttributeView; -import java.nio.file.attribute.BasicFileAttributeView; -import java.util.Formatter; -/* - * - * @author Xueming Shen, Rajendra Gutupalli, Jaya Hangal +/** + * @author Xueming Shen, Rajendra Gutupalli, Jaya Hangal */ - class ZipFileStore extends FileStore { private final ZipFileSystem zfs; @@ -76,7 +72,6 @@ } @Override - @SuppressWarnings("unchecked") public V getFileStoreAttributeView(Class type) { if (type == null) throw new NullPointerException(); diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java --- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java +++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,49 +25,63 @@ package jdk.nio.zipfs; +import static java.lang.Boolean.TRUE; +import static jdk.nio.zipfs.ZipConstants.*; +import static jdk.nio.zipfs.ZipUtils.*; +import static java.nio.file.StandardOpenOption.*; +import static java.nio.file.StandardCopyOption.*; + import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.EOFException; -import java.io.File; import java.io.FilterOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.ByteBuffer; import java.nio.MappedByteBuffer; -import java.nio.channels.*; +import java.nio.channels.FileChannel; +import java.nio.channels.FileLock; +import java.nio.channels.ReadableByteChannel; +import java.nio.channels.SeekableByteChannel; +import java.nio.channels.WritableByteChannel; import java.nio.file.*; -import java.nio.file.attribute.*; -import java.nio.file.spi.*; +import java.nio.file.attribute.FileAttribute; +import java.nio.file.attribute.FileTime; +import java.nio.file.attribute.UserPrincipalLookupService; +import java.nio.file.spi.FileSystemProvider; import java.security.AccessController; import java.security.PrivilegedAction; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Formatter; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.regex.Pattern; import java.util.zip.CRC32; +import java.util.zip.Deflater; +import java.util.zip.DeflaterOutputStream; import java.util.zip.Inflater; -import java.util.zip.Deflater; import java.util.zip.InflaterInputStream; -import java.util.zip.DeflaterOutputStream; import java.util.zip.ZipException; -import static java.lang.Boolean.*; -import static jdk.nio.zipfs.ZipConstants.*; -import static jdk.nio.zipfs.ZipUtils.*; -import static java.nio.file.StandardOpenOption.*; -import static java.nio.file.StandardCopyOption.*; /** * A FileSystem built on a zip file * * @author Xueming Shen */ - class ZipFileSystem extends FileSystem { - private final ZipFileSystemProvider provider; private final Path zfpath; final ZipCoder zc; @@ -79,15 +93,15 @@ private final boolean useTempFile; // use a temp file for newOS, default // is to use BAOS for better performance private static final boolean isWindows = AccessController.doPrivileged( - (PrivilegedAction) () -> System.getProperty("os.name") - .startsWith("Windows")); + (PrivilegedAction)() -> System.getProperty("os.name") + .startsWith("Windows")); private final boolean forceEnd64; private final int defaultMethod; // METHOD_STORED if "noCompression=true" // METHOD_DEFLATED otherwise ZipFileSystem(ZipFileSystemProvider provider, Path zfpath, - Map env) throws IOException + Map env) throws IOException { // default encoding for name/comment String nameEncoding = env.containsKey("encoding") ? @@ -269,12 +283,12 @@ } if (!streams.isEmpty()) { // unlock and close all remaining streams Set copy = new HashSet<>(streams); - for (InputStream is: copy) + for (InputStream is : copy) is.close(); } beginWrite(); // lock and sync try { - AccessController.doPrivileged((PrivilegedExceptionAction) () -> { + AccessController.doPrivileged((PrivilegedExceptionAction)() -> { sync(); return null; }); ch.close(); // close the ch just in case no update @@ -296,7 +310,7 @@ IOException ioe = null; synchronized (tmppaths) { - for (Path p: tmppaths) { + for (Path p : tmppaths) { try { AccessController.doPrivileged( (PrivilegedExceptionAction)() -> Files.deleteIfExists(p)); @@ -521,7 +535,7 @@ boolean hasCreate = false; boolean hasAppend = false; boolean hasTruncate = false; - for (OpenOption opt: options) { + for (OpenOption opt : options) { if (opt == READ) throw new IllegalArgumentException("READ not allowed"); if (opt == CREATE_NEW) @@ -1477,7 +1491,7 @@ // TBD: wrap to hook close() // streams.add(eis); return eis; - } else { // untouced CEN or COPY + } else { // untouched CEN or COPY eis = new EntryInputStream(e, ch); } if (e.method == METHOD_DEFLATED) { @@ -1539,14 +1553,12 @@ // point to a new channel after sync() private long pos; // current position within entry data protected long rem; // number of remaining bytes within entry - protected final long size; // uncompressed size of this entry EntryInputStream(Entry e, SeekableByteChannel zfch) throws IOException { this.zfch = zfch; rem = e.csize; - size = e.size; pos = e.locoff; if (pos == -1) { Entry e2 = getEntry(e.name); @@ -1613,10 +1625,6 @@ return rem > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) rem; } - public long size() { - return size; - } - public void close() { rem = 0; streams.remove(this); @@ -1672,7 +1680,7 @@ // List of available Deflater objects for compression private final List deflaters = new ArrayList<>(); - // Gets an deflater from the list of available deflaters or allocates + // Gets a deflater from the list of available deflaters or allocates // a new one. private Deflater getDeflater() { synchronized (deflaters) { @@ -1686,18 +1694,6 @@ } } - // Releases the specified inflater to the list of available inflaters. - private void releaseDeflater(Deflater def) { - synchronized (deflaters) { - if (inflaters.size() < MAX_FLATER) { - def.reset(); - deflaters.add(def); - } else { - def.end(); - } - } - } - // End of central directory record static class END { // these 2 fields are not used by anyone and write() uses "0" @@ -1985,9 +1981,7 @@ return this; } - int writeCEN(OutputStream os) throws IOException - { - int written = CENHDR; + int writeCEN(OutputStream os) throws IOException { int version0 = version(); long csize0 = csize; long size0 = size; @@ -2102,8 +2096,6 @@ int writeLOC(OutputStream os) throws IOException { writeInt(os, LOCSIG); // LOC header signature - int version = version(); - byte[] zname = isdir ? toDirectoryPath(name) : name; int nlen = (zname != null) ? zname.length - 1 : 0; // [0] is slash int elen = (extra != null) ? extra.length : 0; @@ -2430,7 +2422,6 @@ // structure. // A possible solution is to build the node tree ourself as // implemented below. - private IndexNode root; // default time stamp for pseudo entries private long zfsDefaultTimeStamp = System.currentTimeMillis(); diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystemProvider.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystemProvider.java --- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystemProvider.java +++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystemProvider.java @@ -25,28 +25,43 @@ package jdk.nio.zipfs; -import java.io.*; -import java.nio.channels.*; -import java.nio.file.*; -import java.nio.file.DirectoryStream.Filter; -import java.nio.file.attribute.*; -import java.nio.file.spi.FileSystemProvider; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.net.URI; import java.net.URISyntaxException; +import java.nio.channels.AsynchronousFileChannel; +import java.nio.channels.FileChannel; +import java.nio.channels.SeekableByteChannel; +import java.nio.file.AccessMode; +import java.nio.file.CopyOption; +import java.nio.file.DirectoryStream; +import java.nio.file.DirectoryStream.Filter; +import java.nio.file.FileStore; +import java.nio.file.FileSystem; +import java.nio.file.FileSystemAlreadyExistsException; +import java.nio.file.FileSystemNotFoundException; +import java.nio.file.Files; +import java.nio.file.LinkOption; +import java.nio.file.OpenOption; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.ProviderMismatchException; +import java.nio.file.attribute.BasicFileAttributes; +import java.nio.file.attribute.FileAttribute; +import java.nio.file.attribute.FileAttributeView; +import java.nio.file.spi.FileSystemProvider; import java.util.HashMap; import java.util.Map; import java.util.Set; +import java.util.concurrent.ExecutorService; import java.util.zip.ZipException; -import java.util.concurrent.ExecutorService; -/* - * - * @author Xueming Shen, Rajendra Gutupalli, Jaya Hangal +/** + * @author Xueming Shen, Rajendra Gutupalli, Jaya Hangal */ - public class ZipFileSystemProvider extends FileSystemProvider { - private final Map filesystems = new HashMap<>(); public ZipFileSystemProvider() {} @@ -202,7 +217,6 @@ } @Override - @SuppressWarnings("unchecked") public V getFileAttributeView(Path path, Class type, LinkOption... options) { diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipInfo.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipInfo.java --- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipInfo.java +++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,18 +25,20 @@ package jdk.nio.zipfs; +import static jdk.nio.zipfs.ZipConstants.*; +import static jdk.nio.zipfs.ZipUtils.dosToJavaTime; +import static jdk.nio.zipfs.ZipUtils.unixToJavaTime; +import static jdk.nio.zipfs.ZipUtils.winToJavaTime; + import java.nio.file.Paths; import java.util.Collections; import java.util.Map; -import static jdk.nio.zipfs.ZipConstants.*; -import static jdk.nio.zipfs.ZipUtils.*; /** * Print all loc and cen headers of the ZIP file * - * @author Xueming Shen + * @author Xueming Shen */ - public class ZipInfo { public static void main(String[] args) throws Throwable { diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipPath.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipPath.java --- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipPath.java +++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipPath.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,22 +25,53 @@ package jdk.nio.zipfs; -import java.io.*; +import static java.nio.charset.StandardCharsets.UTF_8; +import static java.nio.file.StandardCopyOption.COPY_ATTRIBUTES; +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static java.nio.file.StandardOpenOption.CREATE; +import static java.nio.file.StandardOpenOption.READ; +import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING; +import static java.nio.file.StandardOpenOption.WRITE; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.net.URI; -import java.nio.channels.*; -import java.nio.file.*; +import java.nio.channels.FileChannel; +import java.nio.channels.SeekableByteChannel; +import java.nio.file.AccessDeniedException; +import java.nio.file.AccessMode; +import java.nio.file.CopyOption; +import java.nio.file.DirectoryNotEmptyException; +import java.nio.file.DirectoryStream; import java.nio.file.DirectoryStream.Filter; -import java.nio.file.attribute.*; -import java.util.*; -import static java.nio.charset.StandardCharsets.UTF_8; -import static java.nio.file.StandardOpenOption.*; -import static java.nio.file.StandardCopyOption.*; +import java.nio.file.FileAlreadyExistsException; +import java.nio.file.FileStore; +import java.nio.file.Files; +import java.nio.file.InvalidPathException; +import java.nio.file.LinkOption; +import java.nio.file.NoSuchFileException; +import java.nio.file.OpenOption; +import java.nio.file.Path; +import java.nio.file.ProviderMismatchException; +import java.nio.file.ReadOnlyFileSystemException; +import java.nio.file.WatchEvent; +import java.nio.file.WatchKey; +import java.nio.file.WatchService; +import java.nio.file.attribute.BasicFileAttributeView; +import java.nio.file.attribute.FileAttribute; +import java.nio.file.attribute.FileTime; +import java.util.Arrays; +import java.util.Iterator; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; /** - * - * @author Xueming Shen, Rajendra Gutupalli,Jaya Hangal + * @author Xueming Shen, Rajendra Gutupalli,Jaya Hangal */ - final class ZipPath implements Path { private final ZipFileSystem zfs; @@ -522,7 +553,6 @@ private byte[] normalize(String path, int off, int len) { StringBuilder to = new StringBuilder(len); to.append(path, 0, off); - int m = off; char prevC = 0; while (off < len) { char c = path.charAt(off++); diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipUtils.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipUtils.java --- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipUtils.java +++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -33,14 +33,12 @@ import java.time.ZoneId; import java.util.Arrays; import java.util.Date; +import java.util.concurrent.TimeUnit; import java.util.regex.PatternSyntaxException; -import java.util.concurrent.TimeUnit; /** - * * @author Xueming Shen */ - class ZipUtils { /* @@ -155,7 +153,6 @@ ldt.getSecond() >> 1) & 0xffffffffL; } - // used to adjust values between Windows and java epoch private static final long WINDOWS_EPOCH_IN_MICROSECONDS = -11644473600000000L; public static final long winToJavaTime(long wtime) { diff --git a/test/jdk/java/util/zip/zip.java b/test/jdk/java/util/zip/zip.java --- a/test/jdk/java/util/zip/zip.java +++ b/test/jdk/java/util/zip/zip.java @@ -21,11 +21,40 @@ * 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 @@ -39,9 +68,9 @@ String[] files; Charset cs = Charset.forName("UTF-8"); - Map entryMap = new HashMap(); - Set entries = new LinkedHashSet(); - List paths = new ArrayList(); + Map entryMap = new HashMap<>(); + Set entries = new LinkedHashSet<>(); + List paths = new ArrayList<>(); CRC32 crc32 = new CRC32(); /* @@ -330,15 +359,13 @@ } } - 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) { @@ -367,11 +394,11 @@ } // 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) { @@ -479,6 +506,8 @@ Set newDirSet() { return new HashSet() { + private static final long serialVersionUID = 4547977575248028254L; + public boolean add(ZipEntry e) { return (e == null || super.add(e)); }}; @@ -520,7 +549,6 @@ Enumeration zes = zf.entries(); while (zes.hasMoreElements()) { ZipEntry e = zes.nextElement(); - InputStream is; if (files == null) { dirs.add(extractFile(zf.getInputStream(e), e)); } else { @@ -533,8 +561,8 @@ } } } + updateLastModifiedTime(dirs); } - updateLastModifiedTime(dirs); } ZipEntry extractFile(InputStream is, ZipEntry e) throws IOException { @@ -727,7 +755,7 @@ st.commentChar('#'); st.quoteChar('"'); st.quoteChar('\''); - while (st.nextToken() != st.TT_EOF) { + while (st.nextToken() != StreamTokenizer.TT_EOF) { args.add(st.sval); } r.close(); @@ -738,4 +766,3 @@ System.exit(z.run(args) ? 0 : 1); } } -