org.apache.commons.io
Class IOUtils
java.lang.Object
org.apache.commons.io.IOUtils
public final class IOUtils
extends java.lang.Object
General IO Stream manipulation.
This class provides static utility methods for input/output operations.
The closeQuietly methods are expected to be used when an IOException
would be meaningless. This is usually when in a catch block for an
IOException.
The toString and toByteArray methods all rely on CopyUtils.copy
methods in the current implementation.
Origin of code: Apache Avalon (Excalibur)
CVS $Revision: 1.14 $ $Date: 2004/04/24 23:49:25 $
IOUtils() - Instances should NOT be constructed in standard programming.
|
static void | closeQuietly(InputStream input) - Unconditionally close an
InputStream .
|
static void | closeQuietly(OutputStream output) - Unconditionally close an
OutputStream .
|
static void | closeQuietly(Reader input) - Unconditionally close an
Reader .
|
static void | closeQuietly(Writer output) - Unconditionally close an
Writer .
|
static boolean | contentEquals(InputStream input1, InputStream input2) - Compare the contents of two Streams to determine if they are equal or not.
|
static byte[] | toByteArray(InputStream input) - Get the contents of an
InputStream as a byte[] .
|
static byte[] | toByteArray(Reader input) - Get the contents of a
Reader as a byte[] .
|
static byte[] | toByteArray(String input) - Get the contents of a
String as a byte[] .
|
static String | toString(InputStream input) - Get the contents of an
InputStream as a String.
|
static String | toString(InputStream input, String encoding) - Get the contents of an
InputStream as a String.
|
static String | toString(Reader input) - Get the contents of a
Reader as a String.
|
static String | toString(byte[] input) - Get the contents of a
byte[] as a String.
|
static String | toString(byte[] input, String encoding) - Get the contents of a
byte[] as a String.
|
DEFAULT_BUFFER_SIZE
private static final int DEFAULT_BUFFER_SIZE
IOUtils
public IOUtils()
Instances should NOT be constructed in standard programming.
closeQuietly
public static void closeQuietly(InputStream input)
Unconditionally close an InputStream
.
Equivalent to InputStream.close()
, except any exceptions will be ignored.
input
- A (possibly null) InputStream
closeQuietly
public static void closeQuietly(OutputStream output)
Unconditionally close an OutputStream
.
Equivalent to OutputStream.close()
, except any exceptions will be ignored.
output
- A (possibly null) OutputStream
closeQuietly
public static void closeQuietly(Reader input)
Unconditionally close an Reader
.
Equivalent to Reader.close()
, except any exceptions will be ignored.
input
- A (possibly null) Reader
closeQuietly
public static void closeQuietly(Writer output)
Unconditionally close an Writer
.
Equivalent to Writer.close()
, except any exceptions will be ignored.
output
- A (possibly null) Writer
contentEquals
public static boolean contentEquals(InputStream input1,
InputStream input2)
throws IOException
Compare the contents of two Streams to determine if they are equal or not.
input1
- the first streaminput2
- the second stream
- true if the content of the streams are equal or they both don't exist, false otherwise
toByteArray
public static byte[] toByteArray(InputStream input)
throws IOException
Get the contents of an InputStream
as a byte[]
.
input
- the InputStream
to read from
toByteArray
public static byte[] toByteArray(Reader input)
throws IOException
Get the contents of a Reader
as a byte[]
.
input
- the Reader
to read from
toByteArray
public static byte[] toByteArray(String input)
throws IOException
Get the contents of a String
as a byte[]
.
input
- the String
to convert
toString
public static String toString(InputStream input)
throws IOException
Get the contents of an InputStream
as a String.
The platform's default encoding is used for the byte-to-char conversion.
input
- the InputStream
to read from
toString
public static String toString(InputStream input,
String encoding)
throws IOException
Get the contents of an InputStream
as a String.
input
- the InputStream
to read fromencoding
- The name of a supported character encoding. See the
IANA
Charset Registry for a list of valid encoding types.
toString
public static String toString(Reader input)
throws IOException
Get the contents of a Reader
as a String.
input
- the Reader
to read from
toString
public static String toString(byte[] input)
throws IOException
Get the contents of a byte[]
as a String.
The platform's default encoding is used for the byte-to-char conversion.
input
- the byte array to read from
toString
public static String toString(byte[] input,
String encoding)
throws IOException
Get the contents of a byte[]
as a String.
input
- the byte array to read fromencoding
- The name of a supported character encoding. See the
IANA
Charset Registry for a list of valid encoding types.