Path instances, intended to complement Files.
Many methods provided by Guava's Files class for java. instances are
now available via the JDK's java. class for Path - check the JDK's
class if a sibling method from Files appears to be missing from this class.
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| private static class |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private static Collection | addException(Collection<IOException> exceptions, IOException e)
Adds the given exception to the given collection, creating the collection if it's null. |
| public static ByteSink | |
| public static ByteSource | |
| public static CharSink | asCharSink(Path path, Charset charset, OpenOption... options)
Returns a view of the given |
| public static CharSource | asCharSource(Path path, Charset charset, OpenOption... options)
Returns a view of the given |
| private static void | checkAllowsInsecure(Path path, RecursiveDeleteOption[] options)
Checks that the given options allow an insecure delete, throwing an exception if not. |
| private static Collection | concat(Collection<IOException> exceptions, Collection<IOException> other)
Concatenates the contents of the two given collections of exceptions. |
| public static void | createParentDirectories(Path path, FileAttribute<?>... attrs)
Creates any necessary but nonexistent parent directories of the specified path. |
| public static void | deleteDirectoryContents(Path path, RecursiveDeleteOption... options)
Deletes all files within the directory at the given |
| private static Collection | deleteDirectoryContentsInsecure(DirectoryStream<Path> dir)
Simple, insecure method for deleting the contents of a directory for file systems that don't
support |
| private static Collection | deleteDirectoryContentsSecure(SecureDirectoryStream<Path> dir)
Secure method for deleting the contents of a directory using |
| public static void | deleteRecursively(Path path, RecursiveDeleteOption... options)
Deletes the file or directory at the given |
| private static Collection | deleteRecursivelyInsecure(Path path)
Insecure recursive delete for file systems that don't support |
| private static Collection | deleteRecursivelySecure(SecureDirectoryStream<Path> dir, Path path)
Secure recursive delete using |
| public static boolean | |
| public static Traverser | |
| private static Iterable | |
| public static String | getFileExtension(Path path)
Returns the file extension for the file at the given path, or the empty string if the file has no extension. |
| public static String | |
| private static Path | |
| public static Predicate | isDirectory(LinkOption... options)
Returns a predicate that returns the result of |
| private static boolean | isDirectory(SecureDirectoryStream<Path> dir, Path name, LinkOption... options)
Returns whether or not the file with the given name in the given dir is a directory. |
| public static Predicate | isRegularFile(LinkOption... options)
Returns a predicate that returns the result of |
| public static ImmutableList | |
| private static NoSuchFileException | |
| private static void | throwDeleteFailed(Path path, Collection<IOException> exceptions)
Throws an exception indicating that one or more files couldn't be deleted when deleting |
| public static void |
| MoreFiles | back to summary |
|---|---|
| private MoreFiles() | |
| addException | back to summary |
|---|---|
| private static Collection Adds the given exception to the given collection, creating the collection if it's null. Returns the collection. | |
| asByteSink | back to summary |
|---|---|
| public static ByteSink asByteSink(Path path, OpenOption... options) Returns a view of the given Any open options provided are used when opening streams to the file
and may affect the behavior of the returned sink and the streams it provides. See | |
| asByteSource | back to summary |
|---|---|
| public static ByteSource asByteSource(Path path, OpenOption... options) Returns a view of the given Any open options provided are used when opening streams to the file
and may affect the behavior of the returned source and the streams it provides. See | |
| asCharSink | back to summary |
|---|---|
| public static CharSink asCharSink(Path path, Charset charset, OpenOption... options) Returns a view of the given Any open options provided are used when opening streams to the file
and may affect the behavior of the returned sink and the streams it provides. See | |
| asCharSource | back to summary |
|---|---|
| public static CharSource asCharSource(Path path, Charset charset, OpenOption... options) Returns a view of the given Any open options provided are used when opening streams to the file
and may affect the behavior of the returned source and the streams it provides. See | |
| checkAllowsInsecure | back to summary |
|---|---|
| private static void checkAllowsInsecure(Path path, RecursiveDeleteOption[] options) throws InsecureRecursiveDeleteException Checks that the given options allow an insecure delete, throwing an exception if not. | |
| concat | back to summary |
|---|---|
| private static Collection Concatenates the contents of the two given collections of exceptions. If either collection is
null, the other collection is returned. Otherwise, the elements of
| |
| createParentDirectories | back to summary |
|---|---|
| public static void createParentDirectories(Path path, FileAttribute<?>... attrs) throws IOException Creates any necessary but nonexistent parent directories of the specified path. Note that if
this operation fails, it may have succeeded in creating some (but not all) of the necessary
parent directories. The parent directory is created with the given
| |
| deleteDirectoryContents | back to summary |
|---|---|
| public static void deleteDirectoryContents(Path path, RecursiveDeleteOption... options) throws IOException Deletes all files within the directory at the given If an I/O exception occurs attempting to read, open or delete any file under the given
directory, this method skips that file and continues. All such exceptions are collected and,
after attempting to delete all files, an Warning: Security of recursive deletesOn a file system that supports symbolic links and does not support By default, this method throws
| |
| deleteDirectoryContentsInsecure | back to summary |
|---|---|
| private static Collection Simple, insecure method for deleting the contents of a directory for file systems that don't
support
| |
| deleteDirectoryContentsSecure | back to summary |
|---|---|
| private static Collection Secure method for deleting the contents of a directory using
| |
| deleteRecursively | back to summary |
|---|---|
| public static void deleteRecursively(Path path, RecursiveDeleteOption... options) throws IOException Deletes the file or directory at the given If an I/O exception occurs attempting to read, open or delete any file under the given
directory, this method skips that file and continues. All such exceptions are collected and,
after attempting to delete all files, an Warning: Security of recursive deletesOn a file system that supports symbolic links and does not support By default, this method throws
| |
| deleteRecursivelyInsecure | back to summary |
|---|---|
| private static Collection Insecure recursive delete for file systems that don't support
| |
| deleteRecursivelySecure | back to summary |
|---|---|
| private static Collection Secure recursive delete using
| |
| equal | back to summary |
|---|---|
| public static boolean equal(Path path1, Path path2) throws IOException Returns true if the files located by the given paths exist, are not directories, and contain the same bytes.
| |
| fileTraverser | back to summary |
|---|---|
| public static Traverser Returns a The returned traverser attempts to avoid following symbolic links to directories. However, the traverser cannot guarantee that it will not follow symbolic links to directories as it is possible for a directory to be replaced with a symbolic link between checking if the file is a directory and actually reading the contents of that directory. If the
Example:
| |
| fileTreeChildren | back to summary |
|---|---|
| private static Iterable | |
| getFileExtension | back to summary |
|---|---|
| public static String getFileExtension(Path path) Returns the file extension for
the file at the given path, or the empty string if the file has no extension. The result does
not include the ' Note This method simply returns everything after the last ' | |
| getNameWithoutExtension | back to summary |
|---|---|
| public static String getNameWithoutExtension(Path path) Returns the file name without its file extension or path. This is
similar to the | |
| getParentPath | back to summary |
|---|---|
| private static Path getParentPath(Path path) Returns a path to the parent directory of the given path. If the path actually has a parent path, this is simple. Otherwise, we need to do some trickier things. Returns null if the path is a root or is the empty path.
| |
| isDirectory | back to summary |
|---|---|
| public static Predicate Returns a predicate that returns the result of | |
| isDirectory | back to summary |
|---|---|
| private static boolean isDirectory(SecureDirectoryStream<Path> dir, Path name, LinkOption... options) throws IOException Returns whether or not the file with the given name in the given dir is a directory. | |
| isRegularFile | back to summary |
|---|---|
| public static Predicate Returns a predicate that returns the result of | |
| listFiles | back to summary |
|---|---|
| public static ImmutableList Returns an immutable list of paths to the files contained in the given directory.
| |
| pathNotFound | back to summary |
|---|---|
private static NoSuchFileException pathNotFound(Path path, Collection<IOException> exceptions)
| |
| throwDeleteFailed | back to summary |
|---|---|
| private static void throwDeleteFailed(Path path, Collection<IOException> exceptions) throws FileSystemException Throws an exception indicating that one or more files couldn't be deleted when deleting If there is only one exception in the collection, and it is a | |
| touch | back to summary |
|---|---|
| public static void touch(Path path) throws IOException Like the unix command of the same name, creates an empty file or updates the last modified timestamp of the existing file at the given path to the current system time.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final OpenOption[] | |
| private final Path |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public OutputStream | openStream()
Implements abstract com. OutputStream for writing to this sink.
|
| public String |
| options | back to summary |
|---|---|
| private final OpenOption[] options | |
| path | back to summary |
|---|---|
| private final Path path | |
| PathByteSink | back to summary |
|---|---|
| private PathByteSink(Path path, OpenOption... options) | |
| openStream | back to summary |
|---|---|
| public OutputStream openStream() throws IOException Implements abstract com. Doc from com. Opens a new The caller is responsible for ensuring that the returned stream is closed.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| Modifier and Type | Field and Description |
|---|---|
| private static final LinkOption[] | |
| private final boolean | |
| private final OpenOption[] | |
| private final Path |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public CharSource | asCharSource(Charset charset)
Overrides com. CharSource view of this byte source that decodes bytes read from this source
as characters using the given Charset.
|
| private static boolean | |
| public InputStream | openStream()
Implements abstract com. InputStream for reading from this source.
|
| public byte[] | read()
Overrides com. |
| private BasicFileAttributes | |
| public long | size()
Overrides com. |
| public Optional | sizeIfKnown()
Overrides com. |
| public String |
| FOLLOW_LINKS | back to summary |
|---|---|
| private static final LinkOption[] FOLLOW_LINKS | |
| followLinks | back to summary |
|---|---|
| private final boolean followLinks | |
| options | back to summary |
|---|---|
| private final OpenOption[] options | |
| path | back to summary |
|---|---|
| private final Path path | |
| PathByteSource | back to summary |
|---|---|
| private PathByteSource(Path path, OpenOption... options) | |
| asCharSource | back to summary |
|---|---|
| public CharSource asCharSource(Charset charset) Overrides com. Doc from com. Returns a If
| |
| followLinks | back to summary |
|---|---|
| private static boolean followLinks(OpenOption[] options) | |
| openStream | back to summary |
|---|---|
| public InputStream openStream() throws IOException Implements abstract com. Doc from com. Opens a new The caller is responsible for ensuring that the returned stream is closed.
| |
| read | back to summary |
|---|---|
| public byte[] read() throws IOException Overrides com. Doc from com. Reads the full contents of this byte source as a byte array.
| |
| readAttributes | back to summary |
|---|---|
| private BasicFileAttributes readAttributes() throws IOException | |
| size | back to summary |
|---|---|
| public long size() throws IOException Overrides com. Doc from com. Returns the size of this source in bytes, even if doing so requires opening and traversing an
entire stream. To avoid a potentially expensive operation, see The default implementation calls Note that for some sources that implement In either case, for mutable sources such as files, a subsequent read may return a different number of bytes if the contents are changed.
| |
| sizeIfKnown | back to summary |
|---|---|
| public Optional Overrides com. Doc from com. Returns the size of this source in bytes, if the size can be easily determined without actually opening the data stream. The default implementation returns Additionally, for mutable sources such as files, a subsequent read may return a different number of bytes if the contents are changed.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |