1e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera/*
2e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
3e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera *
5e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * This code is free software; you can redistribute it and/or modify it
6e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * under the terms of the GNU General Public License version 2 only, as
7e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * published by the Free Software Foundation.  Oracle designates this
8e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * particular file as subject to the "Classpath" exception as provided
9e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * by Oracle in the LICENSE file that accompanied this code.
10e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera *
11e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * This code is distributed in the hope that it will be useful, but WITHOUT
12e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * version 2 for more details (a copy is included in the LICENSE file that
15e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * accompanied this code).
16e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera *
17e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * You should have received a copy of the GNU General Public License version
18e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * 2 along with this work; if not, write to the Free Software Foundation,
19e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera *
21e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * or visit www.oracle.com if you need additional information or have any
23e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * questions.
24e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera */
25e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
26e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmerapackage java.nio.file.spi;
27e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
28e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmeraimport java.nio.file.*;
29e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmeraimport java.nio.file.attribute.*;
30e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmeraimport java.nio.channels.*;
31e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmeraimport java.net.URI;
32e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmeraimport java.io.InputStream;
33e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmeraimport java.io.OutputStream;
34e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmeraimport java.io.IOException;
35e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmeraimport java.util.*;
36e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmeraimport java.util.concurrent.ExecutorService;
37e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmeraimport java.security.AccessController;
38e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmeraimport java.security.PrivilegedAction;
39e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
40e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera/**
41e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * Service-provider class for file systems. The methods defined by the {@link
42e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * java.nio.file.Files} class will typically delegate to an instance of this
43e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * class.
44e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera *
45e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * <p> A file system provider is a concrete implementation of this class that
46e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * implements the abstract methods defined by this class. A provider is
47e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * identified by a {@code URI} {@link #getScheme() scheme}. The default provider
48e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * is identified by the URI scheme "file". It creates the {@link FileSystem} that
49e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * provides access to the file systems accessible to the Java virtual machine.
50e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * The {@link FileSystems} class defines how file system providers are located
51e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * and loaded. The default provider is typically a system-default provider but
52e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * may be overridden if the system property {@code
53e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * java.nio.file.spi.DefaultFileSystemProvider} is set. In that case, the
54e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * provider has a one argument constructor whose formal parameter type is {@code
55e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * FileSystemProvider}. All other providers have a zero argument constructor
56e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * that initializes the provider.
57e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera *
58e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * <p> A provider is a factory for one or more {@link FileSystem} instances. Each
59e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * file system is identified by a {@code URI} where the URI's scheme matches
60e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * the provider's {@link #getScheme scheme}. The default file system, for example,
61e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * is identified by the URI {@code "file:///"}. A memory-based file system,
62e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * for example, may be identified by a URI such as {@code "memory:///?name=logfs"}.
63e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * The {@link #newFileSystem newFileSystem} method may be used to create a file
64e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * system, and the {@link #getFileSystem getFileSystem} method may be used to
65e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * obtain a reference to an existing file system created by the provider. Where
66e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * a provider is the factory for a single file system then it is provider dependent
67e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * if the file system is created when the provider is initialized, or later when
68e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * the {@code newFileSystem} method is invoked. In the case of the default
69e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * provider, the {@code FileSystem} is created when the provider is initialized.
70e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera *
71e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * <p> All of the methods in this class are safe for use by multiple concurrent
72e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * threads.
73e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera *
74e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera * @since 1.7
75e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera */
76e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
77e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmerapublic abstract class FileSystemProvider {
78e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    // lock using when loading providers
79e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    private static final Object lock = new Object();
80e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
81e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    // installed providers
82e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    private static volatile List<FileSystemProvider> installedProviders;
83e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
84e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    // used to avoid recursive loading of instaled providers
85e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    private static boolean loadingProviders  = false;
86e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
87e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    private static Void checkPermission() {
88e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        SecurityManager sm = System.getSecurityManager();
89e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        if (sm != null)
90e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera            sm.checkPermission(new RuntimePermission("fileSystemProvider"));
91e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        return null;
92e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    }
93e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    private FileSystemProvider(Void ignore) { }
94e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
95e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
96e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Initializes a new instance of this class.
97e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
98e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <p> During construction a provider may safely access files associated
99e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * with the default provider but care needs to be taken to avoid circular
100e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * loading of other installed providers. If circular loading of installed
101e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * providers is detected then an unspecified error is thrown.
102e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
103e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
104e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          If a security manager has been installed and it denies
105e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          {@link RuntimePermission}<tt>("fileSystemProvider")</tt>
106e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
107e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    protected FileSystemProvider() {
108e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        this(checkPermission());
109e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    }
110e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
111e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    // loads all installed providers
112e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    private static List<FileSystemProvider> loadInstalledProviders() {
113e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        List<FileSystemProvider> list = new ArrayList<FileSystemProvider>();
114e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
115e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        ServiceLoader<FileSystemProvider> sl = ServiceLoader
116e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera            .load(FileSystemProvider.class, ClassLoader.getSystemClassLoader());
117e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
118e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        // ServiceConfigurationError may be throw here
119e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        for (FileSystemProvider provider: sl) {
120e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera            String scheme = provider.getScheme();
121e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
122e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera            // add to list if the provider is not "file" and isn't a duplicate
123e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera            if (!scheme.equalsIgnoreCase("file")) {
124e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                boolean found = false;
125e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                for (FileSystemProvider p: list) {
126e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                    if (p.getScheme().equalsIgnoreCase(scheme)) {
127e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                        found = true;
128e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                        break;
129e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                    }
130e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                }
131e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                if (!found) {
132e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                    list.add(provider);
133e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                }
134e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera            }
135e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        }
136e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        return list;
137e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    }
138e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
139e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
140e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Returns a list of the installed file system providers.
141e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
142e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <p> The first invocation of this method causes the default provider to be
143e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * initialized (if not already initialized) and loads any other installed
144e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * providers as described by the {@link FileSystems} class.
145e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
146e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @return  An unmodifiable list of the installed file system providers. The
147e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          list contains at least one element, that is the default file
148e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          system provider
149e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
150e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  ServiceConfigurationError
151e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          When an error occurs while loading a service provider
152e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
153e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public static List<FileSystemProvider> installedProviders() {
154e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        if (installedProviders == null) {
155e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera            // ensure default provider is initialized
156e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera            FileSystemProvider defaultProvider = FileSystems.getDefault().provider();
157e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
158e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera            synchronized (lock) {
159e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                if (installedProviders == null) {
160e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                    if (loadingProviders) {
161e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                        throw new Error("Circular loading of installed providers detected");
162e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                    }
163e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                    loadingProviders = true;
164e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
165e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                    List<FileSystemProvider> list = AccessController
166e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                        .doPrivileged(new PrivilegedAction<List<FileSystemProvider>>() {
167e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                            @Override
168e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                            public List<FileSystemProvider> run() {
169e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                                return loadInstalledProviders();
170e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                        }});
171e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
172e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                    // insert the default provider at the start of the list
173e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                    list.add(0, defaultProvider);
174e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
175e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                    installedProviders = Collections.unmodifiableList(list);
176e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                }
177e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera            }
178e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        }
179e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        return installedProviders;
180e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    }
181e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
182e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
183e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Returns the URI scheme that identifies this provider.
184e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
185e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @return  The URI scheme
186e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
187e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public abstract String getScheme();
188e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
189e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
190e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Constructs a new {@code FileSystem} object identified by a URI. This
191e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * method is invoked by the {@link FileSystems#newFileSystem(URI,Map)}
192e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * method to open a new file system identified by a URI.
193e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
194e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <p> The {@code uri} parameter is an absolute, hierarchical URI, with a
195e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * scheme equal (without regard to case) to the scheme supported by this
196e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * provider. The exact form of the URI is highly provider dependent. The
197e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * {@code env} parameter is a map of provider specific properties to configure
198e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * the file system.
199e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
200e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <p> This method throws {@link FileSystemAlreadyExistsException} if the
201e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * file system already exists because it was previously created by an
202e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * invocation of this method. Once a file system is {@link
203e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * java.nio.file.FileSystem#close closed} it is provider-dependent if the
204e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * provider allows a new file system to be created with the same URI as a
205e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * file system it previously created.
206e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
207e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   uri
208e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          URI reference
209e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   env
210e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          A map of provider specific properties to configure the file system;
211e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          may be empty
212e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
213e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @return  A new file system
214e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
215e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IllegalArgumentException
216e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          If the pre-conditions for the {@code uri} parameter aren't met,
217e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          or the {@code env} parameter does not contain properties required
218e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          by the provider, or a property value is invalid
219e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IOException
220e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          An I/O error occurs creating the file system
221e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
222e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          If a security manager is installed and it denies an unspecified
223e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          permission required by the file system provider implementation
224e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  FileSystemAlreadyExistsException
225e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          If the file system has already been created
226e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
227e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public abstract FileSystem newFileSystem(URI uri, Map<String,?> env)
228e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        throws IOException;
229e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
230e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
231e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Returns an existing {@code FileSystem} created by this provider.
232e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
233e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <p> This method returns a reference to a {@code FileSystem} that was
234e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * created by invoking the {@link #newFileSystem(URI,Map) newFileSystem(URI,Map)}
235e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * method. File systems created the {@link #newFileSystem(Path,Map)
236e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * newFileSystem(Path,Map)} method are not returned by this method.
237e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * The file system is identified by its {@code URI}. Its exact form
238e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * is highly provider dependent. In the case of the default provider the URI's
239e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * path component is {@code "/"} and the authority, query and fragment components
240e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * are undefined (Undefined components are represented by {@code null}).
241e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
242e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <p> Once a file system created by this provider is {@link
243e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * java.nio.file.FileSystem#close closed} it is provider-dependent if this
244e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * method returns a reference to the closed file system or throws {@link
245e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * FileSystemNotFoundException}. If the provider allows a new file system to
246e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * be created with the same URI as a file system it previously created then
247e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * this method throws the exception if invoked after the file system is
248e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * closed (and before a new instance is created by the {@link #newFileSystem
249e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * newFileSystem} method).
250e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
251e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <p> If a security manager is installed then a provider implementation
252e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * may require to check a permission before returning a reference to an
253e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * existing file system. In the case of the {@link FileSystems#getDefault
254e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * default} file system, no permission check is required.
255e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
256e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   uri
257e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          URI reference
258e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
259e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @return  The file system
260e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
261e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IllegalArgumentException
262e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          If the pre-conditions for the {@code uri} parameter aren't met
263e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  FileSystemNotFoundException
264e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          If the file system does not exist
265e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
266e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          If a security manager is installed and it denies an unspecified
267e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          permission.
268e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
269e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public abstract FileSystem getFileSystem(URI uri);
270e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
271e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
272e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Return a {@code Path} object by converting the given {@link URI}. The
273e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * resulting {@code Path} is associated with a {@link FileSystem} that
274e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * already exists or is constructed automatically.
275e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
276e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <p> The exact form of the URI is file system provider dependent. In the
277e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * case of the default provider, the URI scheme is {@code "file"} and the
278e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * given URI has a non-empty path component, and undefined query, and
279e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * fragment components. The resulting {@code Path} is associated with the
280e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * default {@link FileSystems#getDefault default} {@code FileSystem}.
281e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
282e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <p> If a security manager is installed then a provider implementation
283e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * may require to check a permission. In the case of the {@link
284e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * FileSystems#getDefault default} file system, no permission check is
285e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * required.
286e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
287e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   uri
288e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          The URI to convert
289e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
290e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @return  The resulting {@code Path}
291e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
292e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IllegalArgumentException
293e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          If the URI scheme does not identify this provider or other
294e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          preconditions on the uri parameter do not hold
295e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  FileSystemNotFoundException
296e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          The file system, identified by the URI, does not exist and
297e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          cannot be created automatically
298e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
299e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          If a security manager is installed and it denies an unspecified
300e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          permission.
301e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
302e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public abstract Path getPath(URI uri);
303e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
304e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
305e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Constructs a new {@code FileSystem} to access the contents of a file as a
306e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * file system.
307e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
308e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <p> This method is intended for specialized providers of pseudo file
309e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * systems where the contents of one or more files is treated as a file
310e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * system. The {@code env} parameter is a map of provider specific properties
311e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * to configure the file system.
312e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
313e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <p> If this provider does not support the creation of such file systems
314e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * or if the provider does not recognize the file type of the given file then
315e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * it throws {@code UnsupportedOperationException}. The default implementation
316e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * of this method throws {@code UnsupportedOperationException}.
317e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
318e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   path
319e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          The path to the file
320e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   env
321e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          A map of provider specific properties to configure the file system;
322e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          may be empty
323e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
324e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @return  A new file system
325e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
326e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  UnsupportedOperationException
327e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          If this provider does not support access to the contents as a
328e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          file system or it does not recognize the file type of the
329e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          given file
330e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IllegalArgumentException
331e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          If the {@code env} parameter does not contain properties required
332e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          by the provider, or a property value is invalid
333e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IOException
334e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          If an I/O error occurs
335e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
336e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          If a security manager is installed and it denies an unspecified
337e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          permission.
338e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
339e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public FileSystem newFileSystem(Path path, Map<String,?> env)
340e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        throws IOException
341e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    {
342e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        throw new UnsupportedOperationException();
343e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    }
344e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
345e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
346e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Opens a file, returning an input stream to read from the file. This
347e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * method works in exactly the manner specified by the {@link
348e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Files#newInputStream} method.
349e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
350e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <p> The default implementation of this method opens a channel to the file
351e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * as if by invoking the {@link #newByteChannel} method and constructs a
352e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * stream that reads bytes from the channel. This method should be overridden
353e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * where appropriate.
354e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
355e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   path
356e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the path to the file to open
357e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   options
358e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          options specifying how the file is opened
359e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
360e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @return  a new input stream
361e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
362e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IllegalArgumentException
363e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if an invalid combination of options is specified
364e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  UnsupportedOperationException
365e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if an unsupported option is specified
366e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IOException
367e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if an I/O error occurs
368e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
369e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          In the case of the default provider, and a security manager is
370e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          installed, the {@link SecurityManager#checkRead(String) checkRead}
371e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          method is invoked to check read access to the file.
372e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
373e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public InputStream newInputStream(Path path, OpenOption... options)
374e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        throws IOException
375e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    {
376e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        if (options.length > 0) {
377e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera            for (OpenOption opt: options) {
378e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                // All OpenOption values except for APPEND and WRITE are allowed
379e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                if (opt == StandardOpenOption.APPEND ||
380e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                    opt == StandardOpenOption.WRITE)
381e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                    throw new UnsupportedOperationException("'" + opt + "' not allowed");
382e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera            }
383e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        }
384e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        return Channels.newInputStream(Files.newByteChannel(path, options));
385e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    }
386e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
387e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
388e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Opens or creates a file, returning an output stream that may be used to
389e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * write bytes to the file. This method works in exactly the manner
390e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * specified by the {@link Files#newOutputStream} method.
391e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
392e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <p> The default implementation of this method opens a channel to the file
393e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * as if by invoking the {@link #newByteChannel} method and constructs a
394e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * stream that writes bytes to the channel. This method should be overridden
395e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * where appropriate.
396e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
397e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   path
398e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the path to the file to open or create
399e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   options
400e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          options specifying how the file is opened
401e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
402e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @return  a new output stream
403e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
404e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IllegalArgumentException
405e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if {@code options} contains an invalid combination of options
406e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  UnsupportedOperationException
407e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if an unsupported option is specified
408e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IOException
409e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if an I/O error occurs
410e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
411e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          In the case of the default provider, and a security manager is
412e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          installed, the {@link SecurityManager#checkWrite(String) checkWrite}
413e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          method is invoked to check write access to the file. The {@link
414e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          SecurityManager#checkDelete(String) checkDelete} method is
415e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          invoked to check delete access if the file is opened with the
416e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          {@code DELETE_ON_CLOSE} option.
417e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
418e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public OutputStream newOutputStream(Path path, OpenOption... options)
419e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        throws IOException
420e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    {
421e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        int len = options.length;
422e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        Set<OpenOption> opts = new HashSet<OpenOption>(len + 3);
423e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        if (len == 0) {
424e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera            opts.add(StandardOpenOption.CREATE);
425e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera            opts.add(StandardOpenOption.TRUNCATE_EXISTING);
426e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        } else {
427e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera            for (OpenOption opt: options) {
428e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                if (opt == StandardOpenOption.READ)
429e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                    throw new IllegalArgumentException("READ not allowed");
430e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                opts.add(opt);
431e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera            }
432e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        }
433e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        opts.add(StandardOpenOption.WRITE);
434e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        return Channels.newOutputStream(newByteChannel(path, opts));
435e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    }
436e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
437e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
438e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Opens or creates a file for reading and/or writing, returning a file
439e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * channel to access the file. This method works in exactly the manner
440e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * specified by the {@link FileChannel#open(Path,Set,FileAttribute[])
441e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * FileChannel.open} method. A provider that does not support all the
442e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * features required to construct a file channel throws {@code
443e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * UnsupportedOperationException}. The default provider is required to
444e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * support the creation of file channels. When not overridden, the default
445e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * implementation throws {@code UnsupportedOperationException}.
446e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
447e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   path
448e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the path of the file to open or create
449e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   options
450e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          options specifying how the file is opened
451e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   attrs
452e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          an optional list of file attributes to set atomically when
453e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          creating the file
454e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
455e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @return  a new file channel
456e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
457e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IllegalArgumentException
458e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          If the set contains an invalid combination of options
459e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  UnsupportedOperationException
460e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          If this provider that does not support creating file channels,
461e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          or an unsupported open option or file attribute is specified
462e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IOException
463e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          If an I/O error occurs
464e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
465e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          In the case of the default file system, the {@link
466e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          SecurityManager#checkRead(String)} method is invoked to check
467e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          read access if the file is opened for reading. The {@link
468e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          SecurityManager#checkWrite(String)} method is invoked to check
469e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          write access if the file is opened for writing
470e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
471e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public FileChannel newFileChannel(Path path,
472e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                                      Set<? extends OpenOption> options,
473e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                                      FileAttribute<?>... attrs)
474e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        throws IOException
475e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    {
476e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        throw new UnsupportedOperationException();
477e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    }
478e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
479e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
480e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Opens or creates a file for reading and/or writing, returning an
481e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * asynchronous file channel to access the file. This method works in
482e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * exactly the manner specified by the {@link
483e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * AsynchronousFileChannel#open(Path,Set,ExecutorService,FileAttribute[])
484e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * AsynchronousFileChannel.open} method.
485e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * A provider that does not support all the features required to construct
486e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * an asynchronous file channel throws {@code UnsupportedOperationException}.
487e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * The default provider is required to support the creation of asynchronous
488e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * file channels. When not overridden, the default implementation of this
489e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * method throws {@code UnsupportedOperationException}.
490e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
491e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   path
492e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the path of the file to open or create
493e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   options
494e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          options specifying how the file is opened
495e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   executor
496e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the thread pool or {@code null} to associate the channel with
497e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the default thread pool
498e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   attrs
499e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          an optional list of file attributes to set atomically when
500e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          creating the file
501e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
502e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @return  a new asynchronous file channel
503e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
504e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IllegalArgumentException
505e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          If the set contains an invalid combination of options
506e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  UnsupportedOperationException
507e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          If this provider that does not support creating asynchronous file
508e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          channels, or an unsupported open option or file attribute is
509e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          specified
510e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IOException
511e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          If an I/O error occurs
512e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
513e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          In the case of the default file system, the {@link
514e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          SecurityManager#checkRead(String)} method is invoked to check
515e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          read access if the file is opened for reading. The {@link
516e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          SecurityManager#checkWrite(String)} method is invoked to check
517e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          write access if the file is opened for writing
518e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
519e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public AsynchronousFileChannel newAsynchronousFileChannel(Path path,
520e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                                                              Set<? extends OpenOption> options,
521e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                                                              ExecutorService executor,
522e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                                                              FileAttribute<?>... attrs)
523e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        throws IOException
524e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    {
525e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        throw new UnsupportedOperationException();
526e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    }
527e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
528e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
529e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Opens or creates a file, returning a seekable byte channel to access the
530e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * file. This method works in exactly the manner specified by the {@link
531e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Files#newByteChannel(Path,Set,FileAttribute[])} method.
532e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
533e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   path
534e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the path to the file to open or create
535e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   options
536e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          options specifying how the file is opened
537e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   attrs
538e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          an optional list of file attributes to set atomically when
539e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          creating the file
540e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
541e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @return  a new seekable byte channel
542e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
543e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IllegalArgumentException
544e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if the set contains an invalid combination of options
545e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  UnsupportedOperationException
546e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if an unsupported open option is specified or the array contains
547e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          attributes that cannot be set atomically when creating the file
548e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  FileAlreadyExistsException
549e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if a file of that name already exists and the {@link
550e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          StandardOpenOption#CREATE_NEW CREATE_NEW} option is specified
551e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          <i>(optional specific exception)</i>
552e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IOException
553e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if an I/O error occurs
554e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
555e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          In the case of the default provider, and a security manager is
556e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          installed, the {@link SecurityManager#checkRead(String) checkRead}
557e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          method is invoked to check read access to the path if the file is
558e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          opened for reading. The {@link SecurityManager#checkWrite(String)
559e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          checkWrite} method is invoked to check write access to the path
560e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if the file is opened for writing. The {@link
561e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          SecurityManager#checkDelete(String) checkDelete} method is
562e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          invoked to check delete access if the file is opened with the
563e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          {@code DELETE_ON_CLOSE} option.
564e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
565e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public abstract SeekableByteChannel newByteChannel(Path path,
566e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException;
567e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
568e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
569e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Opens a directory, returning a {@code DirectoryStream} to iterate over
570e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * the entries in the directory. This method works in exactly the manner
571e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * specified by the {@link
572e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Files#newDirectoryStream(java.nio.file.Path, java.nio.file.DirectoryStream.Filter)}
573e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * method.
574e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
575e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   dir
576e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the path to the directory
577e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   filter
578e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the directory stream filter
579e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
580e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @return  a new and open {@code DirectoryStream} object
581e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
582e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  NotDirectoryException
583e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if the file could not otherwise be opened because it is not
584e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          a directory <i>(optional specific exception)</i>
585e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IOException
586e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if an I/O error occurs
587e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
588e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          In the case of the default provider, and a security manager is
589e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          installed, the {@link SecurityManager#checkRead(String) checkRead}
590e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          method is invoked to check read access to the directory.
591e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
592e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public abstract DirectoryStream<Path> newDirectoryStream(Path dir,
593e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera         DirectoryStream.Filter<? super Path> filter) throws IOException;
594e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
595e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
596e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Creates a new directory. This method works in exactly the manner
597e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * specified by the {@link Files#createDirectory} method.
598e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
599e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   dir
600e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the directory to create
601e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   attrs
602e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          an optional list of file attributes to set atomically when
603e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          creating the directory
604e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
605e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  UnsupportedOperationException
606e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if the array contains an attribute that cannot be set atomically
607e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          when creating the directory
608e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  FileAlreadyExistsException
609e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if a directory could not otherwise be created because a file of
610e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          that name already exists <i>(optional specific exception)</i>
611e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IOException
612e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if an I/O error occurs or the parent directory does not exist
613e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
614e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          In the case of the default provider, and a security manager is
615e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          installed, the {@link SecurityManager#checkWrite(String) checkWrite}
616e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          method is invoked to check write access to the new directory.
617e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
618e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public abstract void createDirectory(Path dir, FileAttribute<?>... attrs)
619e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        throws IOException;
620e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
621e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
622e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Creates a symbolic link to a target. This method works in exactly the
623e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * manner specified by the {@link Files#createSymbolicLink} method.
624e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
625e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <p> The default implementation of this method throws {@code
626e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * UnsupportedOperationException}.
627e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
628e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   link
629e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the path of the symbolic link to create
630e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   target
631e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the target of the symbolic link
632e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   attrs
633e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the array of attributes to set atomically when creating the
634e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          symbolic link
635e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
636e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  UnsupportedOperationException
637e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if the implementation does not support symbolic links or the
638e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          array contains an attribute that cannot be set atomically when
639e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          creating the symbolic link
640e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  FileAlreadyExistsException
641e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if a file with the name already exists <i>(optional specific
642e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          exception)</i>
643e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IOException
644e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if an I/O error occurs
645e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
646e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          In the case of the default provider, and a security manager
647e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          is installed, it denies {@link LinkPermission}<tt>("symbolic")</tt>
648e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          or its {@link SecurityManager#checkWrite(String) checkWrite}
649e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          method denies write access to the path of the symbolic link.
650e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
651e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public void createSymbolicLink(Path link, Path target, FileAttribute<?>... attrs)
652e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        throws IOException
653e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    {
654e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        throw new UnsupportedOperationException();
655e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    }
656e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
657e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
658e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Creates a new link (directory entry) for an existing file. This method
659e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * works in exactly the manner specified by the {@link Files#createLink}
660e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * method.
661e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
662e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <p> The default implementation of this method throws {@code
663e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * UnsupportedOperationException}.
664e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
665e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   link
666e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the link (directory entry) to create
667e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   existing
668e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          a path to an existing file
669e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
670e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  UnsupportedOperationException
671e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if the implementation does not support adding an existing file
672e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          to a directory
673e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  FileAlreadyExistsException
674e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if the entry could not otherwise be created because a file of
675e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          that name already exists <i>(optional specific exception)</i>
676e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IOException
677e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if an I/O error occurs
678e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
679e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          In the case of the default provider, and a security manager
680e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          is installed, it denies {@link LinkPermission}<tt>("hard")</tt>
681e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          or its {@link SecurityManager#checkWrite(String) checkWrite}
682e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          method denies write access to either the  link or the
683e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          existing file.
684e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
685e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public void createLink(Path link, Path existing) throws IOException {
686e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        throw new UnsupportedOperationException();
687e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    }
688e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
689e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
690e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Deletes a file. This method works in exactly the  manner specified by the
691e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * {@link Files#delete} method.
692e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
693e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   path
694e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the path to the file to delete
695e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
696e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  NoSuchFileException
697e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if the file does not exist <i>(optional specific exception)</i>
698e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  DirectoryNotEmptyException
699e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if the file is a directory and could not otherwise be deleted
700e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          because the directory is not empty <i>(optional specific
701e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          exception)</i>
702e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IOException
703e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if an I/O error occurs
704e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
705e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          In the case of the default provider, and a security manager is
706e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          installed, the {@link SecurityManager#checkDelete(String)} method
707e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          is invoked to check delete access to the file
708e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
709e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public abstract void delete(Path path) throws IOException;
710e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
711e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
712e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Deletes a file if it exists. This method works in exactly the manner
713e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * specified by the {@link Files#deleteIfExists} method.
714e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
715e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <p> The default implementation of this method simply invokes {@link
716e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * #delete} ignoring the {@code NoSuchFileException} when the file does not
717e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * exist. It may be overridden where appropriate.
718e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
719e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   path
720e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the path to the file to delete
721e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
722e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @return  {@code true} if the file was deleted by this method; {@code
723e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          false} if the file could not be deleted because it did not
724e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          exist
725e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
726e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  DirectoryNotEmptyException
727e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if the file is a directory and could not otherwise be deleted
728e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          because the directory is not empty <i>(optional specific
729e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          exception)</i>
730e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IOException
731e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if an I/O error occurs
732e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
733e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          In the case of the default provider, and a security manager is
734e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          installed, the {@link SecurityManager#checkDelete(String)} method
735e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          is invoked to check delete access to the file
736e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
737e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public boolean deleteIfExists(Path path) throws IOException {
738e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        try {
739e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera            delete(path);
740e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera            return true;
741e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        } catch (NoSuchFileException ignore) {
742e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera            return false;
743e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        }
744e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    }
745e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
746e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
747e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Reads the target of a symbolic link. This method works in exactly the
748e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * manner specified by the {@link Files#readSymbolicLink} method.
749e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
750e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <p> The default implementation of this method throws {@code
751e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * UnsupportedOperationException}.
752e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
753e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   link
754e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the path to the symbolic link
755e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
756e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @return  The target of the symbolic link
757e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
758e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  UnsupportedOperationException
759e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if the implementation does not support symbolic links
760e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  NotLinkException
761e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if the target could otherwise not be read because the file
762e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          is not a symbolic link <i>(optional specific exception)</i>
763e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IOException
764e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if an I/O error occurs
765e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
766e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          In the case of the default provider, and a security manager
767e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          is installed, it checks that {@code FilePermission} has been
768e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          granted with the "{@code readlink}" action to read the link.
769e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
770e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public Path readSymbolicLink(Path link) throws IOException {
771e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        throw new UnsupportedOperationException();
772e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    }
773e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
774e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
775e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Copy a file to a target file. This method works in exactly the manner
776e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * specified by the {@link Files#copy(Path,Path,CopyOption[])} method
777e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * except that both the source and target paths must be associated with
778e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * this provider.
779e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
780e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   source
781e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the path to the file to copy
782e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   target
783e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the path to the target file
784e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   options
785e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          options specifying how the copy should be done
786e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
787e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  UnsupportedOperationException
788e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if the array contains a copy option that is not supported
789e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  FileAlreadyExistsException
790e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if the target file exists but cannot be replaced because the
791e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          {@code REPLACE_EXISTING} option is not specified <i>(optional
792e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          specific exception)</i>
793e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  DirectoryNotEmptyException
794e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the {@code REPLACE_EXISTING} option is specified but the file
795e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          cannot be replaced because it is a non-empty directory
796e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          <i>(optional specific exception)</i>
797e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IOException
798e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if an I/O error occurs
799e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
800e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          In the case of the default provider, and a security manager is
801e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          installed, the {@link SecurityManager#checkRead(String) checkRead}
802e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          method is invoked to check read access to the source file, the
803e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          {@link SecurityManager#checkWrite(String) checkWrite} is invoked
804e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          to check write access to the target file. If a symbolic link is
805e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          copied the security manager is invoked to check {@link
806e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          LinkPermission}{@code ("symbolic")}.
807e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
808e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public abstract void copy(Path source, Path target, CopyOption... options)
809e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        throws IOException;
810e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
811e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
812e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Move or rename a file to a target file. This method works in exactly the
813e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * manner specified by the {@link Files#move} method except that both the
814e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * source and target paths must be associated with this provider.
815e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
816e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   source
817e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the path to the file to move
818e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   target
819e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the path to the target file
820e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   options
821e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          options specifying how the move should be done
822e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
823e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  UnsupportedOperationException
824e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if the array contains a copy option that is not supported
825e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  FileAlreadyExistsException
826e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if the target file exists but cannot be replaced because the
827e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          {@code REPLACE_EXISTING} option is not specified <i>(optional
828e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          specific exception)</i>
829e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  DirectoryNotEmptyException
830e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the {@code REPLACE_EXISTING} option is specified but the file
831e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          cannot be replaced because it is a non-empty directory
832e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          <i>(optional specific exception)</i>
833e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  AtomicMoveNotSupportedException
834e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if the options array contains the {@code ATOMIC_MOVE} option but
835e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the file cannot be moved as an atomic file system operation.
836e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IOException
837e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if an I/O error occurs
838e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
839e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          In the case of the default provider, and a security manager is
840e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          installed, the {@link SecurityManager#checkWrite(String) checkWrite}
841e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          method is invoked to check write access to both the source and
842e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          target file.
843e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
844e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public abstract void move(Path source, Path target, CopyOption... options)
845e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        throws IOException;
846e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
847e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
848e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Tests if two paths locate the same file. This method works in exactly the
849e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * manner specified by the {@link Files#isSameFile} method.
850e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
851e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   path
852e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          one path to the file
853e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   path2
854e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the other path
855e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
856e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @return  {@code true} if, and only if, the two paths locate the same file
857e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
858e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IOException
859e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if an I/O error occurs
860e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
861e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          In the case of the default provider, and a security manager is
862e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          installed, the {@link SecurityManager#checkRead(String) checkRead}
863e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          method is invoked to check read access to both files.
864e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
865e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public abstract boolean isSameFile(Path path, Path path2)
866e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        throws IOException;
867e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
868e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
869e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Tells whether or not a file is considered <em>hidden</em>. This method
870e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * works in exactly the manner specified by the {@link Files#isHidden}
871e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * method.
872e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
873e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <p> This method is invoked by the {@link Files#isHidden isHidden} method.
874e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
875e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   path
876e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the path to the file to test
877e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
878e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @return  {@code true} if the file is considered hidden
879e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
880e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IOException
881e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if an I/O error occurs
882e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
883e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          In the case of the default provider, and a security manager is
884e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          installed, the {@link SecurityManager#checkRead(String) checkRead}
885e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          method is invoked to check read access to the file.
886e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
887e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public abstract boolean isHidden(Path path) throws IOException;
888e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
889e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
890e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Returns the {@link FileStore} representing the file store where a file
891e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * is located. This method works in exactly the manner specified by the
892e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * {@link Files#getFileStore} method.
893e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
894e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   path
895e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the path to the file
896e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
897e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @return  the file store where the file is stored
898e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
899e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IOException
900e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if an I/O error occurs
901e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
902e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          In the case of the default provider, and a security manager is
903e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          installed, the {@link SecurityManager#checkRead(String) checkRead}
904e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          method is invoked to check read access to the file, and in
905e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          addition it checks {@link RuntimePermission}<tt>
906e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          ("getFileStoreAttributes")</tt>
907e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
908e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public abstract FileStore getFileStore(Path path) throws IOException;
909e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
910e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
911e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Checks the existence, and optionally the accessibility, of a file.
912e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
913e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <p> This method may be used by the {@link Files#isReadable isReadable},
914e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * {@link Files#isWritable isWritable} and {@link Files#isExecutable
915e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * isExecutable} methods to check the accessibility of a file.
916e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
917e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <p> This method checks the existence of a file and that this Java virtual
918e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * machine has appropriate privileges that would allow it access the file
919e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * according to all of access modes specified in the {@code modes} parameter
920e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * as follows:
921e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
922e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <table border=1 cellpadding=5 summary="">
923e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <tr> <th>Value</th> <th>Description</th> </tr>
924e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <tr>
925e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *   <td> {@link AccessMode#READ READ} </td>
926e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *   <td> Checks that the file exists and that the Java virtual machine has
927e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *     permission to read the file. </td>
928e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * </tr>
929e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <tr>
930e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *   <td> {@link AccessMode#WRITE WRITE} </td>
931e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *   <td> Checks that the file exists and that the Java virtual machine has
932e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *     permission to write to the file, </td>
933e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * </tr>
934e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <tr>
935e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *   <td> {@link AccessMode#EXECUTE EXECUTE} </td>
936e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *   <td> Checks that the file exists and that the Java virtual machine has
937e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *     permission to {@link Runtime#exec execute} the file. The semantics
938e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *     may differ when checking access to a directory. For example, on UNIX
939e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *     systems, checking for {@code EXECUTE} access checks that the Java
940e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *     virtual machine has permission to search the directory in order to
941e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *     access file or subdirectories. </td>
942e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * </tr>
943e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * </table>
944e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
945e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <p> If the {@code modes} parameter is of length zero, then the existence
946e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * of the file is checked.
947e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
948e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * <p> This method follows symbolic links if the file referenced by this
949e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * object is a symbolic link. Depending on the implementation, this method
950e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * may require to read file permissions, access control lists, or other
951e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * file attributes in order to check the effective access to the file. To
952e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * determine the effective access to a file may require access to several
953e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * attributes and so in some implementations this method may not be atomic
954e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * with respect to other file system operations.
955e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
956e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   path
957e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the path to the file to check
958e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   modes
959e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          The access modes to check; may have zero elements
960e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
961e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  UnsupportedOperationException
962e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          an implementation is required to support checking for
963e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          {@code READ}, {@code WRITE}, and {@code EXECUTE} access. This
964e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          exception is specified to allow for the {@code Access} enum to
965e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          be extended in future releases.
966e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  NoSuchFileException
967e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if a file does not exist <i>(optional specific exception)</i>
968e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  AccessDeniedException
969e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the requested access would be denied or the access cannot be
970e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          determined because the Java virtual machine has insufficient
971e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          privileges or other reasons. <i>(optional specific exception)</i>
972e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IOException
973e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if an I/O error occurs
974e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
975e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          In the case of the default provider, and a security manager is
976e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          installed, the {@link SecurityManager#checkRead(String) checkRead}
977e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          is invoked when checking read access to the file or only the
978e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          existence of the file, the {@link SecurityManager#checkWrite(String)
979e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          checkWrite} is invoked when checking write access to the file,
980e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          and {@link SecurityManager#checkExec(String) checkExec} is invoked
981e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          when checking execute access.
982e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
983e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public abstract void checkAccess(Path path, AccessMode... modes)
984e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        throws IOException;
985e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
986e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
987e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Returns a file attribute view of a given type. This method works in
988e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * exactly the manner specified by the {@link Files#getFileAttributeView}
989e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * method.
990e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
991e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   <V>
992e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          The {@code FileAttributeView} type
993e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   path
994e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the path to the file
995e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   type
996e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the {@code Class} object corresponding to the file attribute view
997e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   options
998e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          options indicating how symbolic links are handled
999e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
1000e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @return  a file attribute view of the specified type, or {@code null} if
1001e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the attribute view type is not available
1002e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
1003e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public abstract <V extends FileAttributeView> V
1004e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        getFileAttributeView(Path path, Class<V> type, LinkOption... options);
1005e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
1006e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
1007e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Reads a file's attributes as a bulk operation. This method works in
1008e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * exactly the manner specified by the {@link
1009e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Files#readAttributes(Path,Class,LinkOption[])} method.
1010e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
1011e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   <A>
1012e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          The {@code BasicFileAttributes} type
1013e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   path
1014e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the path to the file
1015e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   type
1016e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the {@code Class} of the file attributes required
1017e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          to read
1018e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   options
1019e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          options indicating how symbolic links are handled
1020e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
1021e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @return  the file attributes
1022e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
1023e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  UnsupportedOperationException
1024e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if an attributes of the given type are not supported
1025e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IOException
1026e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if an I/O error occurs
1027e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
1028e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          In the case of the default provider, a security manager is
1029e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          installed, its {@link SecurityManager#checkRead(String) checkRead}
1030e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          method is invoked to check read access to the file
1031e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
1032e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public abstract <A extends BasicFileAttributes> A
1033e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException;
1034e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
1035e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
1036e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Reads a set of file attributes as a bulk operation. This method works in
1037e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * exactly the manner specified by the {@link
1038e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Files#readAttributes(Path,String,LinkOption[])} method.
1039e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
1040e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   path
1041e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the path to the file
1042e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   attributes
1043e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the attributes to read
1044e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   options
1045e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          options indicating how symbolic links are handled
1046e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
1047e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @return  a map of the attributes returned; may be empty. The map's keys
1048e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          are the attribute names, its values are the attribute values
1049e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
1050e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  UnsupportedOperationException
1051e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if the attribute view is not available
1052e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IllegalArgumentException
1053e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if no attributes are specified or an unrecognized attributes is
1054e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          specified
1055e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IOException
1056e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          If an I/O error occurs
1057e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
1058e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          In the case of the default provider, and a security manager is
1059e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          installed, its {@link SecurityManager#checkRead(String) checkRead}
1060e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          method denies read access to the file. If this method is invoked
1061e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          to read security sensitive attributes then the security manager
1062e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          may be invoke to check for additional permissions.
1063e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
1064e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public abstract Map<String,Object> readAttributes(Path path, String attributes,
1065e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                                                      LinkOption... options)
1066e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        throws IOException;
1067e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera
1068e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    /**
1069e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * Sets the value of a file attribute. This method works in exactly the
1070e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * manner specified by the {@link Files#setAttribute} method.
1071e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
1072e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   path
1073e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the path to the file
1074e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   attribute
1075e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the attribute to set
1076e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   value
1077e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the attribute value
1078e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @param   options
1079e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          options indicating how symbolic links are handled
1080e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *
1081e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  UnsupportedOperationException
1082e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if the attribute view is not available
1083e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IllegalArgumentException
1084e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          if the attribute name is not specified, or is not recognized, or
1085e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          the attribute value is of the correct type but has an
1086e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          inappropriate value
1087e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  ClassCastException
1088e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          If the attribute value is not of the expected type or is a
1089e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          collection containing elements that are not of the expected
1090e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          type
1091e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  IOException
1092e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          If an I/O error occurs
1093e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     * @throws  SecurityException
1094e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          In the case of the default provider, and a security manager is
1095e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          installed, its {@link SecurityManager#checkWrite(String) checkWrite}
1096e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          method denies write access to the file. If this method is invoked
1097e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          to set security sensitive attributes then the security manager
1098e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     *          may be invoked to check for additional permissions.
1099e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera     */
1100e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera    public abstract void setAttribute(Path path, String attribute,
1101e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera                                      Object value, LinkOption... options)
1102e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera        throws IOException;
1103e6bac4bf9c85c2454ce22c91da6c654552c268e0Shubham Ajmera}
1104