jdk/test/demo/zipfs/ZipFSTester.java
changeset 8005 5bc99c45810a
parent 7531 77870839c857
child 8165 b67d8b1f4e46
equal deleted inserted replaced
8004:11f3cdd5c639 8005:5bc99c45810a
    26 import java.nio.channels.*;
    26 import java.nio.channels.*;
    27 import java.nio.file.*;
    27 import java.nio.file.*;
    28 import java.nio.file.attribute.*;
    28 import java.nio.file.attribute.*;
    29 import java.net.*;
    29 import java.net.*;
    30 import java.util.*;
    30 import java.util.*;
       
    31 import java.util.zip.*;
    31 
    32 
    32 import static java.nio.file.StandardOpenOption.*;
    33 import static java.nio.file.StandardOpenOption.*;
    33 import static java.nio.file.StandardCopyOption.*;
    34 import static java.nio.file.StandardCopyOption.*;
    34 
    35 
    35 /*
    36 /*
    40 
    41 
    41     public static void main(String[] args) throws Throwable {
    42     public static void main(String[] args) throws Throwable {
    42         FileSystem fs = null;
    43         FileSystem fs = null;
    43         try {
    44         try {
    44             fs = newZipFileSystem(Paths.get(args[0]), new HashMap<String, Object>());
    45             fs = newZipFileSystem(Paths.get(args[0]), new HashMap<String, Object>());
    45             test(fs);
    46             test0(fs);
       
    47             test1(fs);
    46             test2(fs);   // more tests
    48             test2(fs);   // more tests
    47         } finally {
    49         } finally {
    48             if (fs != null)
    50             if (fs != null)
    49                 fs.close();
    51                 fs.close();
    50         }
    52         }
    51     }
    53     }
    52 
    54 
    53     static void test(FileSystem fs)
    55     static void test0(FileSystem fs)
    54         throws Exception
    56         throws Exception
    55     {
    57     {
       
    58         List<String> list = new LinkedList<>();
       
    59         try (ZipFile zf = new ZipFile(fs.toString())) {
       
    60             Enumeration<? extends ZipEntry> zes = zf.entries();
       
    61             while (zes.hasMoreElements()) {
       
    62                 list.add(zes.nextElement().getName());
       
    63             }
       
    64             for (String pname : list) {
       
    65                 Path path = fs.getPath(pname);
       
    66                 if (!path.exists())
       
    67                     throw new RuntimeException("path existence check failed!");
       
    68                 while ((path = path.getParent()) != null) {
       
    69                     if (!path.exists())
       
    70                         throw new RuntimeException("parent existence check failed!");
       
    71                 }
       
    72             }
       
    73         }
       
    74     }
       
    75 
       
    76     static void test1(FileSystem fs)
       
    77         throws Exception
       
    78     {
    56         Random rdm = new Random();
    79         Random rdm = new Random();
    57 
       
    58         // clone a fs and test on it
    80         // clone a fs and test on it
    59         Path tmpfsPath = getTempPath();
    81         Path tmpfsPath = getTempPath();
    60         Map<String, Object> env = new HashMap<String, Object>();
    82         Map<String, Object> env = new HashMap<String, Object>();
    61         env.put("create", "true");
    83         env.put("create", "true");
    62         FileSystem fs0 = newZipFileSystem(tmpfsPath, env);
    84         FileSystem fs0 = newZipFileSystem(tmpfsPath, env);