|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--iglu.util.IOTools
This class provides some helper procedures to make IO a bit simpler.
Field Summary | |
static java.lang.String |
GENERIC_WORD_DELIMITERS
|
private static java.io.BufferedReader |
standardInput
|
static java.lang.String |
WHITE_SPACE_CHARACTERS
|
Constructor Summary | |
private |
IOTools()
Prevent instantiation. |
Method Summary | |
static java.lang.String |
changeExtension(java.lang.String filename,
java.lang.String extension)
Changes the extension of a filename. |
static boolean |
fileExists(java.lang.String name)
Check to see if the specified file exists |
static java.io.BufferedReader |
getFileReader(java.io.File theFile)
Returns a BufferedReader that can read the
contents of a File. |
static java.io.BufferedReader |
getFileReader(java.lang.String filename)
Returns a BufferedReader that can read the
contents of the file filename . |
static java.io.PrintWriter |
getFileWriter(java.io.File theFile)
Returns a PrintWriter that can write to the given
file. |
static java.io.PrintWriter |
getFileWriter(java.lang.String filename)
Returns a PrintWriter that can write to the given
file. |
static java.io.File |
getIndependentFile(java.lang.String filename)
Creates a File that will work on any operating system, assuming the directory structures are the same. |
static java.io.BufferedReader |
getProcessReader(java.lang.String command)
Returns a BufferedReader that can read the
results of running the process command . |
static java.io.BufferedReader |
getURLReader(java.lang.String url)
Returns a BufferedReader that contains the contents
of a URL. |
static java.io.BufferedReader |
getWashingFileReader(java.io.File theFile)
Returns a BufferedReader that can read the sanitized
contents of the File. |
static java.io.BufferedReader |
getWashingFileReader(java.lang.String filename)
Returns a BufferedReader that can read the sanitized
contents of the file filename . |
static void |
main(java.lang.String[] args)
Runs some test examples on the methods of this class. |
static java.lang.Object |
objectFromBytes(byte[] bytes)
|
static java.io.Serializable |
objectFromFile(java.lang.String filename)
A convienence class which reads serializable object from the disk. |
static byte[] |
objectToBytes(java.io.Serializable o)
|
static boolean |
objectToFile(java.io.Serializable o,
java.lang.String filename)
A convienence class which writes serializable objects out to disk. |
static java.lang.String |
readLine()
Reads a line of text from stdin and returns it as a string. |
static java.lang.String |
readLines(java.io.BufferedReader rdr,
int numLines)
Reads numLines lines from the reader, concatenates
them into a String, and returns the String. |
static java.lang.Object |
retrieveObject(java.io.File theFile)
Retrieves an object from the specified file. |
static void |
saveObject(java.lang.Object item,
java.io.File theFile)
Saves a single object to the specified file. |
static java.lang.String |
slurp(java.io.BufferedReader rdr)
Reads the entire contents of a reader and returns them as a String. |
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 GENERIC_WORD_DELIMITERS
public static final java.lang.String WHITE_SPACE_CHARACTERS
private static java.io.BufferedReader standardInput
Constructor Detail |
private IOTools()
Method Detail |
public static java.lang.String readLine()
public static java.lang.String readLines(java.io.BufferedReader rdr, int numLines)
numLines
lines from the reader, concatenates
them into a String, and returns the String. If the reader
doesn't contain enough lines, all lines that exist are returned.
public static java.lang.String slurp(java.io.BufferedReader rdr)
public static java.io.File getIndependentFile(java.lang.String filename)
If the first character of the string is a forward slash or tilde, or the second character is a colon, then the string is assumed to be an absolute filename, and the file is created directly from the string. Otherwise, the user's home directory is used as a base, and the file is created relative to this base.
public static java.io.PrintWriter getFileWriter(java.lang.String filename)
PrintWriter
that can write to the given
file.
public static java.io.PrintWriter getFileWriter(java.io.File theFile)
PrintWriter
that can write to the given
file.
public static java.io.BufferedReader getFileReader(java.lang.String filename) throws java.io.FileNotFoundException
BufferedReader
that can read the
contents of the file filename
.
java.io.FileNotFoundException
public static java.io.BufferedReader getFileReader(java.io.File theFile) throws java.io.FileNotFoundException
BufferedReader
that can read the
contents of a File.
java.io.FileNotFoundException
public static java.io.BufferedReader getWashingFileReader(java.lang.String filename) throws java.io.FileNotFoundException
BufferedReader
that can read the sanitized
contents of the file filename
. For sanitizing,
contents are passed through the WashingFilter, which throws away
non-ASCII characters.
java.io.FileNotFoundException
public static java.io.BufferedReader getWashingFileReader(java.io.File theFile) throws java.io.FileNotFoundException
BufferedReader
that can read the sanitized
contents of the File. For sanitizing,
contents are passed through the WashingFilter, which throws away
non-ASCII characters.
java.io.FileNotFoundException
public static java.io.BufferedReader getProcessReader(java.lang.String command) throws java.io.IOException
BufferedReader
that can read the
results of running the process command
.
java.io.IOException
public static java.io.BufferedReader getURLReader(java.lang.String url) throws java.io.IOException
BufferedReader
that contains the contents
of a URL.
java.io.IOException
public static void saveObject(java.lang.Object item, java.io.File theFile) throws java.io.IOException
Serializable
. If the file exists, it is overwritten.
If it doesn't exist, it is created.
java.io.IOException
public static java.lang.Object retrieveObject(java.io.File theFile) throws java.io.IOException
Serializable
. Assumes that there is only one object
(or object graph) in the file.
null
if it is not.
java.io.IOException
public static java.lang.String changeExtension(java.lang.String filename, java.lang.String extension)
public static byte[] objectToBytes(java.io.Serializable o)
public static java.lang.Object objectFromBytes(byte[] bytes)
public static boolean objectToFile(java.io.Serializable o, java.lang.String filename)
public static boolean fileExists(java.lang.String name)
public static java.io.Serializable objectFromFile(java.lang.String filename)
objectToFile
public static void main(java.lang.String[] args) throws java.io.IOException
java.io.IOException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |