|
|||||||||
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.
Field Summary | |
---|---|
static java.lang.String |
eolChar
|
Method Summary | ||
---|---|---|
static java.io.File |
backupFile(java.io.File file)
|
|
static java.lang.String |
backupName(java.lang.String filename)
|
|
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.File |
ensureDir(java.io.File tgtDir)
Given a filepath, makes sure a directory exists there. |
|
static java.io.BufferedReader |
getBufferedFileReader(java.lang.String filename)
|
|
static java.io.BufferedReader |
getBufferedFileReader(java.lang.String filename,
java.lang.String encoding)
|
|
static java.io.InputStream |
getBZip2PipedInputStream(java.lang.String filename)
|
|
static java.io.OutputStream |
getBZip2PipedOutputStream(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.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.io.File |
getJNLPLocalScratch()
A JavaNLP specific convenience routine for obtaining the current scratch directory for the machine you're currently running on. |
|
static java.io.PrintWriter |
getPrintWriter(java.io.File textFile)
|
|
static java.io.PrintWriter |
getPrintWriter(java.lang.String filename)
|
|
static java.io.PrintWriter |
getPrintWriter(java.lang.String filename,
java.lang.String encoding)
|
|
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.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 void |
main(java.lang.String[] args)
|
|
static java.io.InputStream |
openFile(java.io.File file)
Quietly opens a File. |
|
static java.util.Set<java.lang.String> |
readColumnSet(java.lang.String infile,
int field)
Read column as set |
|
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.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 java.util.Map<java.lang.String,java.lang.String> |
readMap(java.lang.String filename)
|
|
static
|
readObjectFromColumns(java.lang.Class objClass,
java.lang.String filename,
java.lang.String[] fieldNames,
java.lang.String delimiter)
|
|
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
|
readObjectFromObjectStream(java.io.ObjectInputStream ois)
|
|
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 boolean |
renameToBackupName(java.io.File file)
|
|
static java.lang.String |
slurpFile(java.io.File file)
Returns all the text in the given File. |
|
static java.lang.String |
slurpFile(java.io.File file,
java.lang.String encoding)
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.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.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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String eolChar
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 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 it
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 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 retrieved
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 retrieved
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 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 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
public static java.util.List<java.util.Map<java.lang.String,java.lang.String>> readCSVWithHeader(java.lang.String path, char quoteChar, char escapeChar) throws java.io.IOException
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)
java.io.IOException
public static java.util.List<java.util.Map<java.lang.String,java.lang.String>> readCSVWithHeader(java.lang.String path) 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 open
java.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 open
java.io.IOException
- if there are exceptions opening the filepublic static java.io.BufferedReader getBufferedFileReader(java.lang.String filename) throws java.io.IOException
java.io.IOException
public static java.io.BufferedReader getBufferedFileReader(java.lang.String filename, java.lang.String encoding) 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.lang.String filename) throws java.io.IOException
java.io.IOException
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 read
java.io.IOException
public 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) throws java.io.IOException
java.io.IOException
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.lang.String backupName(java.lang.String filename)
public static java.io.File backupFile(java.io.File file)
public static boolean renameToBackupName(java.io.File file)
public static java.io.File getJNLPLocalScratch()
public static java.io.File ensureDir(java.io.File tgtDir) throws java.lang.Exception
java.lang.Exception
public static void main(java.lang.String[] args)
public static java.lang.String getExtension(java.lang.String fileName)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |