jdk/test/jdk/nio/zipfs/ZipFSTester.java
changeset 27565 729f9700483a
parent 27260 8d82d0e9556b
child 28561 bdb3c1d3a975
equal deleted inserted replaced
27564:eaaa79b68cd5 27565:729f9700483a
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 import java.io.*;
    24 import java.io.File;
    25 import java.nio.*;
    25 import java.io.IOException;
    26 import java.nio.channels.*;
    26 import java.io.InputStream;
    27 import java.nio.file.*;
    27 import java.io.OutputStream;
    28 import java.nio.file.spi.*;
    28 import java.net.URI;
    29 import java.nio.file.attribute.*;
    29 import java.nio.ByteBuffer;
    30 import java.net.*;
    30 import java.nio.channels.FileChannel;
    31 import java.util.*;
    31 import java.nio.channels.SeekableByteChannel;
       
    32 import java.nio.file.DirectoryStream;
       
    33 import java.nio.file.FileAlreadyExistsException;
       
    34 import java.nio.file.FileSystem;
       
    35 import java.nio.file.FileSystemAlreadyExistsException;
       
    36 import java.nio.file.FileSystemException;
       
    37 import java.nio.file.FileSystems;
       
    38 import java.nio.file.FileVisitResult;
       
    39 import java.nio.file.Files;
       
    40 import java.nio.file.OpenOption;
       
    41 import java.nio.file.Path;
       
    42 import java.nio.file.Paths;
       
    43 import java.nio.file.SimpleFileVisitor;
       
    44 import java.nio.file.attribute.BasicFileAttributeView;
       
    45 import java.nio.file.attribute.BasicFileAttributes;
       
    46 import java.nio.file.spi.FileSystemProvider;
       
    47 import java.util.ArrayList;
       
    48 import java.util.Collections;
       
    49 import java.util.Enumeration;
       
    50 import java.util.HashMap;
       
    51 import java.util.HashSet;
       
    52 import java.util.Iterator;
       
    53 import java.util.LinkedList;
       
    54 import java.util.List;
       
    55 import java.util.Map;
       
    56 import java.util.Random;
       
    57 import java.util.Set;
    32 import java.util.concurrent.TimeUnit;
    58 import java.util.concurrent.TimeUnit;
    33 import java.util.zip.*;
    59 import java.util.zip.ZipEntry;
       
    60 import java.util.zip.ZipFile;
    34 
    61 
    35 import static java.nio.file.StandardOpenOption.*;
    62 import static java.nio.file.StandardOpenOption.*;
    36 import static java.nio.file.StandardCopyOption.*;
    63 import static java.nio.file.StandardCopyOption.*;
    37 
    64 
    38 /*
    65 /*
    46  * @run main/othervm/java.security.policy=test.policy ZipFSTester
    73  * @run main/othervm/java.security.policy=test.policy ZipFSTester
    47  */
    74  */
    48 
    75 
    49 public class ZipFSTester {
    76 public class ZipFSTester {
    50 
    77 
    51     public static void main(String[] args) throws Throwable {
    78     public static void main(String[] args) throws Exception {
    52         try (FileSystem fs = newZipFileSystem(
    79 
    53                  Paths.get(System.getProperty("test.jdk"), "jre/lib/ext/zipfs.jar"),
    80         // create JAR file for test, actual contents don't matter
    54                  new HashMap<String, Object>()))
    81         Path jarFile = Utils.createJarFile("tester.jar",
    55         {
    82                 "META-INF/MANIFEST.MF",
       
    83                 "dir1/foo",
       
    84                 "dir2/bar");
       
    85 
       
    86         try (FileSystem fs = newZipFileSystem(jarFile, Collections.emptyMap())) {
    56             test0(fs);
    87             test0(fs);
    57             test1(fs);
    88             test1(fs);
    58             test2(fs);   // more tests
    89             test2(fs);   // more tests
    59         }
    90         }
    60         testTime(Paths.get(System.getProperty("test.jdk"), "jre/lib/ext/zipfs.jar"));
    91         testTime(jarFile);
    61     }
    92     }
    62 
    93 
    63     static void test0(FileSystem fs)
    94     static void test0(FileSystem fs)
    64         throws Exception
    95         throws Exception
    65     {
    96     {
   100             try (FileSystem fsPath = provider.newFileSystem(tmpfsPath, new HashMap<String, Object>())){}
   131             try (FileSystem fsPath = provider.newFileSystem(tmpfsPath, new HashMap<String, Object>())){}
   101             try (FileSystem fsUri = provider.newFileSystem(
   132             try (FileSystem fsUri = provider.newFileSystem(
   102                      new URI("jar", tmpfsPath.toUri().toString(), null),
   133                      new URI("jar", tmpfsPath.toUri().toString(), null),
   103                      new HashMap<String, Object>()))
   134                      new HashMap<String, Object>()))
   104             {
   135             {
   105               throw new RuntimeException("newFileSystem(uri...) does not throw exception");
   136                 throw new RuntimeException("newFileSystem(URI...) does not throw exception");
   106             } catch (FileSystemAlreadyExistsException fsaee) {}
   137             } catch (FileSystemAlreadyExistsException fsaee) {}
   107 
   138 
   108             // prepare a src
   139             // prepare a src
   109             Path src = getTempPath();
   140             Path src = getTempPath();
   110             String tmpName = src.toString();
   141             String tmpName = src.toString();