Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/nio/fs/AbstractFileSystemProvider.java
38918 views
/*1* Copyright (c) 2011, 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.spi.FileSystemProvider;29import java.io.IOException;30import java.util.Map;3132/**33* Base implementation class of FileSystemProvider34*/3536abstract class AbstractFileSystemProvider extends FileSystemProvider {37protected AbstractFileSystemProvider() { }3839/**40* Splits the given attribute name into the name of an attribute view and41* the attribute. If the attribute view is not identified then it assumed42* to be "basic".43*/44private static String[] split(String attribute) {45String[] s = new String[2];46int pos = attribute.indexOf(':');47if (pos == -1) {48s[0] = "basic";49s[1] = attribute;50} else {51s[0] = attribute.substring(0, pos++);52s[1] = (pos == attribute.length()) ? "" : attribute.substring(pos);53}54return s;55}5657/**58* Gets a DynamicFileAttributeView by name. Returns {@code null} if the59* view is not available.60*/61abstract DynamicFileAttributeView getFileAttributeView(Path file,62String name,63LinkOption... options);6465@Override66public final void setAttribute(Path file,67String attribute,68Object value,69LinkOption... options)70throws IOException71{72String[] s = split(attribute);73if (s[0].length() == 0)74throw new IllegalArgumentException(attribute);75DynamicFileAttributeView view = getFileAttributeView(file, s[0], options);76if (view == null)77throw new UnsupportedOperationException("View '" + s[0] + "' not available");78view.setAttribute(s[1], value);79}8081@Override82public final Map<String,Object> readAttributes(Path file, String attributes, LinkOption... options)83throws IOException84{85String[] s = split(attributes);86if (s[0].length() == 0)87throw new IllegalArgumentException(attributes);88DynamicFileAttributeView view = getFileAttributeView(file, s[0], options);89if (view == null)90throw new UnsupportedOperationException("View '" + s[0] + "' not available");91return view.readAttributes(s[1].split(","));92}9394/**95* Deletes a file. The {@code failIfNotExists} parameters determines if an96* {@code IOException} is thrown when the file does not exist.97*/98abstract boolean implDelete(Path file, boolean failIfNotExists) throws IOException;99100@Override101public final void delete(Path file) throws IOException {102implDelete(file, true);103}104105@Override106public final boolean deleteIfExists(Path file) throws IOException {107return implDelete(file, false);108}109}110111112