|
|||||||||
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(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 Iterable<File> |
iterFilesRecursive(File dir)
Iterate over all the files in the directory, recursively. |
|
static Iterable<File> |
iterFilesRecursive(File dir,
Pattern pattern)
Iterate over all the files in the directory, recursively. |
|
static Iterable<File> |
iterFilesRecursive(File dir,
String ext)
Iterate over all the files in the directory, recursively. |
|
static int |
lineCount(File textFile)
|
|
static InputStream |
openFile(File file)
Quietly opens a File. |
|
static Iterable<String> |
readLines(File file)
Returns an Iterable of the lines in the file. |
|
static Iterable<String> |
readLines(File file,
Class<? extends InputStream> fileInputStreamWrapper)
Returns an Iterable of the lines in the file, wrapping the generated FileInputStream with an instance of the supplied class. |
|
static Iterable<String> |
readLines(String path)
Returns an Iterable of the lines in the file. |
|
static
|
readObjectFromFile(File file)
Read an object from a stored file. |
|
static
|
readObjectFromFile(String filename)
Read an object from a stored file. |
|
static
|
readObjectFromFileNoExceptions(File file)
Read an object from a stored file without throwing exceptions. |
|
static BufferedReader |
readReaderFromString(String textFileOrUrl)
|
|
static BufferedReader |
readReaderFromString(String textFileOrUrl,
String encoding)
Open a BufferedReader to a file or URL specified by a String name. |
|
static ObjectInputStream |
readStreamFromString(String filenameOrUrl)
|
|
static String |
slurpFile(File file)
Returns all the text in the given File. |
|
static String |
slurpFile(String filename)
Returns all the text in the given file |
|
static String |
slurpFile(String filename,
String encoding)
Returns all the text in the given file with the given encoding. |
|
static String |
slurpFileNoExceptions(File file)
Returns all the text in the given File. |
|
static String |
slurpFileNoExceptions(String filename)
Returns all the text in the given File. |
|
static String |
slurpFileNoExceptions(String filename,
String encoding)
Returns all the text in the given file with the given encoding. |
|
static String |
slurpGBFile(String filename)
|
|
static String |
slurpGBFileNoExceptions(String filename)
|
|
static String |
slurpGBURL(URL u)
Returns all the text at the given URL. |
|
static String |
slurpGBURLNoExceptions(URL u)
Returns all the text at the given URL. |
|
static String |
slurpGZippedFile(File file)
Returns all the text in the given File. |
|
static String |
slurpGZippedFile(String filename)
Returns all the text in the given File. |
|
static String |
slurpReader(Reader reader)
Returns all the text from the given Reader. |
|
static String |
slurpURL(String path)
Returns all the text at the given URL. |
|
static String |
slurpURL(URL u)
Returns all the text at the given URL. |
|
static String |
slurpURL(URL u,
String encoding)
Returns all the text at the given URL. |
|
static String |
slurpURLNoExceptions(String path)
Returns all the text at the given URL. |
|
static String |
slurpURLNoExceptions(URL u)
Returns all the text at the given URL. |
|
static String |
slurpURLNoExceptions(URL u,
String encoding)
Returns all the text at the given URL. |
|
static File |
writeObjectToFile(Object o,
File file)
Write an object to a specified File. |
|
static File |
writeObjectToFile(Object o,
String filename)
Write object to a file with the specified name. |
|
static File |
writeObjectToFileNoExceptions(Object o,
String filename)
Write object to a file with the specified name. |
|
static File |
writeObjectToTempFile(Object o,
String filename)
Write object to temp file which is destroyed when the program exits. |
|
static File |
writeObjectToTempFileNoExceptions(Object o,
String filename)
Write object to a temp file and ignore exceptions. |
|
static ObjectOutputStream |
writeStreamFromString(String serializePath)
|
|
static void |
writeStreamToStream(InputStream input,
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 File writeObjectToFile(Object o, String filename) throws IOException
o
- object to be written to filefilename
- name of the temp file
IOException
- If can't write file.public static File writeObjectToFile(Object o, File file) throws IOException
o
- object to be written to filefile
- The temp File
IOException
- If File cannot be writtenpublic static File writeObjectToFileNoExceptions(Object o, String filename)
o
- object to be written to filefilename
- name of the temp file
public static File writeObjectToTempFile(Object o, String filename) throws IOException
o
- object to be written to filefilename
- name of the temp file
IOException
- If file cannot be writtenpublic static File writeObjectToTempFileNoExceptions(Object o, String filename)
o
- object to be written to filefilename
- name of the temp file
public static <T> T readObjectFromFile(File file) throws IOException, ClassNotFoundException
file
- the file pointing to the object to be retrived
IOException
- If file cannot be read
ClassNotFoundException
- If reading serialized object failspublic static <T> T readObjectFromFile(String filename) throws IOException, ClassNotFoundException
filename
- The filename of the object to be retrived
IOException
- If file cannot be read
ClassNotFoundException
- If reading serialized object failspublic static <T> T readObjectFromFileNoExceptions(File file)
file
- the file pointing to the object to be retrived
public static int lineCount(File textFile) throws IOException
IOException
public static ObjectOutputStream writeStreamFromString(String serializePath) throws IOException
IOException
public static ObjectInputStream readStreamFromString(String filenameOrUrl) throws IOException
IOException
public static BufferedReader readReaderFromString(String textFileOrUrl) throws IOException
IOException
public static BufferedReader readReaderFromString(String textFileOrUrl, String encoding) throws IOException
textFileOrUrl
- What to read fromencoding
- CharSet encoding
IOException
- If there is an I/O problempublic static Iterable<String> readLines(String path)
path
- The file whose lines are to be read.
public static Iterable<String> readLines(File file)
file
- The file whose lines are to be read.
public static Iterable<String> readLines(File file, Class<? extends 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 InputStream openFile(File file) throws RuntimeIOException
RuntimeIOException
public static void closeIgnoringExceptions(Closeable c)
c
- The IO resource to close (e.g., a Stream/Reader)public static Iterable<File> iterFilesRecursive(File dir)
dir
- The root directory.
public static Iterable<File> iterFilesRecursive(File dir, String ext)
dir
- The root directory.ext
- A string that must be at the end of all files (e.g. ".txt")
public static Iterable<File> iterFilesRecursive(File dir, 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 String slurpFile(File file) throws IOException
IOException
public static String slurpGZippedFile(String filename) throws IOException
IOException
public static String slurpGZippedFile(File file) throws IOException
IOException
public static String slurpGBFileNoExceptions(String filename)
public static String slurpFile(String filename, String encoding) throws IOException
IOException
public static String slurpFileNoExceptions(String filename, String encoding)
null
.
public static String slurpGBFile(String filename) throws IOException
IOException
public static String slurpFile(String filename) throws IOException
IOException
public static String slurpGBURL(URL u) throws IOException
IOException
public static String slurpGBURLNoExceptions(URL u)
public static String slurpURLNoExceptions(URL u, String encoding)
public static String slurpURL(URL u, String encoding) throws IOException
IOException
public static String slurpURL(URL u) throws IOException
IOException
public static String slurpURLNoExceptions(URL u)
public static String slurpURL(String path) throws Exception
Exception
public static String slurpURLNoExceptions(String path)
null
.
public static String slurpFileNoExceptions(File file)
null
.public static String slurpFileNoExceptions(String filename)
null
.public static String slurpReader(Reader reader)
public static void writeStreamToStream(InputStream input, OutputStream output) throws IOException
input
- The input bytes.output
- Where the bytes should be written.
IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |