3471N/A/*
3471N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3471N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3471N/A *
3471N/A * This code is free software; you can redistribute it and/or modify it
3471N/A * under the terms of the GNU General Public License version 2 only, as
3471N/A * published by the Free Software Foundation. Oracle designates this
3471N/A * particular file as subject to the "Classpath" exception as provided
3471N/A * by Oracle in the LICENSE file that accompanied this code.
3471N/A *
3471N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3471N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3471N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3471N/A * version 2 for more details (a copy is included in the LICENSE file that
3471N/A * accompanied this code).
3471N/A *
3471N/A * You should have received a copy of the GNU General Public License version
3471N/A * 2 along with this work; if not, write to the Free Software Foundation,
3471N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3471N/A *
3471N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3471N/A * or visit www.oracle.com if you need additional information or have any
3471N/A * questions.
3471N/A */
3471N/A
3471N/Apackage sun.nio.fs;
3471N/A
3471N/Aimport java.nio.file.*;
3471N/Aimport java.nio.file.spi.FileSystemProvider;
3471N/Aimport java.io.IOException;
3471N/Aimport java.util.Map;
3471N/A
3471N/A/**
3471N/A * Base implementation class of FileSystemProvider
3471N/A */
3471N/A
3471N/Aabstract class AbstractFileSystemProvider extends FileSystemProvider {
3471N/A protected AbstractFileSystemProvider() { }
3471N/A
3471N/A /**
3471N/A * Splits the given attribute name into the name of an attribute view and
3471N/A * the attribute. If the attribute view is not identified then it assumed
3471N/A * to be "basic".
3471N/A */
3471N/A private static String[] split(String attribute) {
3471N/A String[] s = new String[2];
3471N/A int pos = attribute.indexOf(':');
3471N/A if (pos == -1) {
3471N/A s[0] = "basic";
3471N/A s[1] = attribute;
3471N/A } else {
3471N/A s[0] = attribute.substring(0, pos++);
3471N/A s[1] = (pos == attribute.length()) ? "" : attribute.substring(pos);
3471N/A }
3471N/A return s;
3471N/A }
3471N/A
3471N/A /**
3471N/A * Gets a DynamicFileAttributeView by name. Returns {@code null} if the
3471N/A * view is not available.
3471N/A */
3471N/A abstract DynamicFileAttributeView getFileAttributeView(Path file,
3471N/A String name,
3471N/A LinkOption... options);
3471N/A
3471N/A @Override
3471N/A public final void setAttribute(Path file,
3471N/A String attribute,
3471N/A Object value,
3471N/A LinkOption... options)
3471N/A throws IOException
3471N/A {
3471N/A String[] s = split(attribute);
3779N/A if (s[0].length() == 0)
3779N/A throw new IllegalArgumentException(attribute);
3471N/A DynamicFileAttributeView view = getFileAttributeView(file, s[0], options);
3471N/A if (view == null)
3471N/A throw new UnsupportedOperationException("View '" + s[0] + "' not available");
3471N/A view.setAttribute(s[1], value);
3471N/A }
3471N/A
3471N/A @Override
3471N/A public final Map<String,Object> readAttributes(Path file, String attributes, LinkOption... options)
3471N/A throws IOException
3471N/A {
3471N/A String[] s = split(attributes);
3779N/A if (s[0].length() == 0)
3779N/A throw new IllegalArgumentException(attributes);
3471N/A DynamicFileAttributeView view = getFileAttributeView(file, s[0], options);
3471N/A if (view == null)
3779N/A throw new UnsupportedOperationException("View '" + s[0] + "' not available");
3471N/A return view.readAttributes(s[1].split(","));
3471N/A }
3471N/A
3471N/A /**
3471N/A * Deletes a file. The {@code failIfNotExists} parameters determines if an
3471N/A * {@code IOException} is thrown when the file does not exist.
3471N/A */
3471N/A abstract boolean implDelete(Path file, boolean failIfNotExists) throws IOException;
3471N/A
3471N/A @Override
3471N/A public final void delete(Path file) throws IOException {
3471N/A implDelete(file, true);
3471N/A }
3471N/A
3471N/A @Override
3471N/A public final boolean deleteIfExists(Path file) throws IOException {
3471N/A return implDelete(file, false);
3471N/A }
3471N/A}