|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.stanford.nlp.io.IOUtils
public class IOUtils
Helper Class for storing serialized objects to disk.
Method Summary | ||
---|---|---|
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 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 gzipped (if necessary) |
|
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.io.File textFile)
|
|
static java.io.InputStream |
openFile(java.io.File file)
Quietly opens a File. |
|
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, 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
|
readObjectFromFile(java.io.File file)
Read an object from a stored file. |
|
static
|
readObjectFromFile(java.lang.String filename)
Read an object from a stored file. |
|
static
|
readObjectFromFileNoExceptions(java.io.File file)
Read an object from a stored file without throwing exceptions. |
|
static java.io.BufferedReader |
readReaderFromString(java.lang.String textFileOrUrl)
|
|
static java.io.BufferedReader |
readReaderFromString(java.lang.String textFileOrUrl,
java.lang.String encoding)
Open a BufferedReader to a file or URL specified by a String name. |
|
static java.io.ObjectInputStream |
readStreamFromString(java.lang.String filenameOrUrl)
|
|
static java.lang.String |
slurpFile(java.io.File file)
Returns all the text in the given File. |
|
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. |
|
static java.lang.String |
slurpFileNoExceptions(java.lang.String filename)
Returns all the text in the given File. |
|
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 |
slurpGBFile(java.lang.String filename)
|
|
static java.lang.String |
slurpGBFileNoExceptions(java.lang.String filename)
|
|
static java.lang.String |
slurpGBURL(java.net.URL u)
Returns all the text at the given URL. |
|
static java.lang.String |
slurpGBURLNoExceptions(java.net.URL u)
Returns all the text at the given URL. |
|
static java.lang.String |
slurpGZippedFile(java.io.File file)
Returns all the text in the given File. |
|
static java.lang.String |
slurpGZippedFile(java.lang.String filename)
Returns all the text in the given File. |
|
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.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.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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
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 file
java.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 File
java.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 file
public 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 file
java.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 file
public static <T> T readObjectFromFile(java.io.File file) throws java.io.IOException, java.lang.ClassNotFoundException
file
- the file pointing to the object to be retrived
java.io.IOException
- If file cannot be read
java.lang.ClassNotFoundException
- If reading serialized object failspublic static <T> T readObjectFromFile(java.lang.String filename) throws java.io.IOException, java.lang.ClassNotFoundException
filename
- The filename of the object to be retrived
java.io.IOException
- If file cannot be read
java.lang.ClassNotFoundException
- If reading serialized object failspublic static <T> T readObjectFromFileNoExceptions(java.io.File file)
file
- the file pointing to the object to be retrived
public static int lineCount(java.io.File textFile) 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
java.io.IOException
public static java.io.InputStream getInputStreamFromURLOrClasspathOrFileSystem(java.lang.String textFileOrUrl) throws java.io.IOException
textFileOrUrl
-
java.io.IOException
public static java.io.BufferedReader readReaderFromString(java.lang.String textFileOrUrl) throws java.io.IOException
java.io.IOException
public static java.io.BufferedReader readReaderFromString(java.lang.String textFileOrUrl, java.lang.String encoding) throws java.io.IOException
textFileOrUrl
- What to read fromencoding
- CharSet encoding
java.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.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.io.InputStream openFile(java.io.File file) throws RuntimeIOException
RuntimeIOException
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 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 slurpGBFileNoExceptions(java.lang.String filename)
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)
null
.
public static java.lang.String slurpGBFile(java.lang.String filename) throws java.io.IOException
java.io.IOException
public static java.lang.String slurpFile(java.lang.String filename) throws java.io.IOException
java.io.IOException
public static java.lang.String slurpGBURL(java.net.URL u) throws java.io.IOException
java.io.IOException
public static java.lang.String slurpGBURLNoExceptions(java.net.URL u)
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 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)
null
.public static java.lang.String slurpFileNoExceptions(java.lang.String filename)
null
.public static java.lang.String slurpReader(java.io.Reader reader)
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
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |