public class StreamUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
close(Closeable... streams)
Closes the specified streams, suppressing any IOExceptions for inputstreams and readers.
|
static void |
closeNoThrow(Closeable stream)
Close and swallow exception the exception.
|
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 |
copy(Reader in,
Writer out)
Copies the content of a reader to a writer.
|
static byte[] |
getContent(InputStream in)
Returns the content of the specified input stream.
|
static String |
getContent(Reader in)
Returns the content of the specified reader.
|
static Reader |
getInputStreamReader(InputStream in)
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 |
getOutputStreamWriter(OutputStream out)
Returns a writer for the specified output stream, using UTF-8 encoding.
|
static InputStream |
getStringInputStream(CharSequence cs)
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.
|
public static byte[] toBytes(CharSequence seq)
seq - the character sequence to convertpublic static String toString(byte[] bytes)
bytes - the bytes to convertpublic static String toString(byte[] bytes, int offset, int length)
bytes - the bytes to convertoffset - the index of the first byte to decodelength - the number of bytes to decodepublic static Properties toProperties(String propFileText) throws CharacterCodingException
propFileText - the property file text in standard property file formatCharacterCodingException - if invalid encodingpublic static Reader getInputStreamReader(InputStream in)
in - the input stream to wrappublic static Reader getInputStreamReader(InputStream in, String charset)
in - the input stream to wrapcharset - the input stream to wrappublic static Writer getOutputStreamWriter(OutputStream out)
out - the output stream to wrappublic static InputStream getStringInputStream(CharSequence cs)
cs - the character sequence to wrappublic static byte[] getContent(InputStream in) throws IOException
in - the input stream to readIOException - if an I/O error occurspublic static String getContent(Reader in) throws IOException
in - the reader to readIOException - if an I/O error occurspublic static void copy(InputStream in, OutputStream out) throws IOException
in - the input stream to readout - the output stream to writeIOException - if an I/O error occurspublic static void copy(InputStream in, Writer writer) throws IOException
in - the input stream to readwriter - the writer to writeIOException - if an I/O error occurspublic static void copy(Reader reader, OutputStream out) throws IOException
reader - the reader to readout - the output stream to writeIOException - if an I/O error occurspublic static void copy(Reader in, Writer out) throws IOException
in - the reader to readout - the writer to writeIOException - if an I/O error occurspublic static void closeNoThrow(Closeable stream)
stream - the streams to closepublic static void close(Closeable... streams) throws IOException
streams - the streams to closeIOException - if an i/o exception occurs while closing any outputstream or writerCopyright © 2022. All rights reserved.