public class IOUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
defaultEncoding |
static java.lang.String |
eolChar |
Modifier and Type | Method and Description |
---|---|
static void |
closeIgnoringExceptions(java.io.Closeable c)
Provides an implementation of closing a file for use in a finally block so
you can correctly close a file without even more exception handling stuff.
|
static void |
console(java.util.function.Consumer<java.lang.String> callback) |
static void |
console(java.lang.String prompt,
java.util.function.Consumer<java.lang.String> callback)
Start a simple console.
|
static void |
cp(java.io.File source,
java.io.File target) |
static void |
cp(java.io.File source,
java.io.File target,
boolean recursive)
An implementation of cp, as close to the Unix command as possible.
|
static boolean |
deleteDirRecursively(java.io.File dir)
Given a filepath, delete all files in the directory recursively
|
static void |
deleteRecursively(java.io.File file)
Delete this file; or, if it is a directory, delete this directory and all its contents.
|
static java.io.Reader |
encodedInputStreamReader(java.io.InputStream stream,
java.lang.String encoding)
Create a Reader with an explicit encoding around an InputStream.
|
static java.io.PrintWriter |
encodedOutputStreamPrintWriter(java.io.OutputStream stream,
java.lang.String encoding,
boolean autoFlush)
Create a Reader with an explicit encoding around an InputStream.
|
static java.io.Writer |
encodedOutputStreamWriter(java.io.OutputStream stream,
java.lang.String encoding)
Create a Reader with an explicit encoding around an InputStream.
|
static java.io.File |
ensureDir(java.io.File tgtDir)
Given a filepath, makes sure a directory exists there.
|
static boolean |
existsInClasspathOrFileSystem(java.lang.String name)
Check if this path exists either in the classpath or on the filesystem.
|
static java.io.BufferedReader |
getBufferedFileReader(java.lang.String filename)
Deprecated.
Just call readerFromString(filename)
|
static java.io.BufferedReader |
getBufferedReaderFromClasspathOrFileSystem(java.lang.String filename)
Deprecated.
Just call readerFromString(filename)
|
static java.io.InputStream |
getBZip2PipedInputStream(java.lang.String filename) |
static java.io.OutputStream |
getBZip2PipedOutputStream(java.lang.String filename) |
static java.io.DataInputStream |
getDataInputStream(java.lang.String filenameUrlOrClassPath) |
static java.io.DataOutputStream |
getDataOutputStream(java.lang.String filename) |
static java.lang.String |
getExtension(java.lang.String fileName) |
static java.io.InputStream |
getFileInputStream(java.lang.String filename)
Get a input file stream (automatically gunzip/bunzip2 depending on file extension)
|
static java.io.OutputStream |
getFileOutputStream(java.lang.String filename)
Get a output file stream (automatically gzip/bzip2 depending on file extension)
|
static java.io.OutputStream |
getFileOutputStream(java.lang.String filename,
boolean append) |
static java.io.InputStream |
getInputStreamFromURLOrClasspathOrFileSystem(java.lang.String textFileOrUrl)
Locates this file either using the given URL, or in the CLASSPATH, or in the file system
The CLASSPATH takes priority over the file system!
This stream is buffered and gunzipped (if necessary).
|
static java.io.File |
getJNLPLocalScratch()
A JavaNLP specific convenience routine for obtaining the current
scratch directory for the machine you're currently running on.
|
static java.lang.Iterable<java.lang.String> |
getLineIterable(java.io.Reader r,
boolean includeEol)
Given a reader, returns the lines from the reader as an Iterable.
|
static java.lang.Iterable<java.lang.String> |
getLineIterable(java.io.Reader r,
int bufferSize,
boolean includeEol) |
static java.io.PrintWriter |
getPrintWriter(java.io.File textFile) |
static java.io.PrintWriter |
getPrintWriter(java.io.File textFile,
java.lang.String encoding) |
static java.io.PrintWriter |
getPrintWriter(java.lang.String filename) |
static java.io.PrintWriter |
getPrintWriter(java.lang.String filename,
java.lang.String encoding) |
static java.io.PrintWriter |
getPrintWriterIgnoringExceptions(java.lang.String filename) |
static java.io.PrintWriter |
getPrintWriterOrDie(java.lang.String filename) |
static java.lang.String |
getUrlEncoding(java.net.URLConnection connection) |
static java.io.InputStream |
inputStreamFromFile(java.io.File file)
Quietly opens a File.
|
static java.lang.Iterable<java.io.File> |
iterFilesRecursive(java.io.File dir)
Iterate over all the files in the directory, recursively.
|
static java.lang.Iterable<java.io.File> |
iterFilesRecursive(java.io.File dir,
java.util.regex.Pattern pattern)
Iterate over all the files in the directory, recursively.
|
static java.lang.Iterable<java.io.File> |
iterFilesRecursive(java.io.File dir,
java.lang.String ext)
Iterate over all the files in the directory, recursively.
|
static int |
lineCount(java.lang.String textFileOrUrl) |
static java.util.List<java.lang.String> |
linesFromFile(java.lang.String filename)
Returns the contents of a file as a list of strings.
|
static java.util.List<java.lang.String> |
linesFromFile(java.lang.String filename,
java.lang.String encoding)
Returns the contents of a file as a list of strings.
|
static java.util.List<java.lang.String> |
linesFromFile(java.lang.String filename,
java.lang.String encoding,
boolean ignoreHeader) |
static java.lang.String |
promptUserInput(java.util.Optional<java.lang.String> prompt)
Create a prompt, and read a single line of response.
|
static java.util.Set<java.lang.String> |
readColumnSet(java.lang.String infile,
int field)
Read column as set
|
static java.util.LinkedList<java.lang.String[]> |
readCSVStrictly(char[] csvContents,
int numColumns)
Read a CSV file character by character.
|
static java.util.LinkedList<java.lang.String[]> |
readCSVStrictly(java.lang.String filename,
int numColumns) |
static java.util.List<java.util.Map<java.lang.String,java.lang.String>> |
readCSVWithHeader(java.lang.String path) |
static java.util.List<java.util.Map<java.lang.String,java.lang.String>> |
readCSVWithHeader(java.lang.String path,
char quoteChar,
char escapeChar)
Read in a CSV formatted file with a header row.
|
static java.io.BufferedReader |
readerFromFile(java.io.File file)
Open a BufferedReader to a File.
|
static java.io.BufferedReader |
readerFromFile(java.io.File file,
java.lang.String encoding)
Open a BufferedReader to a File.
|
static java.io.BufferedReader |
readerFromStdin()
Open a BufferedReader on stdin.
|
static java.io.BufferedReader |
readerFromStdin(java.lang.String encoding)
Open a BufferedReader on stdin.
|
static java.io.BufferedReader |
readerFromString(java.lang.String textFileOrUrl)
Open a BufferedReader to a file, class path entry or URL specified by a String name.
|
static java.io.BufferedReader |
readerFromString(java.lang.String textFileOrUrl,
java.lang.String encoding)
Open a BufferedReader to a file or URL specified by a String name.
|
static java.lang.Iterable<java.lang.String> |
readLines(java.io.File file)
Returns an Iterable of the lines in the file.
|
static java.lang.Iterable<java.lang.String> |
readLines(java.io.File file,
java.lang.Class<? extends java.io.InputStream> fileInputStreamWrapper)
Returns an Iterable of the lines in the file.
|
static java.lang.Iterable<java.lang.String> |
readLines(java.io.File file,
java.lang.Class<? extends java.io.InputStream> fileInputStreamWrapper,
java.lang.String encoding)
Returns an Iterable of the lines in the file, wrapping the generated
FileInputStream with an instance of the supplied class.
|
static java.lang.Iterable<java.lang.String> |
readLines(java.lang.String path)
Returns an Iterable of the lines in the file.
|
static java.lang.Iterable<java.lang.String> |
readLines(java.lang.String path,
java.lang.String encoding)
Returns an Iterable of the lines in the file.
|
static java.util.Map<java.lang.String,java.lang.String> |
readMap(java.lang.String filename) |
static <T> T |
readObjectAnnouncingTimingFromURLOrClasspathOrFileSystem(Redwood.RedwoodChannels log,
java.lang.String msg,
java.lang.String path) |
static <C> java.util.List<C> |
readObjectFromColumns(java.lang.Class objClass,
java.lang.String filename,
java.lang.String[] fieldNames,
java.lang.String delimiter) |
static <T> T |
readObjectFromFile(java.io.File file)
Read an object from a stored file.
|
static <T> T |
readObjectFromFile(java.lang.String filename)
Read an object from a stored file.
|
static <T> T |
readObjectFromFileNoExceptions(java.io.File file)
Read an object from a stored file without throwing exceptions.
|
static <T> T |
readObjectFromObjectStream(java.io.ObjectInputStream ois) |
static <T> T |
readObjectFromURLOrClasspathOrFileSystem(java.lang.String filename)
Read an object from a stored file.
|
static java.io.ObjectInputStream |
readStreamFromString(java.lang.String filenameOrUrl)
Returns an ObjectInputStream reading from any of a URL, a CLASSPATH resource, or a file.
|
static java.lang.String |
slurpFile(java.io.File file)
Returns all the text in the given File as a single String.
|
static java.lang.String |
slurpFile(java.io.File file,
java.lang.String encoding)
Returns all the text in the given File as a single String.
|
static java.lang.String |
slurpFile(java.lang.String filename)
Returns all the text in the given file
|
static java.lang.String |
slurpFile(java.lang.String filename,
java.lang.String encoding)
Returns all the text in the given file with the given encoding.
|
static java.lang.String |
slurpFileNoExceptions(java.io.File file)
Returns all the text in the given file with the given
encoding.
|
static java.lang.String |
slurpFileNoExceptions(java.lang.String filename)
Returns all the text in the given file with the given
encoding.
|
static java.lang.String |
slurpFileNoExceptions(java.lang.String filename,
java.lang.String encoding)
Returns all the text in the given file with the given
encoding.
|
static java.lang.String |
slurpGZippedFile(java.io.File file)
Returns all the text in the given File as a single String.
|
static java.lang.String |
slurpGZippedFile(java.lang.String filename)
Returns all the text in the given File as a single String.
|
static java.lang.String |
slurpInputStream(java.io.InputStream input,
java.lang.String encoding)
Read the contents of an input stream, decoding it according to the given character encoding.
|
static java.lang.String |
slurpReader(java.io.Reader reader)
Returns all the text from the given Reader.
|
static java.lang.String |
slurpURL(java.lang.String path)
Returns all the text at the given URL.
|
static java.lang.String |
slurpURL(java.net.URL u)
Returns all the text at the given URL.
|
static java.lang.String |
slurpURL(java.net.URL u,
java.lang.String encoding)
Returns all the text at the given URL.
|
static java.lang.String |
slurpURLNoExceptions(java.lang.String path)
Returns all the text at the given URL.
|
static java.lang.String |
slurpURLNoExceptions(java.net.URL u)
Returns all the text at the given URL.
|
static java.lang.String |
slurpURLNoExceptions(java.net.URL u,
java.lang.String encoding)
Returns all the text at the given URL.
|
static java.lang.String |
stringFromFile(java.lang.String filename)
Returns the contents of a file as a single string.
|
static java.lang.String |
stringFromFile(java.lang.String filename,
java.lang.String encoding)
Returns the contents of a file as a single string.
|
static java.lang.String[] |
tail(java.io.File f,
int n) |
static java.lang.String[] |
tail(java.io.File f,
int n,
java.lang.String encoding)
A Java implementation of the Unix tail functionality.
|
static java.lang.String |
throwableToStackTrace(java.lang.Throwable t) |
static java.io.File |
writeObjectToFile(java.lang.Object o,
java.io.File file)
Write an object to a specified File.
|
static java.io.File |
writeObjectToFile(java.lang.Object o,
java.io.File file,
boolean append)
Write an object to a specified File.
|
static java.io.File |
writeObjectToFile(java.lang.Object o,
java.lang.String filename)
Write object to a file with the specified name.
|
static java.io.File |
writeObjectToFileNoExceptions(java.lang.Object o,
java.lang.String filename)
Write object to a file with the specified name.
|
static java.io.File |
writeObjectToTempFile(java.lang.Object o,
java.lang.String filename)
Write object to temp file which is destroyed when the program exits.
|
static java.io.File |
writeObjectToTempFileNoExceptions(java.lang.Object o,
java.lang.String filename)
Write object to a temp file and ignore exceptions.
|
static java.io.ObjectOutputStream |
writeStreamFromString(java.lang.String serializePath) |
static void |
writeStreamToStream(java.io.InputStream input,
java.io.OutputStream output)
Send all bytes from the input stream to the output stream.
|
static void |
writeStringToFile(java.lang.String contents,
java.lang.String path,
java.lang.String encoding)
Writes a string to a file.
|
static void |
writeStringToFileNoExceptions(java.lang.String contents,
java.lang.String path,
java.lang.String encoding)
Writes a string to a file, squashing exceptions
|
static void |
writeStringToTempFile(java.lang.String contents,
java.lang.String path)
Writes a string to a temporary file, as UTF-8
|
static java.io.File |
writeStringToTempFile(java.lang.String contents,
java.lang.String path,
java.lang.String encoding)
Writes a string to a temporary file.
|
static void |
writeStringToTempFileNoExceptions(java.lang.String contents,
java.lang.String path)
Writes a string to a temporary file with UTF-8 encoding, squashing exceptions
|
static java.io.File |
writeStringToTempFileNoExceptions(java.lang.String contents,
java.lang.String path,
java.lang.String encoding)
Writes a string to a temporary file, squashing exceptions
|
public static final java.lang.String eolChar
public static final java.lang.String defaultEncoding
public static java.io.File writeObjectToFile(java.lang.Object o, java.lang.String filename) throws java.io.IOException
o
- Object to be written to filefilename
- Name of the temp filejava.io.IOException
- If can't write file.public static java.io.File writeObjectToFile(java.lang.Object o, java.io.File file) throws java.io.IOException
o
- Object to be written to filefile
- The temp Filejava.io.IOException
- If File cannot be writtenpublic static java.io.File writeObjectToFile(java.lang.Object o, java.io.File file, boolean append) throws java.io.IOException
o
- Object to be written to filefile
- The temp Fileappend
- If true, append to this file instead of overwriting itjava.io.IOException
- If File cannot be writtenpublic static java.io.File writeObjectToFileNoExceptions(java.lang.Object o, java.lang.String filename)
o
- Object to be written to filefilename
- Name of the temp filepublic static java.io.File writeObjectToTempFile(java.lang.Object o, java.lang.String filename) throws java.io.IOException
o
- Object to be written to filefilename
- Name of the temp filejava.io.IOException
- If file cannot be writtenpublic static java.io.File writeObjectToTempFileNoExceptions(java.lang.Object o, java.lang.String filename)
o
- Object to be written to filefilename
- Name of the temp filepublic static void writeStringToFile(java.lang.String contents, java.lang.String path, java.lang.String encoding) throws java.io.IOException
contents
- The string to writepath
- The file pathencoding
- The encoding to encode injava.io.IOException
- In case of failurepublic static void writeStringToFileNoExceptions(java.lang.String contents, java.lang.String path, java.lang.String encoding)
contents
- The string to writepath
- The file pathencoding
- The encoding to encode inpublic static java.io.File writeStringToTempFile(java.lang.String contents, java.lang.String path, java.lang.String encoding) throws java.io.IOException
contents
- The string to writepath
- The file pathencoding
- The encoding to encode injava.io.IOException
- In case of failurepublic static void writeStringToTempFile(java.lang.String contents, java.lang.String path) throws java.io.IOException
contents
- The string to writepath
- The file pathjava.io.IOException
- In case of failurepublic static java.io.File writeStringToTempFileNoExceptions(java.lang.String contents, java.lang.String path, java.lang.String encoding)
contents
- The string to writepath
- The file pathencoding
- The encoding to encode inpublic static void writeStringToTempFileNoExceptions(java.lang.String contents, java.lang.String path)
contents
- The string to writepath
- The file pathpublic static <T> T readObjectFromFile(java.io.File file) throws java.io.IOException, java.lang.ClassNotFoundException
file
- The file pointing to the object to be retrievedjava.io.IOException
- If file cannot be readjava.lang.ClassNotFoundException
- If reading serialized object failspublic static java.io.DataInputStream getDataInputStream(java.lang.String filenameUrlOrClassPath) throws java.io.IOException
java.io.IOException
public static java.io.DataOutputStream getDataOutputStream(java.lang.String filename) throws java.io.IOException
java.io.IOException
public static <T> T readObjectFromURLOrClasspathOrFileSystem(java.lang.String filename) throws java.io.IOException, java.lang.ClassNotFoundException
filename
- The file pointing to the object to be retrievedjava.io.IOException
- If file cannot be readjava.lang.ClassNotFoundException
- If reading serialized object failspublic static <T> T readObjectAnnouncingTimingFromURLOrClasspathOrFileSystem(Redwood.RedwoodChannels log, java.lang.String msg, java.lang.String path)
public static <T> T readObjectFromObjectStream(java.io.ObjectInputStream ois) throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException
public static <T> T readObjectFromFile(java.lang.String filename) throws java.io.IOException, java.lang.ClassNotFoundException
filename
- The filename of the object to be retrievedjava.io.IOException
- If file cannot be readjava.lang.ClassNotFoundException
- If reading serialized object failspublic static <T> T readObjectFromFileNoExceptions(java.io.File file)
file
- The file pointing to the object to be retrievedpublic static int lineCount(java.lang.String textFileOrUrl) throws java.io.IOException
java.io.IOException
public static java.io.ObjectOutputStream writeStreamFromString(java.lang.String serializePath) throws java.io.IOException
java.io.IOException
public static java.io.ObjectInputStream readStreamFromString(java.lang.String filenameOrUrl) throws java.io.IOException
filenameOrUrl
- The String specifying the URL/resource/file to loadRuntimeIOException
- On any IO errorjava.lang.NullPointerException
- Input parameter is nulljava.io.IOException
public static boolean existsInClasspathOrFileSystem(java.lang.String name)
name
- The file or resource name.getBufferedReaderFromClasspathOrFileSystem(String)
would return a valid stream.public static java.io.InputStream getInputStreamFromURLOrClasspathOrFileSystem(java.lang.String textFileOrUrl) throws java.io.IOException, java.lang.NullPointerException
textFileOrUrl
- The String specifying the URL/resource/file to loadjava.io.IOException
- On any IO errorjava.lang.NullPointerException
- Input parameter is nullpublic static java.io.InputStream inputStreamFromFile(java.io.File file) throws RuntimeIOException
RuntimeIOException
public static java.io.BufferedReader readerFromFile(java.io.File file)
file
- What to read fromRuntimeIOException
- If there is an I/O problempublic static java.io.BufferedReader readerFromFile(java.io.File file, java.lang.String encoding)
file
- What to read fromencoding
- What charset to use. A null String is interpreted as platform default encodingRuntimeIOException
- If there is an I/O problempublic static java.io.BufferedReader readerFromStdin()
public static java.io.BufferedReader readerFromStdin(java.lang.String encoding) throws java.io.IOException
encoding
- CharSet encoding. Maybe be null, in which case the
platform default encoding is usedjava.io.IOException
- If there is an I/O problempublic static java.io.BufferedReader readerFromString(java.lang.String textFileOrUrl) throws java.io.IOException
textFileOrUrl
- What to read fromjava.io.IOException
- If there is an I/O problempublic static java.io.BufferedReader readerFromString(java.lang.String textFileOrUrl, java.lang.String encoding) throws java.io.IOException
textFileOrUrl
- What to read fromencoding
- CharSet encoding. Maybe be null, in which case the
platform default encoding is usedjava.io.IOException
- If there is an I/O problempublic static java.lang.Iterable<java.lang.String> readLines(java.lang.String path)
path
- The file whose lines are to be read.public static java.lang.Iterable<java.lang.String> readLines(java.lang.String path, java.lang.String encoding)
path
- The file whose lines are to be read.encoding
- The encoding to use when reading lines.public static java.lang.Iterable<java.lang.String> readLines(java.io.File file)
file
- The file whose lines are to be read.public static java.lang.Iterable<java.lang.String> readLines(java.io.File file, java.lang.Class<? extends java.io.InputStream> fileInputStreamWrapper)
file
- The file whose lines are to be read.fileInputStreamWrapper
- The class to wrap the InputStream with, e.g. GZIPInputStream. Note
that the class must have a constructor that accepts an
InputStream.public static java.lang.Iterable<java.lang.String> readLines(java.io.File file, java.lang.Class<? extends java.io.InputStream> fileInputStreamWrapper, java.lang.String encoding)
file
- The file whose lines are to be read.fileInputStreamWrapper
- The class to wrap the InputStream with, e.g. GZIPInputStream. Note
that the class must have a constructor that accepts an
InputStream.encoding
- The encoding to use when reading lines.public static java.lang.Iterable<java.lang.String> getLineIterable(java.io.Reader r, boolean includeEol)
r
- input readerincludeEol
- whether to keep eol-characters in the returned stringspublic static java.lang.Iterable<java.lang.String> getLineIterable(java.io.Reader r, int bufferSize, boolean includeEol)
public static void closeIgnoringExceptions(java.io.Closeable c)
c
- The IO resource to close (e.g., a Stream/Reader)public static java.lang.Iterable<java.io.File> iterFilesRecursive(java.io.File dir)
dir
- The root directory.public static java.lang.Iterable<java.io.File> iterFilesRecursive(java.io.File dir, java.lang.String ext)
dir
- The root directory.ext
- A string that must be at the end of all files (e.g. ".txt")public static java.lang.Iterable<java.io.File> iterFilesRecursive(java.io.File dir, java.util.regex.Pattern pattern)
dir
- The root directory.pattern
- A regular expression that the file path must match. This uses
Matcher.find(), so use ^ and $ to specify endpoints.public static java.lang.String slurpFile(java.io.File file) throws java.io.IOException
java.io.IOException
public static java.lang.String slurpFile(java.io.File file, java.lang.String encoding) throws java.io.IOException
file
- The file to read fromencoding
- The character encoding to assume. This may be null, and
the platform default character encoding is used.java.io.IOException
public static java.lang.String slurpGZippedFile(java.lang.String filename) throws java.io.IOException
java.io.IOException
public static java.lang.String slurpGZippedFile(java.io.File file) throws java.io.IOException
java.io.IOException
public static java.lang.String slurpFile(java.lang.String filename, java.lang.String encoding) throws java.io.IOException
java.io.IOException
public static java.lang.String slurpFileNoExceptions(java.lang.String filename, java.lang.String encoding)
public static java.lang.String slurpFile(java.lang.String filename) throws java.io.IOException
java.io.IOException
public static java.lang.String slurpURLNoExceptions(java.net.URL u, java.lang.String encoding)
public static java.lang.String slurpURL(java.net.URL u, java.lang.String encoding) throws java.io.IOException
java.io.IOException
public static java.lang.String getUrlEncoding(java.net.URLConnection connection)
public static java.lang.String slurpURL(java.net.URL u) throws java.io.IOException
java.io.IOException
public static java.lang.String slurpURLNoExceptions(java.net.URL u)
public static java.lang.String slurpURL(java.lang.String path) throws java.lang.Exception
java.lang.Exception
public static java.lang.String slurpURLNoExceptions(java.lang.String path)
null
.public static java.lang.String slurpFileNoExceptions(java.io.File file)
public static java.lang.String slurpFileNoExceptions(java.lang.String filename)
public static java.lang.String slurpReader(java.io.Reader reader)
public static java.lang.String slurpInputStream(java.io.InputStream input, java.lang.String encoding) throws java.io.IOException
input
- The input stream to read fromjava.io.IOException
public static void writeStreamToStream(java.io.InputStream input, java.io.OutputStream output) throws java.io.IOException
input
- The input bytes.output
- Where the bytes should be written.java.io.IOException
public static java.util.List<java.util.Map<java.lang.String,java.lang.String>> readCSVWithHeader(java.lang.String path, char quoteChar, char escapeChar)
path
- - path to CSV filequoteChar
- - character for enclosing strings, defaults to "escapeChar
- - character for escaping quotes appearing in quoted strings; defaults to " (i.e. "" is used for " inside quotes, consistent with Excel)public static java.util.List<java.util.Map<java.lang.String,java.lang.String>> readCSVWithHeader(java.lang.String path)
public static java.util.LinkedList<java.lang.String[]> readCSVStrictly(char[] csvContents, int numColumns)
csvContents
- The char[] array corresponding to the contents of the filenumColumns
- The number of columns in the file (for verification, primarily)public static java.util.LinkedList<java.lang.String[]> readCSVStrictly(java.lang.String filename, int numColumns) throws java.io.IOException
java.io.IOException
public static java.io.InputStream getFileInputStream(java.lang.String filename) throws java.io.IOException
filename
- Name of file to openjava.io.IOException
- if there are exceptions opening the filepublic static java.io.OutputStream getFileOutputStream(java.lang.String filename) throws java.io.IOException
filename
- Name of file to openjava.io.IOException
- if there are exceptions opening the filepublic static java.io.OutputStream getFileOutputStream(java.lang.String filename, boolean append) throws java.io.IOException
java.io.IOException
@Deprecated public static java.io.BufferedReader getBufferedFileReader(java.lang.String filename) throws java.io.IOException
java.io.IOException
@Deprecated public static java.io.BufferedReader getBufferedReaderFromClasspathOrFileSystem(java.lang.String filename) throws java.io.IOException
java.io.IOException
public static java.io.PrintWriter getPrintWriter(java.io.File textFile) throws java.io.IOException
java.io.IOException
public static java.io.PrintWriter getPrintWriter(java.io.File textFile, java.lang.String encoding) throws java.io.IOException
java.io.IOException
public static java.io.PrintWriter getPrintWriter(java.lang.String filename) throws java.io.IOException
java.io.IOException
public static java.io.PrintWriter getPrintWriterIgnoringExceptions(java.lang.String filename)
public static java.io.PrintWriter getPrintWriterOrDie(java.lang.String filename)
public static java.io.PrintWriter getPrintWriter(java.lang.String filename, java.lang.String encoding) throws java.io.IOException
java.io.IOException
public static java.io.InputStream getBZip2PipedInputStream(java.lang.String filename) throws java.io.IOException
java.io.IOException
public static java.io.OutputStream getBZip2PipedOutputStream(java.lang.String filename) throws java.io.IOException
java.io.IOException
public static java.util.Set<java.lang.String> readColumnSet(java.lang.String infile, int field) throws java.io.IOException
infile
- filenamefield
- index of field to readjava.io.IOException
- If I/O errorpublic static <C> java.util.List<C> readObjectFromColumns(java.lang.Class objClass, java.lang.String filename, java.lang.String[] fieldNames, java.lang.String delimiter) throws java.io.IOException, java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.NoSuchFieldException, java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException
java.io.IOException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.NoSuchFieldException
java.lang.NoSuchMethodException
java.lang.reflect.InvocationTargetException
public static java.util.Map<java.lang.String,java.lang.String> readMap(java.lang.String filename)
public static java.lang.String stringFromFile(java.lang.String filename)
public static java.lang.String stringFromFile(java.lang.String filename, java.lang.String encoding)
public static java.util.List<java.lang.String> linesFromFile(java.lang.String filename)
public static java.util.List<java.lang.String> linesFromFile(java.lang.String filename, java.lang.String encoding)
public static java.util.List<java.lang.String> linesFromFile(java.lang.String filename, java.lang.String encoding, boolean ignoreHeader)
public static java.io.File getJNLPLocalScratch()
public static java.io.File ensureDir(java.io.File tgtDir) throws java.io.IOException
tgtDir
- The directory that you wish to ensure existsjava.io.IOException
- If directory can't be created, is an existing file, or for other reasonspublic static boolean deleteDirRecursively(java.io.File dir)
dir
- Directory from which to delete filestrue
if the deletion is successful, false
otherwisepublic static java.lang.String getExtension(java.lang.String fileName)
public static java.io.Reader encodedInputStreamReader(java.io.InputStream stream, java.lang.String encoding) throws java.io.IOException
stream
- An InputStreamencoding
- A charset encodingjava.io.IOException
- If any IO problempublic static java.io.Writer encodedOutputStreamWriter(java.io.OutputStream stream, java.lang.String encoding) throws java.io.IOException
stream
- An InputStreamencoding
- A charset encodingjava.io.IOException
- If any IO problempublic static java.io.PrintWriter encodedOutputStreamPrintWriter(java.io.OutputStream stream, java.lang.String encoding, boolean autoFlush) throws java.io.IOException
stream
- An InputStreamencoding
- A charset encodingautoFlush
- Whether to make an autoflushing Writerjava.io.IOException
- If any IO problempublic static void cp(java.io.File source, java.io.File target, boolean recursive) throws java.io.IOException
An implementation of cp, as close to the Unix command as possible. Both directories and files are valid for either the source or the target; if the target exists, the semantics of Unix cp are [intended to be] obeyed.
source
- The source file or directory.target
- The target to write this file or directory to.recursive
- If true, recursively copy directory contentsjava.io.IOException
- If either the copy fails (standard IO Exception), or the command is invalid
(e.g., copying a directory without the recursive flag)public static void cp(java.io.File source, java.io.File target) throws java.io.IOException
java.io.IOException
cp(java.io.File, java.io.File, boolean)
public static java.lang.String[] tail(java.io.File f, int n, java.lang.String encoding) throws java.io.IOException
f
- The file to read the last n lines fromn
- The number of lines to read from the end of the file.encoding
- The encoding to read the file in.java.io.IOException
- if the file could not be read.public static java.lang.String[] tail(java.io.File f, int n) throws java.io.IOException
java.io.IOException
tail(java.io.File, int, String)
public static void deleteRecursively(java.io.File file)
file
- The file or directory to delete.public static void console(java.lang.String prompt, java.util.function.Consumer<java.lang.String> callback) throws java.io.IOException
callback
- The function to run for every line of input.java.io.IOException
- Thrown from the underlying input stream.public static java.lang.String promptUserInput(java.util.Optional<java.lang.String> prompt) throws java.io.IOException
prompt
- An optional prompt to show the user.java.io.IOException
- Throw from the underlying reader.public static void console(java.util.function.Consumer<java.lang.String> callback) throws java.io.IOException
java.io.IOException
console(String, Consumer)
public static java.lang.String throwableToStackTrace(java.lang.Throwable t)