Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/nio/fs/LinuxFileSystemProvider.java
32288 views
/*1* Copyright (c) 2008, 2012, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.nio.fs;2627import java.nio.file.*;28import java.nio.file.attribute.*;29import java.nio.file.spi.FileTypeDetector;30import java.io.IOException;31import java.security.AccessController;32import sun.security.action.GetPropertyAction;3334/**35* Linux implementation of FileSystemProvider36*/3738public class LinuxFileSystemProvider extends UnixFileSystemProvider {39public LinuxFileSystemProvider() {40super();41}4243@Override44LinuxFileSystem newFileSystem(String dir) {45return new LinuxFileSystem(this, dir);46}4748@Override49LinuxFileStore getFileStore(UnixPath path) throws IOException {50return new LinuxFileStore(path);51}5253@Override54@SuppressWarnings("unchecked")55public <V extends FileAttributeView> V getFileAttributeView(Path obj,56Class<V> type,57LinkOption... options)58{59if (type == DosFileAttributeView.class) {60return (V) new LinuxDosFileAttributeView(UnixPath.toUnixPath(obj),61Util.followLinks(options));62}63if (type == UserDefinedFileAttributeView.class) {64return (V) new LinuxUserDefinedFileAttributeView(UnixPath.toUnixPath(obj),65Util.followLinks(options));66}67return super.getFileAttributeView(obj, type, options);68}6970@Override71public DynamicFileAttributeView getFileAttributeView(Path obj,72String name,73LinkOption... options)74{75if (name.equals("dos")) {76return new LinuxDosFileAttributeView(UnixPath.toUnixPath(obj),77Util.followLinks(options));78}79if (name.equals("user")) {80return new LinuxUserDefinedFileAttributeView(UnixPath.toUnixPath(obj),81Util.followLinks(options));82}83return super.getFileAttributeView(obj, name, options);84}8586@Override87@SuppressWarnings("unchecked")88public <A extends BasicFileAttributes> A readAttributes(Path file,89Class<A> type,90LinkOption... options)91throws IOException92{93if (type == DosFileAttributes.class) {94DosFileAttributeView view =95getFileAttributeView(file, DosFileAttributeView.class, options);96return (A) view.readAttributes();97} else {98return super.readAttributes(file, type, options);99}100}101102@Override103FileTypeDetector getFileTypeDetector() {104Path userMimeTypes = Paths.get(AccessController.doPrivileged(105new GetPropertyAction("user.home")), ".mime.types");106Path etcMimeTypes = Paths.get("/etc/mime.types");107108return chain(new GnomeFileTypeDetector(),109new MimeTypesFileTypeDetector(userMimeTypes),110new MimeTypesFileTypeDetector(etcMimeTypes),111new MagicFileTypeDetector());112}113}114115116