Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/nio/file/FileSystem/Basic.java
38828 views
/*1* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 4313887 683833325* @summary Unit test for java.nio.file.FileSystem26* @library .. /lib/testlibrary27* @build jdk.testlibrary.FileUtils28* @run main Basic29*/3031import java.io.File;32import java.io.IOException;33import java.net.URI;34import java.net.URISyntaxException;35import java.nio.file.Files;36import java.nio.file.FileStore;37import java.nio.file.FileSystem;38import java.nio.file.FileSystems;39import java.nio.file.Path;40import java.nio.file.Paths;41import java.nio.file.ProviderNotFoundException;42import java.util.HashMap;43import java.util.concurrent.TimeUnit;44import jdk.testlibrary.FileUtils;4546/**47* Simple santity checks for java.nio.file.FileSystem48*/49public class Basic {5051static void check(boolean okay, String msg) {52if (!okay)53throw new RuntimeException(msg);54}5556static void checkFileStores(FileSystem fs) throws IOException {57// sanity check method58if (FileUtils.areFileSystemsAccessible()) {59System.out.println("\n--- Begin FileStores ---");60for (FileStore store: fs.getFileStores()) {61System.out.println(store);62}63System.out.println("--- EndFileStores ---\n");64} else {65System.err.println66("Skipping FileStore check due to file system access failure");67}68}6970static void checkSupported(FileSystem fs, String... views) {71for (String view: views) {72check(fs.supportedFileAttributeViews().contains(view),73"support for '" + view + "' expected");74}75}7677public static void main(String[] args)78throws IOException, URISyntaxException {79String os = System.getProperty("os.name");80FileSystem fs = FileSystems.getDefault();8182// close should throw UOE83try {84fs.close();85throw new RuntimeException("UnsupportedOperationException expected");86} catch (UnsupportedOperationException e) { }87check(fs.isOpen(), "should be open");8889check(!fs.isReadOnly(), "should provide read-write access");9091check(fs.provider().getScheme().equals("file"),92"should use 'file' scheme");9394// sanity check FileStores95checkFileStores(fs);9697// sanity check supportedFileAttributeViews98checkSupported(fs, "basic");99if (os.equals("SunOS"))100checkSupported(fs, "posix", "unix", "owner", "acl", "user");101if (os.equals("Linux"))102checkSupported(fs, "posix", "unix", "owner", "dos", "user");103if (os.contains("OS X"))104checkSupported(fs, "posix", "unix", "owner");105if (os.equals("Windows"))106checkSupported(fs, "owner", "dos", "acl", "user");107}108}109110111