public class Streams extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
closeInputSource(InputSource in)
Close the specified input source.
|
static void |
closeInputStream(InputStream in)
Deprecated.
Use
closeQuietly(Closeable) instead. |
static void |
closeOutputStream(OutputStream out)
Deprecated.
Use
closeQuietly(Closeable) instead. |
static IOException |
closeQuietly(Closeable c)
Closes the closeable without raising exceptions.
|
static void |
closeReader(Reader reader)
Deprecated.
Use
closeQuietly(Closeable) instead. |
static void |
closeWriter(Writer writer)
Deprecated.
Use
closeQuietly(Closeable) instead. |
static void |
copy(InputStream in,
OutputStream out)
Copies the content of the input stream into the output stream.
|
static void |
copy(Reader reader,
Writer writer)
Copies the content of the reader into the writer.
|
static String |
getDefaultJavaCharset()
Returns Java's canonical name of the default character set for
the system's current default locale.
|
static byte[] |
toByteArray(InputStream in)
Returns all the bytes read from the specified input stream as an
array.
|
static char[] |
toCharArray(InputSource in)
Reads the character content from the specified input source and
returns it as a character array.
|
static char[] |
toCharArray(InputStream in,
String charset)
Reads the full contents of the specified input stream and
returns the characters determined by the specified character set.
|
static char[] |
toCharArray(Reader reader)
Reads the full contents of the specified reader and returns
it as a character array.
|
public static String getDefaultJavaCharset()
Note: This method is available in the J2EE version
of Java as javax.mail.internet.getDefaultJavaCharset().
Note 2: For example, the standard English install
of Sun's J2SE 1.4.2 on windows sets the default character set to
"Cp1252", the Windows variant of Latin1.
public static byte[] toByteArray(InputStream in) throws IOException
This method will block waiting for input.
in - Input stream from which to read bytes.IOException - If the underlying stream throws an exception
while reading.public static char[] toCharArray(Reader reader) throws IOException
reader - Reader from which to get characters.IOException - If there is an underlying I/O exception.public static char[] toCharArray(InputStream in, String charset) throws IOException
in - The input stream from which to read the bytes.charset - Character set used to convert bytes to characters.IOException - If there is an underlying I/O exception.public static char[] toCharArray(InputSource in) throws IOException
Reader), then that
is used. If it has a specified byte stream (an
InputStream), then that is used. If it has
neither a character nor a byte stream, a byte stream is created
from the system identifier (URL). For both specified and
URL-constructed byte streams, the input source's specified
character set will be used if it is specified, otherwise the
platform default is used (as specified in InputStreamReader.InputStreamReader(InputStream)).
I/O errors will arise from errors reading from a specified stream, from the character set conversion on a byte stream, or from errors forming or opening a URL specified as a system identifier.
Note that this method does not close the streams within the
input source. See closeInputSource(InputSource).
in - Input source from which to read.IOException - If there is an I/O error reading.public static void copy(Reader reader, Writer writer) throws IOException
reader - Reader to copy from.writer - Writer to copy to.IOException - If there is an underlying I/O exception.public static void copy(InputStream in, OutputStream out) throws IOException
in - Input stream to copy from.out - Output stream to copy to.IOException - If there is an underlying I/O exception.public static IOException closeQuietly(Closeable c)
c - The object to close.public static void closeInputSource(InputSource in)
null,
as may its byte stream and/or character stream without throwing
an exception.in - Input source to close.@Deprecated public static void closeInputStream(InputStream in)
closeQuietly(Closeable) instead.null without
generating an exception.in - Input stream to close.@Deprecated public static void closeOutputStream(OutputStream out)
closeQuietly(Closeable) instead.null
without generating an exception.out - Output stream to close.@Deprecated public static void closeReader(Reader reader)
closeQuietly(Closeable) instead.null
without generating an exception.reader - Reader to close.@Deprecated public static void closeWriter(Writer writer)
closeQuietly(Closeable) instead.null
without generating an exception.writer - Writer to close.Copyright © 2016 Alias-i, Inc.. All rights reserved.