/* * Copyright (c) 2009, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
publicclass Basic { publicstaticvoid main(String[] args) throws Exception { // Test: zip should be returned in provider list boolean found = false; for (FileSystemProvider provider: FileSystemProvider.installedProviders()) { if (provider.getScheme().equalsIgnoreCase("jar")) {
found = true; break;
}
} if (!found) thrownew RuntimeException("'jar' provider not installed");
// create JAR file for test
Path jarFile = Utils.createJarFile("basic.jar", "META-INF/services/java.nio.file.spi.FileSystemProvider");
// Test: FileSystems#newFileSystem(URI)
URI uri = new URI("jar", jarFile.toUri().toString(), null);
FileSystem fs = FileSystems.newFileSystem(uri, env, null);
// Test: exercise toUri method
String expected = uri.toString() + "!/foo";
String actual = fs.getPath("/foo").toUri().toString(); if (!actual.equals(expected)) { thrownew RuntimeException("toUri returned '" + actual + "', expected '" + expected + "'");
}
// Test: exercise directory iterator and retrieval of basic attributes
Files.walkFileTree(fs.getPath("/"), new FileTreePrinter());
// Test: copy file from zip file to current (scratch) directory
Path source = fs.getPath("/META-INF/services/java.nio.file.spi.FileSystemProvider"); if (Files.exists(source)) {
Path target = Path.of(source.getFileName().toString());
Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING); try { long s1 = Files.readAttributes(source, BasicFileAttributes.class).size(); long s2 = Files.readAttributes(target, BasicFileAttributes.class).size(); if (s2 != s1) thrownew RuntimeException("target size != source size");
} finally {
Files.delete(target);
}
}
// Test: FileStore
FileStore store = Files.getFileStore(fs.getPath("/")); if (!store.supportsFileAttributeView("basic")) thrownew RuntimeException("BasicFileAttributeView should be supported");
// Test: watch register should throw PME try {
fs.getPath("/")
.register(FileSystems.getDefault().newWatchService(), ENTRY_CREATE); thrownew RuntimeException("watch service is not supported");
} catch (ProviderMismatchException x) { }
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.