@ParametersAreNonnullByDefault public abstract class FileSystemProviderBase extends FileSystemProvider
FileSystemProvider
implementation
Important note: in order to match the behaviour of the default filesystems, you should be aware of the following:
copy
operation will not
perform recursive copies; if the source is a non empty directory, the
operation fails with DirectoryNotEmptyException
. This class
enforces this behaviour if the source and target paths are not on the
same filesystem
; if they are, this is then
delegated to your own copy
implementation
.move
operation exists and is a non empty directory, and you selected to
replace the existing target path, the operation fails with DirectoryNotEmptyException
; if the source and target paths are not on
the same filesystem, this behaviour is enforced by this class; if they
are on the same filesystem, this is delegated to your own move implementation
.
delete(Path)
and FileSystemProvider.deleteIfExists(Path)
do not perform recursive deletions; if the target
is a non empty directory, this method throws DirectoryNotEmptyException
.All methods of this class which accept options as arguments will check the validity of these options before performing the actual operation. Two exceptions are possible when checking options:
Modifier and Type | Field and Description |
---|---|
protected FileSystemOptionsFactory |
optionsFactory |
protected FileSystemRepository |
repository |
Modifier | Constructor and Description |
---|---|
protected |
FileSystemProviderBase(FileSystemRepository repository) |
Modifier and Type | Method and Description |
---|---|
void |
checkAccess(Path path,
AccessMode... modes)
Check whether a path exists and can be accessed using the given modes
|
void |
copy(Path source,
Path target,
CopyOption... options)
Copy a source path to a target path
|
void |
createDirectory(Path dir,
FileAttribute<?>... attrs)
Create a directory
|
void |
delete(Path path)
Delete an entry on the filesystem
|
<V extends FileAttributeView> |
getFileAttributeView(Path path,
Class<V> type,
LinkOption... options) |
FileStore |
getFileStore(Path path) |
FileSystem |
getFileSystem(URI uri) |
Path |
getPath(URI uri) |
String |
getScheme() |
boolean |
isHidden(Path path)
Tell whether the filesystem object pointed by the path (if any) is hidden
|
boolean |
isSameFile(Path path,
Path path2)
Tell whether two paths represent exactly the same filesystem objects
|
void |
move(Path source,
Path target,
CopyOption... options)
Move a source path to a target path
|
SeekableByteChannel |
newByteChannel(Path path,
Set<? extends OpenOption> options,
FileAttribute<?>... attrs)
TODO: throws UnsupportedOperationException if attributes are specified
|
DirectoryStream<Path> |
newDirectoryStream(Path dir,
DirectoryStream.Filter<? super Path> filter)
Open a new directory stream from a target path
|
FileSystem |
newFileSystem(URI uri,
Map<String,?> env) |
InputStream |
newInputStream(Path path,
OpenOption... options)
Open an input stream to an existing path
|
OutputStream |
newOutputStream(Path path,
OpenOption... options)
Open an output stream to a given path
|
<A extends BasicFileAttributes> |
readAttributes(Path path,
Class<A> type,
LinkOption... options) |
Map<String,Object> |
readAttributes(Path path,
String attributes,
LinkOption... options) |
void |
setAttribute(Path path,
String attribute,
Object value,
LinkOption... options) |
createLink, createSymbolicLink, deleteIfExists, installedProviders, newAsynchronousFileChannel, newFileChannel, newFileSystem, readSymbolicLink
protected final FileSystemRepository repository
protected final FileSystemOptionsFactory optionsFactory
protected FileSystemProviderBase(FileSystemRepository repository)
public final String getScheme()
getScheme
in class FileSystemProvider
public final FileSystem newFileSystem(URI uri, Map<String,?> env) throws IOException
newFileSystem
in class FileSystemProvider
IOException
public final FileSystem getFileSystem(URI uri)
getFileSystem
in class FileSystemProvider
public final Path getPath(URI uri)
getPath
in class FileSystemProvider
public final InputStream newInputStream(Path path, OpenOption... options) throws IOException
This method checks the existence of the file before delegating the creation of the input stream to the relevant driver. The driver is also responsible to deal with the target not being a directory.
newInputStream
in class FileSystemProvider
path
- the path to openoptions
- open optionsNoSuchFileException
- file does not existIOException
- other I/O exceptionFileSystemDriver.newInputStream(Path, Set)
public final OutputStream newOutputStream(Path path, OpenOption... options) throws IOException
This class performs the following checks before delegating to the driver:
StandardOpenOption.CREATE_NEW
is specified and the
file already exists, throws FileAlreadyExistsException
;StandardOpenOption.CREATE
is not set, throws NoSuchFileException
;AccessDeniedException
.All other checks, such as for instance the target being a directory and not a file, are left to the driver.
newOutputStream
in class FileSystemProvider
path
- the path to openoptions
- the set of open optionsFileAlreadyExistsException
- StandardOpenOption.CREATE_NEW
was specified but the target already existsAccessDeniedException
- target exists but cannot be written toIOException
- other I/O exceptionFileSystemDriver.newOutputStream(Path, Set)
public final SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException
newByteChannel
in class FileSystemProvider
path
- the path to open a channel tooptions
- the set of optionsattrs
- file attributes to set if file is createdIOException
- error creating the channelFileSystemDriver.newByteChannel(Path, Set, FileAttribute[])
public final DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter) throws IOException
This method checks that the target path exists and that the process has read access to it before delegating the directory stream creation to the driver.
It is up to the driver to perform other checks (such as whether the target path is indeed a directory).
newDirectoryStream
in class FileSystemProvider
dir
- the pathfilter
- a filter for directory entriesNoSuchFileException
- target path does not existIOException
- other I/O exceptionFileSystemDriver.newDirectoryStream(Path, DirectoryStream.Filter)
public final void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException
TODO: UnsupportedOperationException if any attributes are specified
createDirectory
in class FileSystemProvider
dir
- the directory to createattrs
- attributes to the created directoryIOException
- directory creation failedFileSystemDriver.createDirectory(Path, FileAttribute[])
public final void delete(Path path) throws IOException
This method will check whether the path actually exists before delegating to the driver.
Recall: this operation does not perform
recursive deletions. It is up to the driver to check whether the target
is a non empty directory, and fail with DirectoryNotEmptyException
if this is the case.
delete
in class FileSystemProvider
path
- the path to deleteNoSuchFileException
- target does not existIOException
- other I/O errorFileSystemDriver.delete(Path)
public final void copy(Path source, Path target, CopyOption... options) throws IOException
This method will do the following before performing the actual copy:
StandardCopyOption.REPLACE_EXISTING
is not set, check
that the destination path does not exist.Il will then delegate to the relevant driver if and only if both paths
are issued from the same FileSystem
. If not, it performs the copy
itself.
Note that recursive copies are NOT performed by this method. Similarly, the driver SHOULD NOT perform recursive copies.
copy
in class FileSystemProvider
source
- the source pathtarget
- the target pathoptions
- the copy optionsNoSuchFileException
- source path does not existFileAlreadyExistsException
- destination path exists and StandardCopyOption.REPLACE_EXISTING
was not setIOException
- other I/O errorFileSystemDriver.copy(Path, Path, Set)
public final void move(Path source, Path target, CopyOption... options) throws IOException
This method will perform the following checks
NoSuchFileException
;StandardCopyOption.REPLACE_EXISTING
is not set, throws FileAlreadyExistsException
.From this point on, it will delegate to the driver if and only if both the source and target are on the same filesystem. If this is not the case, TODO: implement metadata driver, for now it sucks
move
in class FileSystemProvider
source
- the path to movetarget
- the destination pathoptions
- the set of copy optionsNoSuchFileException
- the source does not existFileAlreadyExistsException
- the target exists and StandardCopyOption.REPLACE_EXISTING
was not setIOException
- other I/O exceptionFileSystemDriver.move(Path, Path, Set)
public final boolean isSameFile(Path path, Path path2) throws IOException
This method checks that both paths exist and have the same driver (which is the same as checking whether they are on the same filesystem, since no two filesystems share a driver), and then delegates to the driver to perform additional checks.
isSameFile
in class FileSystemProvider
path
- the first pathpath2
- the second pathNoSuchFileException
- one, or both, paths do not existIOException
- error processing one, or both, pathsFileSystemDriver.isSameFile(Path, Path)
public final boolean isHidden(Path path) throws IOException
Typically, on Unix systems, this will be for paths whose last name component (if any) starts with a dot.
isHidden
in class FileSystemProvider
path
- the path to checkIOException
- error accessing path informationFileSystemDriver.isSameFile(Path, Path)
public final void checkAccess(Path path, AccessMode... modes) throws IOException
Passing no modes argument typically only makes an existence check.
checkAccess
in class FileSystemProvider
path
- the path to checkmodes
- the modes to check againstIOException
- error accessing path informationFileSystemDriver.checkAccess(Path, AccessMode...)
public final <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options)
getFileAttributeView
in class FileSystemProvider
public final <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException
readAttributes
in class FileSystemProvider
IOException
public final Map<String,Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException
readAttributes
in class FileSystemProvider
IOException
public final void setAttribute(Path path, String attribute, Object value, LinkOption... options) throws IOException
setAttribute
in class FileSystemProvider
IOException
public final FileStore getFileStore(Path path) throws IOException
getFileStore
in class FileSystemProvider
IOException