|
JavaGantt 2011.1 API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecteu.beesoft.gaia.util.Streams
public final class Streams
Utility class for the stream I/O operations.
Method Summary | |
---|---|
static void |
close(java.io.InputStream input)
Closes given input stream. |
static void |
close(java.io.OutputStream output)
Closes given output stream. |
static void |
close(java.io.Reader input)
Closes given input reader. |
static void |
close(java.io.Writer output)
Closes given output writer. |
static void |
copy(java.io.InputStream input,
java.io.OutputStream output)
Copies all data from input stream to output stream. |
static byte[] |
copyToByteArray(java.io.InputStream input)
Copies all data from input stream to the returned byte array. |
static java.io.InputStream |
getInputStream(java.io.File resource)
Returns an input stream from a given File resource . |
static java.io.InputStream |
getInputStream(java.lang.String resource)
Returns an input stream for given resource . |
static java.io.OutputStream |
getOutputStream(java.io.File file)
Returns an output stream for a given file . |
static java.io.OutputStream |
getOutputStream(java.lang.String fileName)
Returns an output stream for a file with given fileName . |
static java.io.Reader |
getReader(java.lang.String resource)
Returns a reader for given resource and system default
encoding. |
static java.io.Reader |
getReader(java.lang.String resource,
java.lang.String encoding)
Returns a reader for given resource and
encoding . |
static java.io.Writer |
getWriter(java.lang.String fileName)
Returns a writer for given fileName and system default
encoding. |
static java.io.Writer |
getWriter(java.lang.String fileName,
java.lang.String encoding)
Returns a writer for given fileName and
encoding . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static java.io.InputStream getInputStream(java.lang.String resource)
resource
. First it tries
to get input stream from a file on the file-system level. If such file
does not exist, it edits name (adds or removes initial slash) and repeats
previous step. If there is no file found, it tries to get input stream
via Class.getResourceAsStream() method for original resource
and if not successfull for edited name, too. If cannot find a
resource
, throws RuntimeException.
resource
- - a resource name
java.lang.NullPointerException
- if resource is null
java.lang.RuntimeException
- if cannot create an input streampublic static java.io.InputStream getInputStream(java.io.File resource)
resource
.
resource
- - a File instance
java.lang.NullPointerException
- if resource is null
java.lang.RuntimeException
- if cannot create an input streampublic static java.io.Reader getReader(java.lang.String resource)
resource
and system default
encoding. Invokes getReader(String, String)
to obtain Reader
instance.
resource
- - a resource name
java.lang.NullPointerException
- if resource is null
java.lang.RuntimeException
- if cannot create a reader instance from given resourcepublic static java.io.Reader getReader(java.lang.String resource, java.lang.String encoding)
resource
and
encoding
. Invokes getInputStream(String)
to obtain
input stream (see description in that method for information about input
stream construction). Then creates a reader for given
encoding
. If encoding is null, uses default system encoding.
resource
- - a resource nameencoding
- - character stream encoding (such as UTF-8), may be null
java.lang.NullPointerException
- if resource is null
java.lang.RuntimeException
- if cannot create a reader instance from a given resource or
if given encoding is not supportedpublic static java.io.OutputStream getOutputStream(java.lang.String fileName)
fileName
.
Creates also all directories that do not exist in the file path.
fileName
- - a file name
java.lang.NullPointerException
- if fileName is null
java.lang.RuntimeException
- if cannot create an output streampublic static java.io.OutputStream getOutputStream(java.io.File file)
file
. Creates also all
directories that do not exist in the file path.
file
- - a File instance to streaming
java.lang.NullPointerException
- if file is null
java.lang.RuntimeException
- if cannot create an output streampublic static java.io.Writer getWriter(java.lang.String fileName)
fileName
and system default
encoding. Invokes getWriter(String, String)
to obtain Writer
instance.
fileName
- - a target file name
java.lang.NullPointerException
- if fileName is null
java.lang.RuntimeException
- if cannot create a writerpublic static java.io.Writer getWriter(java.lang.String fileName, java.lang.String encoding)
fileName
and
encoding
. Invokes getOutputStream(String)
to obtain
output stream (see description in that method for information about
output stream construction). Then creates a writer for given
encoding
. If encoding is null, uses default system encoding.
fileName
- - a target file nameencoding
- - character stream encoding (such as UTF-8)
java.lang.NullPointerException
- if fileName is null
java.lang.RuntimeException
- if cannot create a writer or if given encoding is not
supportedpublic static void copy(java.io.InputStream input, java.io.OutputStream output)
input
- - an input streamoutput
- - an output stream
java.lang.RuntimeException
- if some exception was thrownpublic static byte[] copyToByteArray(java.io.InputStream input)
input
- - an input stream
java.lang.RuntimeException
- if some exception was thrownpublic static void close(java.io.InputStream input)
input
stream. No exception is thrown if some
problem occurs.
input
- - an input stream to closepublic static void close(java.io.Reader input)
input
reader. No exception is thrown if some
problem occurs.
input
- - an input stream to closepublic static void close(java.io.OutputStream output)
output
stream. A stream is flushed before
close.
output
- - an output stream to close, may be null
java.lang.RuntimeException
- if an error occurspublic static void close(java.io.Writer output)
output
writer. A writer is flushed before
close.
output
- - an output stream to close, may be null
java.lang.RuntimeException
- if an error occurs
|
JavaGantt 2011.1 API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |