|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
@ComponentSpecification public interface StreamUtil
This is the interface for a collection of utility functions that help to deal
with InputStream
s, OutputStream
s, Reader
s and
Writer
s.
Information:
Whenever the javadoc of a method specifies that an object (stream, reader or
writer) is closed, then this means that it will be closed on successful
return of the method as well as in an exceptional state. If it says that an
object is NOT closed then the caller is responsible to ensure that it will be
closed properly.
StreamUtilImpl
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 . |
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. |
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 . |
Method Detail |
---|
String read(Reader reader) throws IOException
reader
into a
string.reader
is read into
memory.
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.long transfer(Reader reader, Writer writer, boolean keepWriterOpen) throws IOException
reader
to the
given writer
.
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.long transfer(FileInputStream inStream, OutputStream outStream, boolean keepOutStreamOpen) throws IOException
inStream
to
the given outStream
using NIO-Channels
.
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.long transfer(InputStream inStream, FileOutputStream outStream, boolean keepOutStreamOpen, long size) throws IOException
inStream
to
the given outStream
using NIO-Channels
.
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.long transfer(InputStream inStream, OutputStream outStream, boolean keepOutStreamOpen) throws IOException
inStream
to
the given outStream
.
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.AsyncTransferrer transferAsync(InputStream inStream, OutputStream outStream, boolean keepOutStreamOpen)
inStream
to
the given outStream
.
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
.
AsyncTransferrer transferAsync(InputStream inStream, OutputStream outStream, boolean keepOutStreamOpen, TransferCallback callback)
inStream
to
the given outStream
.
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.
AsyncTransferrer transferAsync(Reader reader, Writer writer, boolean keepWriterOpen)
reader
to the
given writer
.
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
.
AsyncTransferrer transferAsync(Reader reader, Writer writer, boolean keepWriterOpen, TransferCallback callback)
reader
to the
given writer
.
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.
Properties loadProperties(InputStream inStream) throws IOException
Properties
from the given
inStream
and closes
it.ISO-8859-1
. Use loadProperties(Reader)
instead to use an explicit encoding
(e.g. UTF-8
).
inStream
- is the InputStream
to the properties data.
inStream
.
IOException
- if the operation failed. Closing is guaranteed even in
exception state.Properties.load(InputStream)
Properties loadProperties(Reader reader) throws IOException
Properties
from the given reader
and closes
it.
reader
- is the Reader
to the properties data.
reader
.
IOException
- if the operation failed. Closing is guaranteed even in
exception state.Properties.load(Reader)
Writer toWriter(Appendable appendable)
Appendable
to a Writer
.
appendable
- is the Appendable
to wrap.
Writer
.PrintWriter toPrintWriter(Appendable appendable)
Appendable
to a PrintWriter
.
appendable
- is the Appendable
to wrap.
PrintWriter
.void close(InputStream inputStream)
inputStream
without throwing an
Exception
. If an exception occurs, it will only be logged.
inputStream
- is the input-stream to close.void close(OutputStream outputStream) throws RuntimeIoException
outputStream
without throwing an
IOException
.
outputStream
- is the output-stream to close.
RuntimeIoException
- if the closing failed.void close(Writer writer) throws RuntimeIoException
writer
without throwing an
IOException
.
writer
- is the writer to close.
RuntimeIoException
- if the closing failed.void close(Reader reader)
reader
without throwing an
Exception
. If an exception occurs, it will only be logged.
reader
- is the reader to close.void close(Channel channel)
channel
without throwing an
Exception
.
channel
- is the channel to close.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |