Package gw.util
Class StreamUtil
- java.lang.Object
-
- gw.util.StreamUtil
-
public class StreamUtil extends java.lang.Object
-
-
Constructor Summary
Constructors Modifier Constructor Description privateStreamUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclose(java.io.Closeable... streams)Closes the specified streams, suppressing any IOExceptions for inputstreams and readers.private static voidclose(java.io.Closeable[] streams, int idx)static voidcloseNoThrow(java.io.Closeable stream)Close and swallow exception the exception.static voidcopy(java.io.File fileOrDirectory, java.io.File toDir)Recursively copy a file or directory to a directory.static voidcopy(java.io.InputStream in, java.io.OutputStream out)Copies the content of an input stream to an output stream.static voidcopy(java.io.InputStream in, java.io.Writer writer)Copies the content of an input stream to a writer.static voidcopy(java.io.Reader reader, java.io.OutputStream out)Copies the content of a reader to an output stream.static voidcopy(java.io.Reader in, java.io.Writer out)Copies the content of a reader to a writer.static voidcopy(java.nio.file.Path fileOrDirectory, java.nio.file.Path toDir)Recursively copy a file or directory to a directory.static byte[]getContent(java.io.InputStream in)Returns the content of the specified input stream.static java.lang.StringgetContent(java.io.Reader in)Returns the content of the specified reader.static java.io.ReadergetInputStreamReader(java.io.InputStream in)Returns a reader for the specified input stream, using UTF-8 encoding.static java.io.ReadergetInputStreamReader(java.io.InputStream in, java.lang.String charset)Returns a reader for the specified input stream, using specified encoding.static java.io.WritergetOutputStreamWriter(java.io.OutputStream out)Returns a writer for the specified output stream, using UTF-8 encoding.static java.io.InputStreamgetStringInputStream(java.lang.CharSequence cs)Returns an input stream for the specified character sequence, using UTF-8 encoding.static byte[]toBytes(java.lang.CharSequence seq)Converts the specified character sequence to bytes using UTF-8.static java.util.PropertiestoProperties(java.lang.String propFileText)Converts the specified property file text to a Properties object.static java.lang.StringtoString(byte[] bytes)Converts the specified byte array to a String using UTF-8.static java.lang.StringtoString(byte[] bytes, int offset, int length)Converts the specified byte array to a String using UTF-8.
-
-
-
Method Detail
-
toBytes
public static byte[] toBytes(java.lang.CharSequence seq)
Converts the specified character sequence to bytes using UTF-8.- Parameters:
seq- the character sequence to convert- Returns:
- the UTF-8 encoded result
-
toString
public static java.lang.String toString(byte[] bytes)
Converts the specified byte array to a String using UTF-8.- Parameters:
bytes- the bytes to convert- Returns:
- the resulting string
-
toString
public static java.lang.String toString(byte[] bytes, int offset, int length)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
public static java.util.Properties toProperties(java.lang.String propFileText) throws java.nio.charset.CharacterCodingExceptionConverts 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:
java.nio.charset.CharacterCodingException- if invalid encoding
-
getInputStreamReader
public static java.io.Reader getInputStreamReader(java.io.InputStream in)
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
public static java.io.Reader getInputStreamReader(java.io.InputStream in, java.lang.String charset)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
public static java.io.Writer getOutputStreamWriter(java.io.OutputStream out)
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
public static java.io.InputStream getStringInputStream(java.lang.CharSequence cs)
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
public static byte[] getContent(java.io.InputStream in) throws java.io.IOExceptionReturns 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:
java.io.IOException- if an I/O error occurs
-
getContent
public static java.lang.String getContent(java.io.Reader in) throws java.io.IOExceptionReturns 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:
java.io.IOException- if an I/O error occurs
-
copy
public static void copy(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOExceptionCopies the content of an input stream to an output stream.- Parameters:
in- the input stream to readout- the output stream to write- Throws:
java.io.IOException- if an I/O error occurs
-
copy
public static void copy(java.io.InputStream in, java.io.Writer writer) throws java.io.IOExceptionCopies the content of an input stream to a writer.- Parameters:
in- the input stream to readwriter- the writer to write- Throws:
java.io.IOException- if an I/O error occurs
-
copy
public static void copy(java.io.Reader reader, java.io.OutputStream out) throws java.io.IOExceptionCopies the content of a reader to an output stream.- Parameters:
reader- the reader to readout- the output stream to write- Throws:
java.io.IOException- if an I/O error occurs
-
copy
public static void copy(java.io.Reader in, java.io.Writer out) throws java.io.IOExceptionCopies the content of a reader to a writer.- Parameters:
in- the reader to readout- the writer to write- Throws:
java.io.IOException- if an I/O error occurs
-
copy
public static void copy(java.io.File fileOrDirectory, java.io.File toDir)Recursively copy a file or directory to a directory.
-
copy
public static void copy(java.nio.file.Path fileOrDirectory, java.nio.file.Path toDir)Recursively copy a file or directory to a directory.
-
closeNoThrow
public static void closeNoThrow(java.io.Closeable stream)
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
public static void close(java.io.Closeable... streams) throws java.io.IOExceptionCloses 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:
java.io.IOException- if an i/o exception occurs while closing any outputstream or writer
-
close
private static void close(java.io.Closeable[] streams, int idx) throws java.io.IOException- Throws:
java.io.IOException
-
-