java.lang.Object
com.aoapps.io.filesystems.JavaFileSystem
- All Implemented Interfaces:
FileSystem
Wraps any standard FileSystem implementation.
The system is treated as a single-root file system. For Windows, this means
that C:\
will become /C:/
.
Note: To work with any possible filename correctly in Linux, one must use a single-byte locale, such as "C", "POSIX", or "en_US". Java has issues when using UTF-8 encoding and filenames do not contain valid UTF-8.
- Author:
- AO Industries, Inc.
-
Field Summary
Modifier and TypeFieldDescriptionprotected final boolean
protected final FileSystem
static final int
The maximum name length. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
checkSubPath
(Path parent, String name) Checks that a given path name is acceptable to this file system.createDirectory
(Path path) Atomically creates a directory (must not have already existed).createFile
(Path path) Atomically creates an empty file (must not have already existed).void
Deletes the file system object at the given path.static JavaFileSystem
Gets the wrapper for the default file system implement by the Java runtime, only one instance is created.protected Path
getJavaPath
(Path path) Gets a Java File for the given path.Lists the children of the given path in no specific order.Locks a file in exclusive mode.long
Gets the size of the file system object at the given path.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.aoapps.io.filesystems.FileSystem
join, parsePath
-
Field Details
-
MAX_PATH_NAME_LENGTH
public static final int MAX_PATH_NAME_LENGTHThe maximum name length. Until Java exposes a reasonable way to detect this, we'll just leave it hard-coded.- See Also:
-
javaFileSystem
-
isSingleRoot
protected final boolean isSingleRoot
-
-
Constructor Details
-
JavaFileSystem
Creates a new Java filesystem.
-
-
Method Details
-
getDefault
Gets the wrapper for the default file system implement by the Java runtime, only one instance is created. -
checkSubPath
Checks that a given path name is acceptable to this file system. Regular path rules are already checked, this is for additional file system specific constraints. The root path is never passed here.General filename restrictions are:
- Must not be longer than
MAX_PATH_NAME_LENGTH
characters - Must not contain the NULL character
- Must not contain the current platform separator character
- Must not be any length sequence of only "." characters (this protects Windows multi-dot, too)
- Specified by:
checkSubPath
in interfaceFileSystem
- Parameters:
name
- The path to check, must be from this file system.- Throws:
InvalidPathException
- If the path is not acceptable
- Must not be longer than
-
getJavaPath
Gets a Java File for the given path.- Throws:
InvalidPathException
- If the path is not acceptableIOException
-
list
Description copied from interface:FileSystem
Lists the children of the given path in no specific order. It is possible that paths may be returned that no longer exist. It is also possible that new file system objects created after the beginning of iteration are not returned.- Specified by:
list
in interfaceFileSystem
- Parameters:
path
- Must be from this file system.- Returns:
- a read-only iterator of children
- Throws:
IOException
- if an underlying I/O error occurs.
-
delete
Description copied from interface:FileSystem
Deletes the file system object at the given path.- Specified by:
delete
in interfaceFileSystem
- Parameters:
path
- Must be from this file system.- Throws:
IOException
- if an underlying I/O error occurs.
-
size
Description copied from interface:FileSystem
Gets the size of the file system object at the given path.- Specified by:
size
in interfaceFileSystem
- Parameters:
path
- Must be from this file system.- Throws:
IOException
- if an underlying I/O error occurs.
-
createFile
Description copied from interface:FileSystem
Atomically creates an empty file (must not have already existed).- Specified by:
createFile
in interfaceFileSystem
- Returns:
- returns the path
- Throws:
IOException
- if an underlying I/O error occurs.
-
createDirectory
Description copied from interface:FileSystem
Atomically creates a directory (must not have already existed).- Specified by:
createDirectory
in interfaceFileSystem
- Returns:
- returns the path
- Throws:
IOException
- if an underlying I/O error occurs.
-
lock
Description copied from interface:FileSystem
Locks a file in exclusive mode. File range and shared locks not currently supported. The lock must be closed to unlock, usually in a try/finally or try-with-resources block. The locks are not reentrant, attempting to obtain the lock from the same thread will result in deadlock.- Specified by:
lock
in interfaceFileSystem
- Throws:
IOException
- if an underlying I/O error occurs.- See Also:
-