| Modifier and Type | Field and Description |
|---|---|
protected static Set<Watchable> |
REGISTERED_WATCHER_PATHS
A collection of
Watchable paths that have already been registered
with the #FILE_CHANGE_WATCHER. |
| Modifier | Constructor and Description |
|---|---|
protected |
FileOps() |
| Modifier and Type | Method and Description |
|---|---|
static void |
append(String content,
String file)
Write the String
content to the end of the file,
preserving anything that was previously there. |
static void |
awaitChange(String file)
Cause the current thread to block while waiting for a change to
file. |
static void |
awaitChangeInterruptibly(String file)
Cause the current thread to block while waiting for a change to
file. |
static String |
expandPath(String path)
Expand the given
path so that it contains completely normalized
components (e.g. |
static String |
expandPath(String path,
String cwd)
Expand the given
path so that it contains completely normalized
components (e.g. |
static String |
getUserHome()
Return the home directory of the user of the parent process for this JVM.
|
static String |
getWorkingDirectory()
Get the working directory of this JVM, which is the directory from which
the process is launched.
|
static boolean |
isDirectory(String path)
Return
true if the specified path is that of a directory
and not a flat file. |
static void |
mkdirs(String path)
Create the directories named by
path, including any necessary,
but nonexistent parent directories. |
static DirectoryStream<Path> |
newDirectoryStream(Path dir)
Return a
DirectoryStream in the same manner as
Files.newDirectoryStream(Path) without throwing a
checked exception. |
static String |
read(String file)
Read the contents of
file into a UTF-8 string. |
static List<String> |
readLines(String file)
Return a list that lazily accumulates lines in the underlying
file. |
static List<String> |
readLines(String file,
String cwd)
Return a list that lazily accumulates lines in the underlying
file. |
static String |
tempDir(String prefix)
Create a temporary directory with the specified
prefix. |
static String |
tempFile()
Create a temporary file that is likely to be deleted some time after this
JVM terminates, but definitely not before.
|
static String |
tempFile(String prefix)
Create a temporary file that is likely to be deleted some time after this
JVM terminates, but definitely not before.
|
static String |
tempFile(String prefix,
String suffix)
Create a temporary file that is likely to be deleted some time after this
JVM terminates, but definitely not before.
|
static String |
tempFile(String dir,
String prefix,
String suffix)
Create a temporary file that is likely to be deleted some time after this
JVM terminates, but definitely not before.
|
static String |
touch(String file)
Create an empty file or update the last updated timestamp on the same as
the unix command of the same name.
|
static URL |
toURL(String path)
A shortcut for getting a
URL instance from a file path. |
static void |
write(String content,
String file)
Write the String
content to the file, overwriting
anything that was previously there. |
public static void append(String content, String file)
content to the end of the file,
preserving anything that was previously there.content - the data to writefile - the path to the filepublic static void awaitChange(String file)
file.
Because of limitations of most underlying file systems, this method can only guarantee changes that occur at least 1 second after this method is invoked. For changes that occur less than 1 second of method invocation, the method will return immediately; however, there is a chance that such a return is indicative of a false positive case where the file changed before this method was invoked, but within the same second of the invocation.
If protection against that kind of false positive is important, the caller should check the contents of the underlying file is this method returns immediately.
file - the path to a regular filepublic static void awaitChangeInterruptibly(String file) throws InterruptedException
file.
Because of limitations of most underlying file systems, this method can only guarantee changes that occur at least 1 second after this method is invoked. For changes that occur less than 1 second of method invocation, the method will return immediately; however, there is a chance that such a return is indicative of a false positive case where the file changed before this method was invoked, but within the same second of the invocation.
If protection against that kind of false positive is important, the caller should check the contents of the underlying file is this method returns immediately.
file - the path to a regular fileInterruptedExceptionpublic static String expandPath(String path)
path so that it contains completely normalized
components (e.g. ".", "..", and "~" are resolved to the correct absolute
paths).path - public static String expandPath(String path, String cwd)
path so that it contains completely normalized
components (e.g. ".", "..", and "~" are resolved to the correct absolute
paths).path - cwd - public static String getUserHome()
public static String getWorkingDirectory()
public static boolean isDirectory(String path)
true if the specified path is that of a directory
and not a flat file.path - the path to checktrue if the path is that of a directorypublic static void mkdirs(String path)
path, including any necessary,
but nonexistent parent directories.
NOTE: If this operation fails, it may have succeeded in creating some of the necessary parent directories.
path - the path of directories to createpublic static DirectoryStream<Path> newDirectoryStream(Path dir)
DirectoryStream in the same manner as
Files.newDirectoryStream(Path) without throwing a
checked exception.dir - the Path for the directoryDirectoryStreampublic static String read(String file)
file into a UTF-8 string.file - public static List<String> readLines(String file)
file.
This method is really just syntactic sugar for reading lines from a file, so the returned list doesn't actually allow any operations other than forward iteration.
file - public static List<String> readLines(String file, String cwd)
file.
This method is really just syntactic sugar for reading lines from a file, so the returned list doesn't actually allow any operations other than forward iteration.
file - cwd - public static String tempDir(String prefix)
prefix.prefix - the directory name prefixpublic static String tempFile()
public static String tempFile(String prefix)
prefix - the prefix for the temp filepublic static String tempFile(String prefix, String suffix)
prefix - the prefix for the temp filesuffix - the suffix for the temp filepublic static String tempFile(String dir, String prefix, String suffix)
dir - the absolute path to the directory in which the temp file
should be createdprefix - the prefix for the temp filesuffix - the suffix for the temp filepublic static String touch(String file)
file - the path of the file to touchfile in case it needs to be passed to a
super constructorpublic static URL toURL(String path)
URL instance from a file path.path - the path to the file or directoryURL that corresponds to path