test/jdk/jdk/nio/zipfs/ZFSTests.java
author lancea
Tue, 29 Oct 2019 14:22:18 -0400
changeset 58845 e492513d3630
parent 51646 364863505019
permissions -rw-r--r--
8231766: Files.copy and Files.move do not honor requested compression method when copying or moving within the same zip file Reviewed-by: clanger, bpb, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12430
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
     1
/*
51638
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
     2
 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
12430
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
     4
 *
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
     7
 * published by the Free Software Foundation.
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
     8
 *
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    13
 * accompanied this code).
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    14
 *
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    18
 *
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    21
 * questions.
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    22
 */
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    23
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    24
/* @test
51646
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
    25
 * @bug 7156873 8040059 8028480 8034773 8153248 8061777 8197398 8210394
24364
da8afb112f5d 8040059: Change default policy for extensions to no permission
mchung
parents: 23925
diff changeset
    26
 * @summary ZipFileSystem regression tests
da8afb112f5d 8040059: Change default policy for extensions to no permission
mchung
parents: 23925
diff changeset
    27
 *
48768
ac007e4bbf4b 8178342: Missing @modules in jdk/jdk/nio/zipfs
shurailine
parents: 47216
diff changeset
    28
 * @modules jdk.zipfs
24364
da8afb112f5d 8040059: Change default policy for extensions to no permission
mchung
parents: 23925
diff changeset
    29
 * @run main ZFSTests
27260
8d82d0e9556b 8043277: Update jdk regression tests to extend the default security policy instead of override
mchung
parents: 24364
diff changeset
    30
 * @run main/othervm/java.security.policy=test.policy ZFSTests
12430
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    31
 */
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    32
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    33
51638
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    34
import java.io.IOException;
30811
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
    35
import java.io.OutputStream;
12430
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    36
import java.net.URI;
30811
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
    37
import java.nio.ByteBuffer;
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
    38
import java.nio.channels.*;
12430
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    39
import java.nio.file.*;
51638
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    40
import java.nio.file.attribute.BasicFileAttributes;
30811
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
    41
import java.nio.file.spi.*;
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
    42
import java.util.*;
51638
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    43
import java.util.concurrent.atomic.AtomicInteger;
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    44
import java.util.zip.ZipEntry;
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    45
import java.util.zip.ZipFile;
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    46
import java.util.zip.ZipOutputStream;
12430
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    47
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    48
public class ZFSTests {
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    49
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    50
    public static void main(String[] args) throws Throwable {
51638
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    51
        test8197398();
12430
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    52
        test7156873();
38769
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
    53
        test8061777();
38568
f992c34c85b3 8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents: 30811
diff changeset
    54
        tests();
12430
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    55
    }
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
    56
51638
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    57
    static void test8197398() throws Throwable {
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    58
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    59
        // root entry "/"
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    60
        Path path = Paths.get("rootdir.zip");
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    61
        URI uri = URI.create("jar:" + path.toUri());
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    62
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    63
        Set<String> dirs = new HashSet<>();
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    64
        Set<String> files = new HashSet<>();
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    65
        try (OutputStream os = Files.newOutputStream(path);
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    66
             ZipOutputStream zos = new ZipOutputStream(os)) {
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    67
            zos.putNextEntry(new ZipEntry("/"));     dirs.add("/");
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    68
            zos.putNextEntry(new ZipEntry("foo"));   files.add("/foo");
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    69
            zos.write("/foo".getBytes());
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    70
            zos.putNextEntry(new ZipEntry("bar"));   files.add("/bar");
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    71
            zos.write("/bar".getBytes());
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    72
        }
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    73
        AtomicInteger cnt = new AtomicInteger();
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    74
        int max = 3;
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    75
        try (FileSystem fs = FileSystems.newFileSystem(uri, Collections.emptyMap())) {
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    76
            Files.walkFileTree(fs.getRootDirectories().iterator().next(),
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    77
                                new SimpleFileVisitor<Path>() {
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    78
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    79
                @Override
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    80
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    81
                        throws IOException {
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    82
                    if (cnt.incrementAndGet() > max)
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    83
                        throw new RuntimeException("visited too many files/dirs");
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    84
                    files.remove(file.toString());
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    85
                    if (!Arrays.equals(Files.readAllBytes(file), file.toString().getBytes()))
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    86
                        throw new RuntimeException("visited files has wrong content: " + file);
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    87
                    return FileVisitResult.CONTINUE;
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    88
                }
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    89
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    90
                @Override
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    91
                public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    92
                        throws IOException {
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    93
                    if (cnt.incrementAndGet() > max)
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    94
                        throw new RuntimeException("visited too many files/dirs");
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    95
                    dirs.remove(dir.toString());
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    96
                    return FileVisitResult.CONTINUE;
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    97
                }
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    98
            });
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
    99
            if (cnt.get() != max || dirs.size() != 0 || files.size() != 0)
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
   100
                throw new RuntimeException("walk files/dirs failed");
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
   101
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
   102
        } finally {
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
   103
            Files.deleteIfExists(path);
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
   104
        }
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
   105
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
   106
        // absolute file/dir, no need to test cnt again..
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
   107
        dirs.clear();
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
   108
        files.clear();
51646
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   109
        try {
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   110
            try (OutputStream os = Files.newOutputStream(path);
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   111
                ZipOutputStream zos = new ZipOutputStream(os)) {
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   112
                zos.putNextEntry(new ZipEntry("/"));     dirs.add("/");
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   113
                zos.putNextEntry(new ZipEntry("/fooo/"));     dirs.add("/fooo");
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   114
                zos.putNextEntry(new ZipEntry("/foo"));   files.add("/foo");
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   115
                zos.write("/foo".getBytes());
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   116
                zos.putNextEntry(new ZipEntry("/bar"));   files.add("/bar");
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   117
                zos.write("/bar".getBytes());
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   118
                zos.putNextEntry(new ZipEntry("/fooo/bar"));   files.add("/fooo/bar");
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   119
                zos.write("/fooo/bar".getBytes());
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   120
            }
51638
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
   121
51646
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   122
            try (FileSystem fs = FileSystems.newFileSystem(uri, Collections.emptyMap())) {
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   123
                Files.walkFileTree(fs.getRootDirectories().iterator().next(),
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   124
                                    new SimpleFileVisitor<Path>() {
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   125
                    @Override
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   126
                    public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   127
                            throws IOException {
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   128
                        files.remove(file.toString());
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   129
                        if (!Arrays.equals(Files.readAllBytes(file), file.toString().getBytes()))
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   130
                            throw new RuntimeException("visited files has wrong content: " + file);
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   131
                        return FileVisitResult.CONTINUE;
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   132
                    }
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   133
                    @Override
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   134
                    public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   135
                            throws IOException {
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   136
                        dirs.remove(dir.toString());
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   137
                        return FileVisitResult.CONTINUE;
51638
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
   138
                    }
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
   139
                });
51646
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   140
                if (dirs.size() != 0 || files.size() != 0)
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   141
                    throw new RuntimeException("walk files/dirs failed");
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   142
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   143
                // for next test: updated any entry, the result zipfs file should have no
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   144
                // absolute path entry
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   145
                Files.write(fs.getPath("/foo"), "/foo".getBytes());
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   146
            }
51638
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
   147
51646
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   148
            // updated zfs should have the same dirs/files (path is not absolute though)
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   149
            dirs.add("/");
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   150
            dirs.add("/fooo");
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   151
            files.add("/foo");
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   152
            files.add("/bar");
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   153
            files.add("/fooo/bar");
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   154
            try (FileSystem fs = FileSystems.newFileSystem(uri, Collections.emptyMap())) {
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   155
                    Files.walk(fs.getPath("/")).forEach( p -> {
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   156
                        if (Files.isDirectory(p)) {
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   157
                            dirs.remove(p.toString());
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   158
                        } else {
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   159
                            files.remove(p.toString());
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   160
                            try {
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   161
                                if (!Arrays.equals(Files.readAllBytes(p), p.toString().getBytes()))
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   162
                                    throw new RuntimeException("visited files has wrong content: " + p);
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   163
                            } catch (IOException x) {
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   164
                                throw new RuntimeException(x);
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   165
                            }
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   166
                        }
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   167
                    });
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   168
                if (dirs.size() != 0 || files.size() != 0)
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   169
                    throw new RuntimeException("walk files/dirs failed");
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   170
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   171
            }
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   172
            // updated zip file should  not have "/" and entry with absolute path
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   173
            try (var zf = new ZipFile(path.toFile())) {
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   174
                String[] entries = zf.stream()
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   175
                                     .map(ZipEntry::toString)
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   176
                                     .sorted()
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   177
                                     .toArray(String[]::new);
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   178
                if (!Arrays.equals(entries, new String[] {"bar", "foo", "fooo/", "fooo/bar" })) {
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   179
                    System.out.println("unexpeded: " + Arrays.toString(entries));
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   180
                    throw new RuntimeException("unexpected entreis in updated zipfs file");
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   181
                }
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   182
            }
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   183
        } finally {
364863505019 8210394: (zipfs) jdk/nio/zipfs/ZFSTests.java rootdir.zip: The process cannot access the file because it is being used by another process
sherman
parents: 51638
diff changeset
   184
            Files.deleteIfExists(path);
51638
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
   185
        }
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
   186
    }
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
   187
12430
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
   188
    static void test7156873() throws Throwable {
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
   189
        String DIRWITHSPACE = "testdir with spaces";
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
   190
        Path dir = Paths.get(DIRWITHSPACE);
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
   191
        Path path = Paths.get(DIRWITHSPACE, "file.zip");
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
   192
        try {
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
   193
            Files.createDirectory(dir);
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
   194
            URI uri = URI.create("jar:" + path.toUri());
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
   195
            Map<String, Object> env = new HashMap<String, Object>();
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
   196
            env.put("create", "true");
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
   197
            try (FileSystem fs = FileSystems.newFileSystem(uri, env)) {}
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
   198
        } finally {
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
   199
            Files.deleteIfExists(path);
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
   200
            Files.deleteIfExists(dir);
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
   201
        }
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
   202
    }
30811
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   203
38769
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   204
    static void test8061777() throws Throwable {
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   205
        Path path = Paths.get("file.zip");
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   206
        try {
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   207
            URI uri = URI.create("jar:" + path.toUri());
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   208
            Map<String, Object> env = new HashMap<String, Object>();
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   209
            env.put("create", "true");
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   210
            env.put("encoding", "Shift_JIS");
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   211
            try (FileSystem fs = FileSystems.newFileSystem(uri, env)) {
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   212
                FileSystemProvider fsp = fs.provider();
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   213
                Path p = fs.getPath("/\u8868\u7533.txt");  // 0x95 0x5c 0x90 0x5c
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   214
                try (OutputStream os = fsp.newOutputStream(p)) {
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   215
                    os.write("Hello!".getBytes("ASCII"));
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   216
                }
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   217
                Path dir = fs.getPath("/");
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   218
                Files.list(dir)
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   219
                     .forEach( child -> {
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   220
                             System.out.println("child:" + child);
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   221
                             if (!child.toString().equals(p.toString()))
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   222
                                 throw new RuntimeException("wrong path name created");
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   223
                          });
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   224
                if (!"Hello!".equals(new String(Files.readAllBytes(p), "ASCII")))
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   225
                    throw new RuntimeException("wrong content in newly created file");
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   226
            }
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   227
        } finally {
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   228
            Files.deleteIfExists(path);
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   229
        }
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   230
    }
8046caf79f1c 8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents: 38568
diff changeset
   231
38568
f992c34c85b3 8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents: 30811
diff changeset
   232
    static void tests() throws Throwable {
30811
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   233
        Path path = Paths.get("file.zip");
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   234
        try {
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   235
            URI uri = URI.create("jar:" + path.toUri());
51638
2e4cf4ca074c 8197398: (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
sherman
parents: 48768
diff changeset
   236
30811
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   237
            Map<String, Object> env = new HashMap<String, Object>();
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   238
            env.put("create", "true");
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   239
            try (FileSystem fs = FileSystems.newFileSystem(uri, env)) {
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   240
                FileSystemProvider fsp = fs.provider();
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   241
                Set<? extends OpenOption> options;
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   242
                Path p = fs.getPath("test.txt");
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   243
                // 8028480
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   244
                options = EnumSet.of(StandardOpenOption.CREATE,
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   245
                                     StandardOpenOption.WRITE,
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   246
                                     StandardOpenOption.APPEND);
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   247
                try (FileChannel ch = fsp.newFileChannel(p, options)) {
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   248
                    ch.write(ByteBuffer.wrap("Hello!".getBytes("ASCII")));
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   249
                }
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   250
                // 8034773
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   251
                try (OutputStream os = fsp.newOutputStream(p, new OpenOption[0])) {
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   252
                    os.write("Hello2!".getBytes("ASCII"));
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   253
                }
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   254
                if (!"Hello2!".equals(new String(
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   255
                        Files.readAllBytes(fs.getPath("test.txt"))))) {
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   256
                    throw new RuntimeException("failed to open as truncate_existing");
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   257
                }
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   258
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   259
                options = EnumSet.of(StandardOpenOption.CREATE,
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   260
                                     StandardOpenOption.APPEND,
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   261
                                     StandardOpenOption.TRUNCATE_EXISTING);
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   262
                try (FileChannel ch = fsp.newFileChannel(p, options)) {
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   263
                    throw new RuntimeException("expected IAE not thrown!");
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   264
                } catch (IllegalArgumentException x) {
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   265
                    // expected x.printStackTrace();
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   266
                }
38568
f992c34c85b3 8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents: 30811
diff changeset
   267
f992c34c85b3 8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents: 30811
diff changeset
   268
                //8153248
f992c34c85b3 8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents: 30811
diff changeset
   269
                Path dir = fs.getPath("/dir");
f992c34c85b3 8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents: 30811
diff changeset
   270
                Path subdir = fs.getPath("/dir/subdir");
f992c34c85b3 8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents: 30811
diff changeset
   271
                Files.createDirectory(dir);
f992c34c85b3 8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents: 30811
diff changeset
   272
                Files.createDirectory(subdir);
f992c34c85b3 8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents: 30811
diff changeset
   273
                Files.list(dir)
f992c34c85b3 8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents: 30811
diff changeset
   274
                     .forEach( child -> {
f992c34c85b3 8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents: 30811
diff changeset
   275
                             System.out.println("child:" + child);
f992c34c85b3 8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents: 30811
diff changeset
   276
                             if (child.toString().endsWith("/"))
f992c34c85b3 8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents: 30811
diff changeset
   277
                                 throw new RuntimeException("subdir names ends with /");
f992c34c85b3 8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents: 30811
diff changeset
   278
                          });
30811
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   279
            }
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   280
        } finally {
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   281
            Files.deleteIfExists(path);
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   282
        }
58432ddf9528 8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents: 27260
diff changeset
   283
    }
12430
bd6e432b84ad 7156873: (zipfs) FileSystems.newFileSystem(uri, env) fails for uri with escaped octets
sherman
parents:
diff changeset
   284
}