|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.mmm.util.component.base.AbstractComponent
net.sf.mmm.util.component.base.AbstractLoggableComponent
net.sf.mmm.util.io.base.StreamUtilImpl
@Singleton @Named public class StreamUtilImpl
This is the implementation of the StreamUtil
interface.
getInstance()
Nested Class Summary | |
---|---|
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
This is an abstract implementation of the AsyncTransferrer
interface, that implements Runnable defining the main flow. |
protected class |
StreamUtilImpl.ReaderTransferrer
This inner class is used to transfer a Reader to a Writer . |
protected class |
StreamUtilImpl.StreamTransferrer
This inner class is used to transfer an InputStream to an
OutputStream . |
Field Summary | |
---|---|
private Pool<byte[]> |
byteArrayPool
|
private Pool<char[]> |
charArrayPool
|
private Executor |
executor
|
private static StreamUtil |
instance
|
Constructor Summary | |
---|---|
StreamUtilImpl()
The constructor. |
Method Summary | |
---|---|
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()
This method gets the char-array Pool used to transfer
Reader s and Writer s. |
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)
This method loads the Properties from the given
inStream and closes it. |
Properties |
loadProperties(Reader reader)
This method loads the Properties from the given reader
and closes it. |
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)
This method transfers the contents of the given inStream to
the given outStream using NIO-Channels . |
long |
transfer(InputStream inStream,
FileOutputStream outStream,
boolean keepOutStreamOpen,
long size)
This method transfers the contents of the given inStream to
the given outStream using NIO-Channels . |
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 . |
Methods inherited from class net.sf.mmm.util.component.base.AbstractLoggableComponent |
---|
getLogger, setLogger |
Methods inherited from class net.sf.mmm.util.component.base.AbstractComponent |
---|
doInitialized, getInitializationState, initialize |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static StreamUtil instance
getInstance()
private Executor executor
getExecutor()
private Pool<byte[]> byteArrayPool
getByteArrayPool()
private Pool<char[]> charArrayPool
getCharArrayPool()
Constructor Detail |
---|
public StreamUtilImpl()
Method Detail |
---|
public static StreamUtil getInstance()
StreamUtilImpl
.getInstance()
methods and
construct new instances via the container-framework of your choice (like
plexus, pico, springframework, etc.). To wire up the dependent components
everything is properly annotated using common-annotations (JSR-250). If
your container does NOT support this, you should consider using a better
one.
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
Reader
s and Writer
s. 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()
initialization
. It is
called when AbstractComponent.initialize()
is invoked for the first time.super.AbstractComponent.doInitialize()
.
doInitialize
in class AbstractLoggableComponent
public String read(Reader reader) throws IOException
reader
into a
string.reader
is read into
memory.
read
in interface StreamUtil
reader
- is where to read the content from. It will be
closed
at the end.
reader
.
IOException
- if an error occurred with an I/O error.public long transfer(Reader reader, Writer writer, boolean keepWriterOpen) throws IOException
reader
to the
given writer
.
transfer
in interface StreamUtil
reader
- 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
.
IOException
- if the operation failed. Closing is guaranteed even in
exception state.public long transfer(FileInputStream inStream, OutputStream outStream, boolean keepOutStreamOpen) throws IOException
inStream
to
the given outStream
using NIO-Channels
.
transfer
in interface StreamUtil
inStream
- 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
.
IOException
- if the operation failed. Closing is guaranteed even in
exception state.public long transfer(InputStream inStream, FileOutputStream outStream, boolean keepOutStreamOpen, long size) throws IOException
inStream
to
the given outStream
using NIO-Channels
.
transfer
in interface StreamUtil
inStream
- 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.
IOException
- if the operation failed. Closing is guaranteed even in
exception state.public long transfer(InputStream inStream, OutputStream outStream, boolean keepOutStreamOpen) throws IOException
inStream
to
the given outStream
.
transfer
in interface StreamUtil
inStream
- 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
.
IOException
- if the operation failed. Closing is guaranteed even in
exception state.public AsyncTransferrer transferAsync(InputStream inStream, OutputStream outStream, boolean keepOutStreamOpen)
inStream
to
the given outStream
.
transferAsync
in interface StreamUtil
inStream
- 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)
inStream
to
the given outStream
.
transferAsync
in interface StreamUtil
inStream
- 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)
reader
to the
given writer
.
transferAsync
in interface StreamUtil
reader
- 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)
reader
to the
given writer
.
transferAsync
in interface StreamUtil
reader
- 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 IOException
Properties
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 StreamUtil
inStream
- is the InputStream
to the properties data.
inStream
.
IOException
- if the operation failed. Closing is guaranteed even in
exception state.Properties.load(InputStream)
public Properties loadProperties(Reader reader) throws IOException
Properties
from the given reader
and closes
it.
loadProperties
in interface StreamUtil
reader
- is the Reader
to the properties data.
reader
.
IOException
- if the operation failed. Closing is guaranteed even in
exception state.Properties.load(Reader)
public PrintWriter toPrintWriter(Appendable appendable)
Appendable
to a PrintWriter
.
toPrintWriter
in interface StreamUtil
appendable
- is the Appendable
to wrap.
PrintWriter
.public Writer toWriter(Appendable appendable)
Appendable
to a Writer
.
toWriter
in interface StreamUtil
appendable
- is the Appendable
to wrap.
Writer
.public void close(InputStream inputStream)
inputStream
without throwing an
Exception
. If an exception occurs, it will only be logged.
close
in interface StreamUtil
inputStream
- is the input-stream to close.public void close(OutputStream outputStream)
outputStream
without throwing an
IOException
.
close
in interface StreamUtil
outputStream
- is the output-stream to close.public void close(Writer writer)
writer
without throwing an
IOException
.
close
in interface StreamUtil
writer
- is the writer to close.public void close(Reader reader)
reader
without throwing an
Exception
. If an exception occurs, it will only be logged.
close
in interface StreamUtil
reader
- is the reader to close.public void close(Channel channel)
channel
without throwing an
Exception
.
close
in interface StreamUtil
channel
- is the channel to close.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |