Package org.cryptacular.util
Class StreamUtil
java.lang.Object
org.cryptacular.util.StreamUtil
Utility methods for stream handling.
- Author:
- Middleware Services
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Buffer size of chunked operations, e.g. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
closeReader
(Reader reader) Closes the given reader and swallows exceptions that may arise during the process.static void
Closes the given stream and swallows exceptions that may arise during the process.static void
closeStream
(OutputStream out) Closes the given stream and swallows exceptions that may arise during the process.static void
closeWriter
(Writer writer) Closes the given writer and swallows exceptions that may arise during the process.static Reader
makeReader
(File file) Creates a reader around the given file that presumably contains character data.static InputStream
makeStream
(File file) Creates an input stream around the given file.static void
pipeAll
(InputStream in, OutputStream out, ChunkHandler handler) Pipes an input stream into an output stream with chunked processing.static byte[]
Reads all the data from the given file.static byte[]
readAll
(InputStream input) Reads all the data from the given input stream.static byte[]
readAll
(InputStream input, int sizeHint) Reads all the data from the given input stream.static String
Reads all data from the given reader.static String
Reads all data from the given reader.static byte[]
Reads all the data from the file at the given path.
-
Field Details
-
CHUNK_SIZE
public static final int CHUNK_SIZEBuffer size of chunked operations, e.g.pipeAll(java.io.InputStream, java.io.OutputStream, org.cryptacular.io.ChunkHandler)
.- See Also:
-
-
Method Details
-
readAll
Reads all the data from the file at the given path.- Parameters:
path
- Path to file.- Returns:
- Byte array of data read from file.
- Throws:
StreamException
- on stream IO errors.
-
readAll
Reads all the data from the given file.- Parameters:
file
- File to read.- Returns:
- Byte array of data read from file.
- Throws:
StreamException
- on stream IO errors.
-
readAll
Reads all the data from the given input stream.- Parameters:
input
- Input stream to read.- Returns:
- Byte array of data read from stream.
- Throws:
StreamException
- on stream IO errors.
-
readAll
Reads all the data from the given input stream.- Parameters:
input
- Input stream to read.sizeHint
- Estimate of amount of data to be read in bytes.- Returns:
- Byte array of data read from stream.
- Throws:
StreamException
- on stream IO errors.
-
readAll
Reads all data from the given reader.- Parameters:
reader
- Reader over character data.- Returns:
- Data read from reader.
- Throws:
StreamException
- on stream IO errors.
-
readAll
Reads all data from the given reader.- Parameters:
reader
- Reader over character data.sizeHint
- Estimate of amount of data to be read in number of characters.- Returns:
- Data read from reader.
- Throws:
StreamException
- on stream IO errors.
-
pipeAll
public static void pipeAll(InputStream in, OutputStream out, ChunkHandler handler) throws StreamException Pipes an input stream into an output stream with chunked processing.- Parameters:
in
- Input stream providing data to process.out
- Output stream holding processed data.handler
- Arbitrary handler for processing input stream.- Throws:
StreamException
- on stream IO errors.
-
makeStream
Creates an input stream around the given file.- Parameters:
file
- Input stream source.- Returns:
- Input stream around file.
- Throws:
StreamException
- on stream IO errors.
-
makeReader
Creates a reader around the given file that presumably contains character data.- Parameters:
file
- Reader source.- Returns:
- Reader around file.
- Throws:
StreamException
- on stream IO errors.
-
closeStream
Closes the given stream and swallows exceptions that may arise during the process.- Parameters:
in
- Input stream to close.
-
closeStream
Closes the given stream and swallows exceptions that may arise during the process.- Parameters:
out
- Output stream to close.
-
closeReader
Closes the given reader and swallows exceptions that may arise during the process.- Parameters:
reader
- Reader to close.
-
closeWriter
Closes the given writer and swallows exceptions that may arise during the process.- Parameters:
writer
- Writer to close.
-