Class FilesPlume
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
A FilenameFilter that accepts files whose name matches the given wildcard. -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable Integer
available
(InputStream is) CallsInputStream.available()
, but returns null instead of throwing an IOException.static boolean
canCreateAndWrite
(File file) Returns true if the file exists and is writable, or if the file can be created.static long
countLines
(String filename) Count the number of lines in the specified file.static File
createTempDir
(String prefix, String suffix) Creates an empty directory in the default temporary-file directory, using the given prefix and suffix to generate its name.static Path
createTempFile
(String prefix, String suffix, FileAttribute<?>... attrs) Creates a new empty file in the default temporary-file directory, using the given prefix and suffix strings to generate its name.static Path
createTempFile
(Path dir, String prefix, String suffix, FileAttribute<?>... attrs) Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name.static boolean
Deletes the directory at dir and all its files.static boolean
Deletes the directory at dirName and all its files.static boolean
equalFiles
(String file1, String file2) Returns true iff files have the same contents.static boolean
equalFiles
(String file1, String file2, boolean trimLines) Returns true iff the files have the same contents.static File
expandFilename
(File name) Does tilde expansion on a file name (to the user's home directory).static String
expandFilename
(String name) Does tilde expansion on a file name (to the user's home directory).static String
fileContents
(File file) Deprecated.static String
inferLineSeparator
(File file) Tries to infer the line separator used in a file.static String
inferLineSeparator
(String filename) Tries to infer the line separator used in a file.static @Nullable Boolean
isWhitespaceOnly
(InputStream is, @org.checkerframework.checker.index.qual.Positive int readLimit) Returns true if the firstreadLimit
bytes of the input stream consist only of whitespace.static String
javaSource
(File name) Returns a string version of the filename that can be used in Java source.static BufferedOutputStream
newBufferedFileOutputStream
(String filename, boolean append) Returns a BufferedOutputStream for the file, accounting for the possibility that the file is compressed.static BufferedReader
newBufferedFileReader
(File file) Returns a BufferedReader for the file, accounting for the possibility that the file is compressed.static BufferedReader
newBufferedFileReader
(File file, @Nullable String charsetName) Returns a BufferedReader for the file, accounting for the possibility that the file is compressed.static BufferedReader
newBufferedFileReader
(String filename) Returns a BufferedReader for the file, accounting for the possibility that the file is compressed.static BufferedReader
newBufferedFileReader
(String filename, @Nullable String charsetName) Returns a BufferedReader for the file, accounting for the possibility that the file is compressed.static BufferedWriter
newBufferedFileWriter
(String filename) Returns a BufferedWriter for the file, accounting for the possibility that the file is compressed.static BufferedWriter
newBufferedFileWriter
(String filename, boolean append) Returns a BufferedWriter for the file, accounting for the possibility that the file is compressed.static InputStream
newFileInputStream
(File file) Returns an InputStream for the file, accounting for the possibility that the file is compressed.static InputStream
newFileInputStream
(Path path) Returns an InputStream for the file, accounting for the possibility that the file is compressed.static OutputStream
newFileOutputStream
(File file) Returns an OutputStream for the file, accounting for the possibility that the file is compressed.static OutputStream
newFileOutputStream
(Path path) Returns an OutputStream for the file, accounting for the possibility that the file is compressed.static OutputStream
newFileOutputStream
(Path path, boolean append) Returns an OutputStream for the file, accounting for the possibility that the file is compressed.static InputStreamReader
newFileReader
(File file) Returns a Reader for the file, accounting for the possibility that the file is compressed.static InputStreamReader
newFileReader
(File file, @Nullable String charsetName) Returns a Reader for the file, accounting for the possibility that the file is compressed.static InputStreamReader
newFileReader
(String filename) Returns a Reader for the file, accounting for the possibility that the file is compressed.static InputStreamReader
newFileReader
(Path path) Returns a Reader for the file, accounting for the possibility that the file is compressed.static InputStreamReader
newFileReader
(Path path, @Nullable String charsetName) Returns a Reader for the file, accounting for the possibility that the file is compressed.static OutputStreamWriter
newFileWriter
(File file) Returns a Writer for the file, accounting for the possibility that the file is compressed.static OutputStreamWriter
newFileWriter
(File file, @Nullable String charsetName) Returns a Writer for the file, accounting for the possibility that the file is compressed.static OutputStreamWriter
newFileWriter
(String filename) Returns a Writer for the file, accounting for the possibility that the file is compressed.static OutputStreamWriter
newFileWriter
(Path path) Returns a Writer for the file, accounting for the possibility that the file is compressed.static OutputStreamWriter
newFileWriter
(Path path, @Nullable String charsetName) Returns a Writer for the file, accounting for the possibility that the file is compressed.static LineNumberReader
newLineNumberFileReader
(File file) Returns a LineNumberReader for the file, accounting for the possibility that the file is compressed.static LineNumberReader
newLineNumberFileReader
(String filename) Returns a LineNumberReader for the file, accounting for the possibility that the file is compressed.static int
Reads a Unicode code point from an input stream.static String
Reads the entire contents of the reader and returns it as a string.static String
Deprecated.Read the entire contents of the file and return it as a list of lines.static Object
readObject
(File file) Reads an Object from a File.static String
readString
(Path path) Reads the entire contents of the file and returns it as a string.static void
streamCopy
(InputStream from, OutputStream to) Copy the contents of the input stream to the output stream.streamLines
(InputStream stream) Reads all lines from the stream and returns them in aList<String>
.static String
Returns a String containing all the characters from the input stream.static void
Deprecated.static void
writeObject
(Object o, File file) Writes an Object to a File.static void
writeString
(File file, String contents) Creates a file with the given name and writes the specified string to it.static void
writeString
(Path path, String contents) Creates a file with the given name and writes the specified string to it.
-
Method Details
-
newFileInputStream
Returns an InputStream for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
path
- the possibly-compressed file to read- Returns:
- an InputStream for file
- Throws:
IOException
- if there is trouble reading the file
-
newFileInputStream
Returns an InputStream for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
file
- the possibly-compressed file to read- Returns:
- an InputStream for file
- Throws:
IOException
- if there is trouble reading the file
-
newFileReader
public static InputStreamReader newFileReader(String filename) throws FileNotFoundException, IOException Returns a Reader for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
filename
- the possibly-compressed file to read- Returns:
- an InputStream for filename
- Throws:
IOException
- if there is trouble reading the fileFileNotFoundException
- if the file is not found
-
newFileReader
Returns a Reader for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
path
- the possibly-compressed file to read- Returns:
- an InputStreamReader for file
- Throws:
FileNotFoundException
- if the file cannot be foundIOException
- if there is trouble reading the file
-
newFileReader
public static InputStreamReader newFileReader(Path path, @Nullable String charsetName) throws FileNotFoundException, IOException Returns a Reader for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
path
- the possibly-compressed file to readcharsetName
- the name of a Charset to use when reading the file, or null to use UTF-8- Returns:
- an InputStreamReader for file
- Throws:
FileNotFoundException
- if the file cannot be foundIOException
- if there is trouble reading the file
-
newFileReader
Returns a Reader for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
file
- the possibly-compressed file to read- Returns:
- an InputStreamReader for file
- Throws:
FileNotFoundException
- if the file cannot be foundIOException
- if there is trouble reading the file
-
newFileReader
public static InputStreamReader newFileReader(File file, @Nullable String charsetName) throws FileNotFoundException, IOException Returns a Reader for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
file
- the possibly-compressed file to readcharsetName
- the name of a Charset to use when reading the file, or null to use UTF-8- Returns:
- an InputStreamReader for file
- Throws:
FileNotFoundException
- if the file cannot be foundIOException
- if there is trouble reading the file
-
newBufferedFileReader
public static BufferedReader newBufferedFileReader(String filename) throws FileNotFoundException, IOException Returns a BufferedReader for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
filename
- the possibly-compressed file to read- Returns:
- a BufferedReader for file
- Throws:
FileNotFoundException
- if the file cannot be foundIOException
- if there is trouble reading the file
-
newBufferedFileReader
public static BufferedReader newBufferedFileReader(File file) throws FileNotFoundException, IOException Returns a BufferedReader for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
file
- the possibility-compressed file to read- Returns:
- a BufferedReader for file
- Throws:
FileNotFoundException
- if the file cannot be foundIOException
- if there is trouble reading the file
-
newBufferedFileReader
public static BufferedReader newBufferedFileReader(String filename, @Nullable String charsetName) throws FileNotFoundException, IOException Returns a BufferedReader for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
filename
- the possibly-compressed file to readcharsetName
- the character set to use when reading the file, or null to use UTF-8- Returns:
- a BufferedReader for filename
- Throws:
FileNotFoundException
- if the file cannot be foundIOException
- if there is trouble reading the file
-
newBufferedFileReader
public static BufferedReader newBufferedFileReader(File file, @Nullable String charsetName) throws FileNotFoundException, IOException Returns a BufferedReader for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
file
- the possibly-compressed file to readcharsetName
- the character set to use when reading the file, or null to use UTF-8- Returns:
- a BufferedReader for file
- Throws:
FileNotFoundException
- if the file cannot be foundIOException
- if there is trouble reading the file
-
newLineNumberFileReader
public static LineNumberReader newLineNumberFileReader(String filename) throws FileNotFoundException, IOException Returns a LineNumberReader for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
filename
- the possibly-compressed file to read- Returns:
- a LineNumberReader for filename
- Throws:
FileNotFoundException
- if the file cannot be foundIOException
- if there is trouble reading the file
-
newLineNumberFileReader
public static LineNumberReader newLineNumberFileReader(File file) throws FileNotFoundException, IOException Returns a LineNumberReader for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
file
- the possibly-compressed file to read- Returns:
- a LineNumberReader for file
- Throws:
FileNotFoundException
- if the file cannot be foundIOException
- if there is trouble reading the file
-
newFileOutputStream
Returns an OutputStream for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
path
- the possibly-compressed file to read- Returns:
- an OutputStream for file
- Throws:
IOException
- if there is trouble reading the file
-
newFileOutputStream
Returns an OutputStream for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
path
- the possibly-compressed file to readappend
- if true, then bytes will be written to the end of the file rather than the beginning- Returns:
- an OutputStream for file
- Throws:
IOException
- if there is trouble reading the file
-
newFileOutputStream
Returns an OutputStream for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
file
- the possibly-compressed file to read- Returns:
- an OutputStream for file
- Throws:
IOException
- if there is trouble reading the file
-
newFileWriter
public static OutputStreamWriter newFileWriter(String filename) throws FileNotFoundException, IOException Returns a Writer for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
filename
- the possibly-compressed file to read- Returns:
- an OutputStream for filename
- Throws:
IOException
- if there is trouble reading the fileFileNotFoundException
- if the file is not found
-
newFileWriter
Returns a Writer for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
path
- the possibly-compressed file to read- Returns:
- an OutputStreamWriter for file
- Throws:
FileNotFoundException
- if the file cannot be foundIOException
- if there is trouble reading the file
-
newFileWriter
public static OutputStreamWriter newFileWriter(Path path, @Nullable String charsetName) throws FileNotFoundException, IOException Returns a Writer for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
path
- the possibly-compressed file to readcharsetName
- the name of a Charset to use when reading the file, or null to use UTF-8- Returns:
- an OutputStreamWriter for file
- Throws:
FileNotFoundException
- if the file cannot be foundIOException
- if there is trouble reading the file
-
newFileWriter
Returns a Writer for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
file
- the possibly-compressed file to read- Returns:
- an OutputStreamWriter for file
- Throws:
FileNotFoundException
- if the file cannot be foundIOException
- if there is trouble reading the file
-
newFileWriter
public static OutputStreamWriter newFileWriter(File file, @Nullable String charsetName) throws FileNotFoundException, IOException Returns a Writer for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
file
- the possibly-compressed file to readcharsetName
- the name of a Charset to use when reading the file, or null to use UTF-8- Returns:
- an OutputStreamWriter for file
- Throws:
FileNotFoundException
- if the file cannot be foundIOException
- if there is trouble reading the file
-
newBufferedFileWriter
Returns a BufferedWriter for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
filename
- the possibly-compressed file to write- Returns:
- a BufferedWriter for filename
- Throws:
IOException
- if there is trouble writing the file
-
newBufferedFileWriter
public static BufferedWriter newBufferedFileWriter(String filename, boolean append) throws IOException Returns a BufferedWriter for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
filename
- the possibly-compressed file to writeappend
- if true, the resulting BufferedWriter appends to the end of the file instead of the beginning- Returns:
- a BufferedWriter for filename
- Throws:
IOException
- if there is trouble writing the file
-
newBufferedFileOutputStream
public static BufferedOutputStream newBufferedFileOutputStream(String filename, boolean append) throws IOException Returns a BufferedOutputStream for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
- Parameters:
filename
- the possibly-compressed file to writeappend
- if true, the resulting BufferedOutputStream appends to the end of the file instead of the beginning- Returns:
- a BufferedOutputStream for filename
- Throws:
IOException
- if there is trouble writing the file
-
countLines
Count the number of lines in the specified file.- Parameters:
filename
- file whose size to count- Returns:
- number of lines in filename
- Throws:
IOException
- if there is trouble reading the file
-
inferLineSeparator
Tries to infer the line separator used in a file.- Parameters:
filename
- the file to infer a line separator from- Returns:
- the inferred line separator used in filename
- Throws:
IOException
- if there is trouble reading the file
-
inferLineSeparator
Tries to infer the line separator used in a file.- Parameters:
file
- the file to infer a line separator from- Returns:
- the inferred line separator used in filename
- Throws:
IOException
- if there is trouble reading the file
-
equalFiles
Returns true iff files have the same contents.- Parameters:
file1
- first file to comparefile2
- second file to compare- Returns:
- true iff the files have the same contents
-
equalFiles
Returns true iff the files have the same contents.- Parameters:
file1
- first file to comparefile2
- second file to comparetrimLines
- if true, call String.trim on each line before comparing- Returns:
- true iff the files have the same contents
-
canCreateAndWrite
Returns true if the file exists and is writable, or if the file can be created.- Parameters:
file
- the file to create and write- Returns:
- true iff the file can be created and written
-
createTempFile
public static Path createTempFile(String prefix, String suffix, FileAttribute<?>... attrs) throws IOException Creates a new empty file in the default temporary-file directory, using the given prefix and suffix strings to generate its name. This is likeFile.createTempFile(java.lang.String, java.lang.String, java.io.File)
, but uses sequential file names.- Parameters:
prefix
- the prefix string to be used in generating the file's name; may be nullsuffix
- the suffix string to be used in generating the file's name; may be null, in which case ".tmp" is usedattrs
- an optional list of file attributes to set atomically when creating the file- Returns:
- the path to the newly created file that did not exist before this method was invoked
- Throws:
IOException
- if there is trouble creating the file
-
createTempFile
public static Path createTempFile(Path dir, String prefix, String suffix, FileAttribute<?>... attrs) throws IOException Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name. This is likeFile.createTempFile(java.lang.String, java.lang.String, java.io.File)
, but uses sequential file names.- Parameters:
dir
- the path to directory in which to create the fileprefix
- the prefix string to be used in generating the file's name; may be nullsuffix
- the suffix string to be used in generating the file's name; may be null, in which case ".tmp" is usedattrs
- an optional list of file attributes to set atomically when creating the file- Returns:
- the path to the newly created file that did not exist before this method was invoked
- Throws:
IOException
- if there is trouble creating the file
-
createTempDir
Creates an empty directory in the default temporary-file directory, using the given prefix and suffix to generate its name. For example, callingcreateTempDir("myPrefix", "mySuffix")
will create the following directory:temporaryFileDirectory/myUserName/myPrefix_
someString_suffix
. someString is internally generated to ensure no temporary files of the same name are generated.- Parameters:
prefix
- the prefix string to be used in generating the file's name; must be at least three characters longsuffix
- the suffix string to be used in generating the file's name; may be null, in which case the suffix ".tmp" will be used Returns: An abstract pathname denoting a newly-created empty file- Returns:
- a File representing the newly-created temporary directory
- Throws:
IllegalArgumentException
- If the prefix argument contains fewer than three charactersIOException
- If a file could not be createdSecurityException
- If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not allow a file to be created- See Also:
-
deleteDir
Deletes the directory at dirName and all its files. Also works on regular files.- Parameters:
dirName
- the directory to delete- Returns:
- true if and only if the file or directory is successfully deleted; false otherwise
-
deleteDir
Deletes the directory at dir and all its files. Also works on regular files.- Parameters:
dir
- the directory to delete- Returns:
- true if and only if the file or directory is successfully deleted; false otherwise
-
expandFilename
Does tilde expansion on a file name (to the user's home directory).- Parameters:
name
- file whose name to expand- Returns:
- file with expanded file
-
expandFilename
Does tilde expansion on a file name (to the user's home directory).- Parameters:
name
- filename to expand- Returns:
- expanded filename
-
javaSource
Returns a string version of the filename that can be used in Java source. On Windows, the file will return a backslash-separated string. Since backslash is an escape character, it must be quoted itself inside the string.The current implementation presumes that backslashes don't appear in filenames except as windows path separators. That seems like a reasonable assumption.
- Parameters:
name
- file whose name to quote- Returns:
- a string version of the name that can be used in Java source
-
writeObject
Writes an Object to a File.- Parameters:
o
- the object to writefile
- the file to which to write the object- Throws:
IOException
- if there is trouble writing the file
-
readObject
Reads an Object from a File. This is a wrapper aroundObjectInputStream.readObject()
, but it takes aFile
as an argument. Note that use of that method can lead to security vulnerabilities.- Parameters:
file
- the file from which to read- Returns:
- the object read from the file
- Throws:
IOException
- if there is trouble reading the fileClassNotFoundException
- if the object's class cannot be found
-
readerContents
Reads the entire contents of the reader and returns it as a string. Any IOException encountered will be turned into an Error.- Parameters:
r
- the Reader to read; this method exhausts it and closes it- Returns:
- the entire contents of the reader, as a string
-
readFile
Deprecated.Reads the entire contents of the file and returns it as a string. Any IOException encountered will be turned into an Error.You could use
new String(Files.readAllBytes(...))
, but it requires a Path rather than a File, and it can throw IOException which has to be caught.- Parameters:
file
- the file to read- Returns:
- the entire contents of the reader, as a string
-
readString
Reads the entire contents of the file and returns it as a string.The point of this method is that it does not throw any checked exception: any IOException encountered will be turned into an Error.
- Parameters:
path
- the path to the file- Returns:
- a String containing the content read from the file
-
readLinesRetainingSeparators
Read the entire contents of the file and return it as a list of lines. Each line ends with a line separator (except perhaps the last line).- Parameters:
path
- the path to the file- Returns:
- the lines of the file
-
fileContents
Deprecated.Reads the entire contents of the file and returns it as a string.The point of this method is that it does not throw any checked exception: any IOException encountered will be turned into an Error.
You could use
new String(Files.readAllBytes(...))
, but it requires a Path rather than a File, and it can throw IOException which has to be caught.- Parameters:
file
- the file to read- Returns:
- the entire contents of the reader, as a string
-
writeFile
Deprecated.Creates a file with the given name and writes the specified string to it. If the file currently exists (and is writable) it is overwritten.The point of this method is that it does not throw any checked exception: any IOException encountered will be turned into an Error.
- Parameters:
file
- the file to write tocontents
- the text to put in the file
-
writeString
Creates a file with the given name and writes the specified string to it. If the file currently exists (and is writable) it is overwritten.The point of this method is that it does not throw any checked exception: any IOException encountered will be turned into an Error.
- Parameters:
file
- the file to write tocontents
- the text to put in the file
-
writeString
Creates a file with the given name and writes the specified string to it. If the file currently exists (and is writable) it is overwritten Any IOException encountered will be turned into an Error.The point of this method is that it does not throw any checked exception: any IOException encountered will be turned into an Error.
- Parameters:
path
- the path to write tocontents
- the text to put in the file
-
streamCopy
Copy the contents of the input stream to the output stream.- Parameters:
from
- input streamto
- output stream
-
streamString
Returns a String containing all the characters from the input stream.- Parameters:
is
- input stream to read- Returns:
- a String containing all the characters from the input stream
-
streamLines
Reads all lines from the stream and returns them in aList<String>
.- Parameters:
stream
- the stream to read from- Returns:
- the list of lines read from the stream
- Throws:
IOException
- if there is an error reading from the stream
-
available
CallsInputStream.available()
, but returns null instead of throwing an IOException.- Parameters:
is
- an input stream- Returns:
is.available()
, or null if that throws an exception
-
isWhitespaceOnly
public static @Nullable Boolean isWhitespaceOnly(InputStream is, @org.checkerframework.checker.index.qual.Positive int readLimit) Returns true if the firstreadLimit
bytes of the input stream consist only of whitespace.- Parameters:
is
- an input streamreadLimit
- how many bytes to look ahead in the input stream- Returns:
- null if
!is.markSupported()
; otherwise, true if the firstreadLimit
characters of the input stream consist only of whitespace
-
readCodePoint
Reads a Unicode code point from an input stream.- Parameters:
is
- an input stream- Returns:
- the Unicode code point for the next character in the input stream
-
readString(java.nio.file.Path)