Package gw.util
Class StreamUtil
java.lang.Object
gw.util.StreamUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Closes the specified streams, suppressing any IOExceptions for inputstreams and readers.private static void
static void
closeNoThrow
(Closeable stream) Close and swallow exception the exception.static void
Recursively copy a file or directory to a directory.static void
copy
(InputStream in, OutputStream out) Copies the content of an input stream to an output stream.static void
copy
(InputStream in, Writer writer) Copies the content of an input stream to a writer.static void
copy
(Reader reader, OutputStream out) Copies the content of a reader to an output stream.static void
Copies the content of a reader to a writer.static void
Recursively copy a file or directory to a directory.static byte[]
Returns the content of the specified input stream.static String
getContent
(Reader in) Returns the content of the specified reader.static Reader
Returns a reader for the specified input stream, using UTF-8 encoding.static Reader
getInputStreamReader
(InputStream in, String charset) Returns a reader for the specified input stream, using specified encoding.static Writer
Returns a writer for the specified output stream, using UTF-8 encoding.static InputStream
Returns an input stream for the specified character sequence, using UTF-8 encoding.static byte[]
toBytes
(CharSequence seq) Converts the specified character sequence to bytes using UTF-8.static Properties
toProperties
(String propFileText) Converts the specified property file text to a Properties object.static String
toString
(byte[] bytes) Converts the specified byte array to a String using UTF-8.static String
toString
(byte[] bytes, int offset, int length) Converts the specified byte array to a String using UTF-8.
-
Constructor Details
-
StreamUtil
private StreamUtil()
-
-
Method Details
-
toBytes
Converts the specified character sequence to bytes using UTF-8.- Parameters:
seq
- the character sequence to convert- Returns:
- the UTF-8 encoded result
-
toString
Converts the specified byte array to a String using UTF-8.- Parameters:
bytes
- the bytes to convert- Returns:
- the resulting string
-
toString
Converts the specified byte array to a String using UTF-8.- Parameters:
bytes
- the bytes to convertoffset
- the index of the first byte to decodelength
- the number of bytes to decode- Returns:
- the resulting string
-
toProperties
Converts the specified property file text to a Properties object.- Parameters:
propFileText
- the property file text in standard property file format- Returns:
- the resulting Properties object
- Throws:
CharacterCodingException
- if invalid encoding
-
getInputStreamReader
Returns a reader for the specified input stream, using UTF-8 encoding.- Parameters:
in
- the input stream to wrap- Returns:
- a reader for this input stream
-
getInputStreamReader
Returns a reader for the specified input stream, using specified encoding.- Parameters:
in
- the input stream to wrapcharset
- the input stream to wrap- Returns:
- a reader for this input stream
-
getOutputStreamWriter
Returns a writer for the specified output stream, using UTF-8 encoding.- Parameters:
out
- the output stream to wrap- Returns:
- a writer for this output stream
-
getStringInputStream
Returns an input stream for the specified character sequence, using UTF-8 encoding.- Parameters:
cs
- the character sequence to wrap- Returns:
- an input stream for reading the specified character sequence
-
getContent
Returns the content of the specified input stream. The stream will be closed after calling this method.- Parameters:
in
- the input stream to read- Returns:
- the content of the input stream
- Throws:
IOException
- if an I/O error occurs
-
getContent
Returns the content of the specified reader. The reader will be closed after calling this method.- Parameters:
in
- the reader to read- Returns:
- the content of the reader
- Throws:
IOException
- if an I/O error occurs
-
copy
Copies the content of an input stream to an output stream.- Parameters:
in
- the input stream to readout
- the output stream to write- Throws:
IOException
- if an I/O error occurs
-
copy
Copies the content of an input stream to a writer.- Parameters:
in
- the input stream to readwriter
- the writer to write- Throws:
IOException
- if an I/O error occurs
-
copy
Copies the content of a reader to an output stream.- Parameters:
reader
- the reader to readout
- the output stream to write- Throws:
IOException
- if an I/O error occurs
-
copy
Copies the content of a reader to a writer.- Parameters:
in
- the reader to readout
- the writer to write- Throws:
IOException
- if an I/O error occurs
-
copy
Recursively copy a file or directory to a directory. -
copy
Recursively copy a file or directory to a directory. -
closeNoThrow
Close and swallow exception the exception. For use in finally blocks where the other io exceptions is what is wanted to be thrown.- Parameters:
stream
- the streams to close
-
close
Closes the specified streams, suppressing any IOExceptions for inputstreams and readers. Even if an I/O exception is thrown, all streams can be considered closed.- Parameters:
streams
- the streams to close- Throws:
IOException
- if an i/o exception occurs while closing any outputstream or writer
-
close
- Throws:
IOException
-