Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/demo/zipfs/ZFSTests.java
38833 views
1
/*
2
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
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
21
* questions.
22
*/
23
24
/* @test
25
@bug 7156873 8028480 8034773 8061777
26
@summary ZipFileSystem regression tests
27
*/
28
29
import java.io.OutputStream;
30
import java.net.URI;
31
import java.nio.ByteBuffer;
32
import java.nio.channels.*;
33
import java.nio.file.*;
34
import java.nio.file.spi.*;
35
import java.util.*;
36
37
public class ZFSTests {
38
39
public static void main(String[] args) throws Throwable {
40
test7156873();
41
test8061777();
42
testOpenOptions();
43
}
44
45
static void test7156873() throws Throwable {
46
String DIRWITHSPACE = "testdir with spaces";
47
Path dir = Paths.get(DIRWITHSPACE);
48
Path path = Paths.get(DIRWITHSPACE, "file.zip");
49
try {
50
Files.createDirectory(dir);
51
URI uri = URI.create("jar:" + path.toUri());
52
Map<String, Object> env = new HashMap<String, Object>();
53
env.put("create", "true");
54
try (FileSystem fs = FileSystems.newFileSystem(uri, env)) {}
55
} finally {
56
Files.deleteIfExists(path);
57
Files.deleteIfExists(dir);
58
}
59
}
60
61
static void test8061777() throws Throwable {
62
Path path = Paths.get("file.zip");
63
try {
64
URI uri = URI.create("jar:" + path.toUri());
65
Map<String, Object> env = new HashMap<String, Object>();
66
env.put("create", "true");
67
env.put("encoding", "Shift_JIS");
68
try (FileSystem fs = FileSystems.newFileSystem(uri, env)) {
69
FileSystemProvider fsp = fs.provider();
70
Path p = fs.getPath("/\u8868\u7533.txt"); // 0x95 0x5c 0x90 0x5c
71
try (OutputStream os = fsp.newOutputStream(p)) {
72
os.write("Hello!".getBytes("ASCII"));
73
}
74
Path dir = fs.getPath("/");
75
Files.list(dir)
76
.forEach( child -> {
77
System.out.println("child:" + child);
78
if (!child.toString().equals(p.toString()))
79
throw new RuntimeException("wrong path name created");
80
});
81
if (!"Hello!".equals(new String(Files.readAllBytes(p), "ASCII")))
82
throw new RuntimeException("wrong content in newly created file");
83
}
84
} finally {
85
Files.deleteIfExists(path);
86
}
87
}
88
89
static void testOpenOptions() throws Throwable {
90
Path path = Paths.get("file.zip");
91
try {
92
URI uri = URI.create("jar:" + path.toUri());
93
Map<String, Object> env = new HashMap<String, Object>();
94
env.put("create", "true");
95
try (FileSystem fs = FileSystems.newFileSystem(uri, env)) {
96
FileSystemProvider fsp = fs.provider();
97
Set<? extends OpenOption> options;
98
Path p = fs.getPath("test.txt");
99
// 8028480
100
options = EnumSet.of(StandardOpenOption.CREATE,
101
StandardOpenOption.WRITE,
102
StandardOpenOption.APPEND);
103
try (FileChannel ch = fsp.newFileChannel(p, options)) {
104
ch.write(ByteBuffer.wrap("Hello!".getBytes("ASCII")));
105
}
106
// 8034773
107
try (OutputStream os = fsp.newOutputStream(p, new OpenOption[0])) {
108
os.write("Hello2!".getBytes("ASCII"));
109
}
110
if (!"Hello2!".equals(new String(
111
Files.readAllBytes(fs.getPath("test.txt"))))) {
112
throw new RuntimeException("failed to open as truncate_existing");
113
}
114
115
options = EnumSet.of(StandardOpenOption.CREATE,
116
StandardOpenOption.APPEND,
117
StandardOpenOption.TRUNCATE_EXISTING);
118
try (FileChannel ch = fsp.newFileChannel(p, options)) {
119
throw new RuntimeException("expected IAE not thrown!");
120
} catch (IllegalArgumentException x) {
121
// expected x.printStackTrace();
122
}
123
}
124
} finally {
125
Files.deleteIfExists(path);
126
}
127
}
128
}
129
130