public class StreamUtilImpl extends AbstractLoggableComponent implements StreamUtil
StreamUtil interface.getInstance()| Modifier and Type | Class and Description |
|---|---|
protected static class |
StreamUtilImpl.AbstractAsyncTransferrer
This is the abstract base class for the
Callable that transfers data of streams or
readers/writers. |
protected static class |
StreamUtilImpl.AsyncTransferrerImpl
This is the default implementation of the
AsyncTransferrer interface. |
protected class |
StreamUtilImpl.BaseTransferrer<BUFFER>
This is an abstract implementation of the
AsyncTransferrer interface, that implements
Runnable defining the main flow. |
protected class |
StreamUtilImpl.ReaderTransferrer
|
protected class |
StreamUtilImpl.StreamTransferrer
This inner class is used to transfer an
InputStream to an OutputStream. |
| Modifier and Type | Field and Description |
|---|---|
private Pool<byte[]> |
byteArrayPool |
private Pool<char[]> |
charArrayPool |
private Executor |
executor |
private static StreamUtil |
instance |
| Constructor and Description |
|---|
StreamUtilImpl()
The constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close(Channel channel)
This method closes the given
channel without throwing an Exception. |
void |
close(InputStream inputStream)
This method closes the given
inputStream without throwing an Exception. |
void |
close(OutputStream outputStream)
This method closes the given
outputStream without throwing an IOException. |
void |
close(Reader reader)
This method closes the given
reader without throwing an Exception. |
void |
close(Writer writer)
This method closes the given
writer without throwing an IOException. |
protected void |
doInitialize()
This method performs the actual
initialization. |
protected Pool<byte[]> |
getByteArrayPool()
This method gets the byte-array
Pool used to transfer streams. |
protected Pool<char[]> |
getCharArrayPool()
|
protected Executor |
getExecutor()
This method gets the
Executor used to run asynchronous tasks. |
static StreamUtil |
getInstance()
This method gets the singleton instance of this
StreamUtilImpl. |
Properties |
loadProperties(InputStream inStream)
|
Properties |
loadProperties(Reader reader)
|
String |
read(Reader reader)
This method reads the contents of the given
reader into a string. |
void |
setByteArrayPool(Pool<byte[]> byteArrayPool)
This method sets the
byte-array-pool. |
void |
setCharArrayPool(Pool<char[]> charArrayPool)
This method sets the
char-array-pool. |
void |
setExecutor(Executor executor)
This method sets the
executor. |
PrintWriter |
toPrintWriter(Appendable appendable)
This method converts the given
Appendable to a PrintWriter. |
Writer |
toWriter(Appendable appendable)
This method converts the given
Appendable to a Writer. |
long |
transfer(FileInputStream inStream,
OutputStream outStream,
boolean keepOutStreamOpen)
|
long |
transfer(InputStream inStream,
FileOutputStream outStream,
boolean keepOutStreamOpen,
long size)
|
long |
transfer(InputStream inStream,
OutputStream outStream,
boolean keepOutStreamOpen)
This method transfers the contents of the given
inStream to the given outStream . |
long |
transfer(Reader reader,
Writer writer,
boolean keepWriterOpen)
This method transfers the contents of the given
reader to the given writer. |
AsyncTransferrer |
transferAsync(InputStream inStream,
OutputStream outStream,
boolean keepOutStreamOpen)
This method transfers the contents of the given
inStream to the given outStream . |
AsyncTransferrer |
transferAsync(InputStream inStream,
OutputStream outStream,
boolean keepOutStreamOpen,
TransferCallback callback)
This method transfers the contents of the given
inStream to the given outStream . |
AsyncTransferrer |
transferAsync(Reader reader,
Writer writer,
boolean keepWriterOpen)
This method transfers the contents of the given
reader to the given writer. |
AsyncTransferrer |
transferAsync(Reader reader,
Writer writer,
boolean keepWriterOpen,
TransferCallback callback)
This method transfers the contents of the given
reader to the given writer. |
createLogger, getLoggerdoInitialized, getInitializationState, initializeprivate static StreamUtil instance
private Executor executor
private Pool<byte[]> byteArrayPool
private Pool<char[]> charArrayPool
public static StreamUtil getInstance()
StreamUtilImpl. Cdi.GET_INSTANCE before using.protected Executor getExecutor()
Executor used to run asynchronous tasks. It may use a thread-pool.@Inject public void setExecutor(Executor executor)
executor.executor - the executor to set.protected Pool<byte[]> getByteArrayPool()
Pool used to transfer streams. Pool instance.public void setByteArrayPool(Pool<byte[]> byteArrayPool)
byte-array-pool.byteArrayPool - the byteArrayPool to setprotected Pool<char[]> getCharArrayPool()
Pool used to transfer Readers and Writers. The
implementation should create char-arrays with a suitable length (at least 512, suggested is 2048). Pool instance.public void setCharArrayPool(Pool<char[]> charArrayPool)
char-array-pool.charArrayPool - the charArrayPool to setprotected void doInitialize()
AbstractComponentinitialization. It is called when AbstractComponent.initialize() is
invoked for the first time. super.AbstractComponent.doInitialize().doInitialize in class AbstractLoggableComponentpublic String read(Reader reader) throws RuntimeIoException
StreamUtilreader into a string. reader is read into memory.read in interface StreamUtilreader - is where to read the content from. It will be closed at the end.reader.RuntimeIoException - if an error occurred with an I/O error.public long transfer(Reader reader, Writer writer, boolean keepWriterOpen) throws RuntimeIoException
StreamUtilreader to the given writer.transfer in interface StreamUtilreader - is where to read the content from. Will be closed at the end.writer - is where to write the content to. Will be closed at the end if
keepWriterOpen is false.keepWriterOpen - if true the given writer will remain open so that additional
content can be appended. Else if false, the writer will be closed.RuntimeIoException - if the operation failed. Closing is guaranteed even in exception state.public long transfer(FileInputStream inStream, OutputStream outStream, boolean keepOutStreamOpen) throws RuntimeIoException
StreamUtiltransfer in interface StreamUtilinStream - is where to read the content from. Will be closed at the end.outStream - is where to write the content to. Will be closed at the end
if keepOutStreamOpen is false.keepOutStreamOpen - if true the given outStream will remain open so that additional
content can be appended. Else if false, the outStream will be
closed.RuntimeIoException - if the operation failed. Closing is guaranteed even in exception state.public long transfer(InputStream inStream, FileOutputStream outStream, boolean keepOutStreamOpen, long size) throws RuntimeIoException
StreamUtiltransfer in interface StreamUtilinStream - is where to read the content from. Will be closed at the end.outStream - is where to write the content to. Will be closed at the end
if keepOutStreamOpen is false.keepOutStreamOpen - if true the given outStream will remain open so that additional
content can be appended. Else if false, the outStream will be
closed.size - is the number of bytes to transfer.RuntimeIoException - if the operation failed. Closing is guaranteed even in exception state.public long transfer(InputStream inStream, OutputStream outStream, boolean keepOutStreamOpen) throws RuntimeIoException
StreamUtilinStream to the given outStream .transfer in interface StreamUtilinStream - is where to read the content from. Will be closed at the end.outStream - is where to write the content to. Will be closed at the end
if keepOutStreamOpen is false.keepOutStreamOpen - if true the given outStream will remain open so that additional
content can be appended. Else if false, the outStream will be
closed.RuntimeIoException - if the operation failed. Closing is guaranteed even in exception state.public AsyncTransferrer transferAsync(InputStream inStream, OutputStream outStream, boolean keepOutStreamOpen)
StreamUtilinStream to the given outStream .transferAsync in interface StreamUtilinStream - is where to read the content from. Will be closed at the end.outStream - is where to write the content to. Will be closed at the end
if keepOutStreamOpen is false.keepOutStreamOpen - if true the given outStream will remain open so that additional
content can be appended. Else if false, the outStream will be
closed.public AsyncTransferrer transferAsync(InputStream inStream, OutputStream outStream, boolean keepOutStreamOpen, TransferCallback callback)
StreamUtilinStream to the given outStream .transferAsync in interface StreamUtilinStream - is where to read the content from. Will be closed at the end.outStream - is where to write the content to. Will be closed at the end
if keepOutStreamOpen is false.keepOutStreamOpen - if true the given outStream will remain open so that additional
content can be appended. Else if false, the outStream will be
closed.callback - is the callback that is invoked if the transfer is done.public AsyncTransferrer transferAsync(Reader reader, Writer writer, boolean keepWriterOpen)
StreamUtilreader to the given writer.transferAsync in interface StreamUtilreader - is where to read the content from. Will be closed at the end.writer - is where to write the content to. Will be closed at the end if
keepWriterOpen is false.keepWriterOpen - if true the given writer will remain open so that additional
content can be appended. Else if false, the writer will be closed.public AsyncTransferrer transferAsync(Reader reader, Writer writer, boolean keepWriterOpen, TransferCallback callback)
StreamUtilreader to the given writer.transferAsync in interface StreamUtilreader - is where to read the content from. Will be closed at the end.writer - is where to write the content to. Will be closed at the end if
keepWriterOpen is false.keepWriterOpen - if true the given writer will remain open so that additional
content can be appended. Else if false, the writer will be closed.callback - is the callback that is invoked if the transfer is done.public Properties loadProperties(InputStream inStream) throws RuntimeIoException
StreamUtilProperties from the given inStream and closes it. ISO-8859-1 . Use
StreamUtil.loadProperties(Reader) instead to use an explicit encoding (e.g. UTF-8).loadProperties in interface StreamUtilinStream - is the InputStream to the properties data.inStream.RuntimeIoException - if the operation failed. Closing is guaranteed even in exception state.Properties.load(InputStream)public Properties loadProperties(Reader reader) throws RuntimeIoException
StreamUtilloadProperties in interface StreamUtilreader - is the Reader to the properties data.reader.RuntimeIoException - if the operation failed. Closing is guaranteed even in exception state.Properties.load(Reader)public PrintWriter toPrintWriter(Appendable appendable)
StreamUtilAppendable to a PrintWriter.toPrintWriter in interface StreamUtilappendable - is the Appendable to wrap.PrintWriter.public Writer toWriter(Appendable appendable)
StreamUtilAppendable to a Writer.toWriter in interface StreamUtilappendable - is the Appendable to wrap.Writer.public void close(InputStream inputStream)
StreamUtilinputStream without throwing an Exception. If an exception
occurs, it will only be logged.close in interface StreamUtilinputStream - is the input-stream to close.public void close(OutputStream outputStream)
StreamUtiloutputStream without throwing an IOException.close in interface StreamUtiloutputStream - is the output-stream to close.public void close(Writer writer)
StreamUtilwriter without throwing an IOException.close in interface StreamUtilwriter - is the writer to close.public void close(Reader reader)
StreamUtilreader without throwing an Exception. If an exception
occurs, it will only be logged.close in interface StreamUtilreader - is the reader to close.public void close(Channel channel)
StreamUtilchannel without throwing an Exception.close in interface StreamUtilchannel - is the channel to close.Copyright © 2001–2016 mmm-Team. All rights reserved.