|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.siefkes.nlstego.util.InOutUtils
public final class InOutUtils
A static class that provides utility constants and methods for I/O. No instances of this class can be created, only the static members should be used.
| Field Summary | |
|---|---|
static String |
LINE_SEPARATOR
The line separator on the current operating system ("\n" on Unix). |
static int |
STANDARD_BLOCK_SIZE
The standard block size recommended for I/O. |
static String |
STANDARD_HTTP_CHARSET
The standard character set defined by the HTTP standard. |
static String |
STANDARD_UNICODE_CHARSET
The standard Unicode-compatible character set. |
| Method Summary | |
|---|---|
static byte[] |
compress(byte[] data)
Compresses data using GZip for compression. |
static FileContent[] |
listFileContents(String[] filePaths,
boolean recurse)
This method converts an array of file paths into an array of FileContent objects. |
static Reader |
openReader(FileContent content)
Opens a reader on a FileContent object. |
static byte |
readExpectedByte(InputStream in)
Reads a byte from an input stream, throwing an EOFException if the end of the stream has been
reached. |
static String |
readToString(Reader reader)
Reads the contents of a reader into a string. |
static boolean |
tryToClose(InputStream in)
Convenience method for closing an input stream. |
static boolean |
tryToClose(OutputStream out)
Convenience method for closing an output stream. |
static boolean |
tryToClose(Reader reader)
Convenience method for closing a reader. |
static boolean |
tryToClose(Writer writer)
Convenience method for closing a writer. |
static byte[] |
uncompress(byte[] compressedData)
Uncompresses data using GZip. |
static String |
userDir()
Returns the user's current working directory. |
static String |
userHome()
Returns the user's home directory. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String LINE_SEPARATOR
public static final int STANDARD_BLOCK_SIZE
public static final String STANDARD_HTTP_CHARSET
public static final String STANDARD_UNICODE_CHARSET
| Method Detail |
|---|
public static byte[] compress(byte[] data)
throws IOException
data - the data to compress
IOException - if an I/O error occurs
public static FileContent[] listFileContents(String[] filePaths,
boolean recurse)
throws IOException
FileContent objects. It uses the
Jakarta Commons Virtual
File System (VFS) which allows accessing local files, URIs, ZIP
entries and various other resources in a uniform way.
filePaths - the array of file pathsrecurse - whether to recursively add the children of folders and
other files containing nested entries
IOException - if an I/O error occurs, e.g. if one of the files
does not exist
public static Reader openReader(FileContent content)
throws FileSystemException,
UnsupportedEncodingException
FileContent object. Uses the character set
specified by FileContentInfo or the default character set of
the current platform if no explicit charset is given.
content - the content to read
FileSystemException - if an error occurs while using the
content object
UnsupportedEncodingException - if the specified charset is not
available on the current platform
public static String readToString(Reader reader)
throws IOException
This method should be slightly more efficient than
IOUtils.toString(java.io.Reader) since it
uses an unsynchronized StringBuilder instead of a synchronized
StringBuffer (hidden in a StringWriter).
reader - the reader to use
IOException - if an I/O error occurs
public static byte[] uncompress(byte[] compressedData)
throws IOException
compressedData - the data the uncompressed
IOException - if an I/O error occurs
public static byte readExpectedByte(InputStream in)
throws EOFException,
IOException
EOFException if the end of the stream has been
reached.
in - the stream to read from
EOFException - if the end of the stream has been reached
IOException - if the end of the stream has been reached or if any
other I/O error occurspublic static String userDir()
System.getProperty("user.dir").
public static String userHome()
System.getProperty("user.home").
public static boolean tryToClose(InputStream in)
null, this method does nothing. Any IOException thrown during closing is swallowed by this method.
in - the input stream to close (might be null)
true if the stream was closed successfully,
false otherwise (the stream was null or an
exception was thrown during closing)public static boolean tryToClose(OutputStream out)
null, this method does nothing. Any IOException thrown during closing is swallowed by this method.
out - the output stream to close (might be null)
true if the stream was closed successfully,
false otherwise (the stream was null or an
exception was thrown during closing)public static boolean tryToClose(Reader reader)
null, this method does nothing. Any IOException thrown during closing is swallowed by this method.
reader - the reader to close (might be null)
true if the reader was closed successfully,
false otherwise (reader was null or an
exception was thrown during closing)public static boolean tryToClose(Writer writer)
null, this method does nothing. Any IOException thrown during closing is swallowed by this method.
writer - the writer to close (might be null)
true if the writer was closed successfully,
false otherwise (writer was null or an
exception was thrown during closing)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||