1 /* 2 * Copyright (c) 2012, 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 8040059 26 * @summary ZipFileSystem regression tests 27 * 28 * @run main ZFSTests 29 * @run main/othervm/java.security.policy=test.policy ZFSTests 30 */ 31 32 33 import java.net.URI; 34 import java.nio.file.*; 35 import java.util.Map; 36 import java.util.HashMap; 37 38 public class ZFSTests { 39 40 public static void main(String[] args) throws Throwable { 41 test7156873(); 42 } 43 44 static void test7156873() throws Throwable { 45 String DIRWITHSPACE = "testdir with spaces"; 46 Path dir = Paths.get(DIRWITHSPACE); 47 Path path = Paths.get(DIRWITHSPACE, "file.zip"); 48 try { 49 Files.createDirectory(dir); 50 URI uri = URI.create("jar:" + path.toUri()); 51 Map<String, Object> env = new HashMap<String, Object>(); 52 env.put("create", "true"); 53 try (FileSystem fs = FileSystems.newFileSystem(uri, env)) {} 54 } finally { 55 Files.deleteIfExists(path); 56 Files.deleteIfExists(dir); 57 } 58 } 59 } | 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 8040059 8028480 8034773 26 * @summary ZipFileSystem regression tests 27 * 28 * @run main ZFSTests 29 * @run main/othervm/java.security.policy=test.policy ZFSTests 30 */ 31 32 33 import java.io.OutputStream; 34 import java.net.URI; 35 import java.nio.ByteBuffer; 36 import java.nio.channels.*; 37 import java.nio.file.*; 38 import java.nio.file.spi.*; 39 import java.util.*; 40 41 public class ZFSTests { 42 43 public static void main(String[] args) throws Throwable { 44 test7156873(); 45 testOpenOptions(); 46 } 47 48 static void test7156873() throws Throwable { 49 String DIRWITHSPACE = "testdir with spaces"; 50 Path dir = Paths.get(DIRWITHSPACE); 51 Path path = Paths.get(DIRWITHSPACE, "file.zip"); 52 try { 53 Files.createDirectory(dir); 54 URI uri = URI.create("jar:" + path.toUri()); 55 Map<String, Object> env = new HashMap<String, Object>(); 56 env.put("create", "true"); 57 try (FileSystem fs = FileSystems.newFileSystem(uri, env)) {} 58 } finally { 59 Files.deleteIfExists(path); 60 Files.deleteIfExists(dir); 61 } 62 } 63 64 static void testOpenOptions() throws Throwable { 65 Path path = Paths.get("file.zip"); 66 try { 67 URI uri = URI.create("jar:" + path.toUri()); 68 Map<String, Object> env = new HashMap<String, Object>(); 69 env.put("create", "true"); 70 try (FileSystem fs = FileSystems.newFileSystem(uri, env)) { 71 FileSystemProvider fsp = fs.provider(); 72 Set<? extends OpenOption> options; 73 Path p = fs.getPath("test.txt"); 74 // 8028480 75 options = EnumSet.of(StandardOpenOption.CREATE, 76 StandardOpenOption.WRITE, 77 StandardOpenOption.APPEND); 78 try (FileChannel ch = fsp.newFileChannel(p, options)) { 79 ch.write(ByteBuffer.wrap("Hello!".getBytes("ASCII"))); 80 } 81 // 8034773 82 try (OutputStream os = fsp.newOutputStream(p, new OpenOption[0])) { 83 os.write("Hello2!".getBytes("ASCII")); 84 } 85 if (!"Hello2!".equals(new String( 86 Files.readAllBytes(fs.getPath("test.txt"))))) { 87 throw new RuntimeException("failed to open as truncate_existing"); 88 } 89 90 options = EnumSet.of(StandardOpenOption.CREATE, 91 StandardOpenOption.APPEND, 92 StandardOpenOption.TRUNCATE_EXISTING); 93 try (FileChannel ch = fsp.newFileChannel(p, options)) { 94 throw new RuntimeException("expected IAE not thrown!"); 95 } catch (IllegalArgumentException x) { 96 // expected x.printStackTrace(); 97 } 98 } 99 } finally { 100 Files.deleteIfExists(path); 101 } 102 } 103 } |