WindowsFileSystemProvider.java revision 2362
893N/A/*
2362N/A * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
893N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
893N/A *
893N/A * This code is free software; you can redistribute it and/or modify it
893N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
893N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
893N/A *
893N/A * This code is distributed in the hope that it will be useful, but WITHOUT
893N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
893N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
893N/A * version 2 for more details (a copy is included in the LICENSE file that
893N/A * accompanied this code).
893N/A *
893N/A * You should have received a copy of the GNU General Public License version
893N/A * 2 along with this work; if not, write to the Free Software Foundation,
893N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
893N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
893N/A */
893N/A
893N/Apackage sun.nio.fs;
893N/A
893N/Aimport java.nio.file.*;
893N/Aimport java.nio.file.spi.*;
893N/Aimport java.nio.file.attribute.*;
893N/Aimport java.nio.channels.*;
893N/Aimport java.net.URI;
893N/Aimport java.util.concurrent.ExecutorService;
893N/Aimport java.io.IOException;
893N/Aimport java.util.*;
893N/A
893N/Aimport sun.nio.ch.ThreadPool;
893N/A
893N/Apublic class WindowsFileSystemProvider
893N/A extends FileSystemProvider
893N/A{
893N/A private static final String USER_DIR = "user.dir";
893N/A private final WindowsFileSystem theFileSystem;
893N/A
893N/A public WindowsFileSystemProvider() {
893N/A theFileSystem = new WindowsFileSystem(this, System.getProperty(USER_DIR));
893N/A }
893N/A
893N/A @Override
893N/A public String getScheme() {
893N/A return "file";
893N/A }
893N/A
893N/A private void checkUri(URI uri) {
893N/A if (!uri.getScheme().equalsIgnoreCase(getScheme()))
893N/A throw new IllegalArgumentException("URI does not match this provider");
893N/A if (uri.getAuthority() != null)
893N/A throw new IllegalArgumentException("Authority component present");
893N/A if (uri.getPath() == null)
893N/A throw new IllegalArgumentException("Path component is undefined");
893N/A if (!uri.getPath().equals("/"))
893N/A throw new IllegalArgumentException("Path component should be '/'");
893N/A if (uri.getQuery() != null)
893N/A throw new IllegalArgumentException("Query component present");
893N/A if (uri.getFragment() != null)
893N/A throw new IllegalArgumentException("Fragment component present");
893N/A }
893N/A
893N/A @Override
893N/A public FileSystem newFileSystem(URI uri, Map<String,?> env)
893N/A throws IOException
893N/A {
893N/A checkUri(uri);
893N/A throw new FileSystemAlreadyExistsException();
893N/A }
893N/A
893N/A @Override
893N/A public final FileSystem getFileSystem(URI uri) {
893N/A checkUri(uri);
893N/A return theFileSystem;
893N/A }
893N/A
893N/A @Override
893N/A public Path getPath(URI uri) {
893N/A return WindowsUriSupport.fromUri(theFileSystem, uri);
893N/A }
893N/A
893N/A @Override
893N/A public FileChannel newFileChannel(Path path,
893N/A Set<? extends OpenOption> options,
893N/A FileAttribute<?>... attrs)
893N/A throws IOException
893N/A {
893N/A if (path == null)
893N/A throw new NullPointerException();
893N/A if (!(path instanceof WindowsPath))
893N/A throw new ProviderMismatchException();
893N/A WindowsPath file = (WindowsPath)path;
893N/A
893N/A WindowsSecurityDescriptor sd = WindowsSecurityDescriptor.fromAttribute(attrs);
893N/A try {
893N/A return WindowsChannelFactory
893N/A .newFileChannel(file.getPathForWin32Calls(),
893N/A file.getPathForPermissionCheck(),
893N/A options,
893N/A sd.address());
893N/A } catch (WindowsException x) {
893N/A x.rethrowAsIOException(file);
893N/A return null;
893N/A } finally {
893N/A if (sd != null)
893N/A sd.release();
893N/A }
893N/A }
893N/A
893N/A @Override
893N/A public AsynchronousFileChannel newAsynchronousFileChannel(Path path,
893N/A Set<? extends OpenOption> options,
893N/A ExecutorService executor,
893N/A FileAttribute<?>... attrs)
893N/A throws IOException
893N/A {
893N/A if (path == null)
893N/A throw new NullPointerException();
893N/A if (!(path instanceof WindowsPath))
893N/A throw new ProviderMismatchException();
893N/A WindowsPath file = (WindowsPath)path;
893N/A ThreadPool pool = (executor == null) ? null : ThreadPool.wrap(executor, 0);
893N/A WindowsSecurityDescriptor sd =
893N/A WindowsSecurityDescriptor.fromAttribute(attrs);
893N/A try {
893N/A return WindowsChannelFactory
893N/A .newAsynchronousFileChannel(file.getPathForWin32Calls(),
893N/A file.getPathForPermissionCheck(),
893N/A options,
893N/A sd.address(),
893N/A pool);
893N/A } catch (WindowsException x) {
893N/A x.rethrowAsIOException(file);
893N/A return null;
893N/A } finally {
893N/A if (sd != null)
893N/A sd.release();
893N/A }
893N/A }
893N/A}