public class IOUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
closeSilently(InputStream in)
Close an input stream without throwing an exception.
|
static void |
closeSilently(OutputStream out)
Close an output stream without throwing an exception.
|
static void |
closeSilently(Reader reader)
Close a reader without throwing an exception.
|
static void |
closeSilently(Writer writer)
Close a writer without throwing an exception.
|
static long |
copy(InputStream in,
OutputStream out)
Copy all data from the input stream to the output stream.
|
static long |
copy(InputStream in,
OutputStream out,
long length)
Copy all data from the input stream to the output stream.
|
static long |
copyAndClose(InputStream in,
OutputStream out)
Copy all data from the input stream to the output stream and close both
streams.
|
static long |
copyAndCloseInput(InputStream in,
OutputStream out)
Copy all data from the input stream to the output stream and close the
input stream.
|
static long |
copyAndCloseInput(Reader in,
Writer out,
long length)
Copy all data from the reader to the writer and close the reader.
|
static Reader |
getAsciiReader(InputStream in)
Wrap an input stream in a reader.
|
static Reader |
getBufferedReader(InputStream in)
Create a buffered reader to read from an input stream using the UTF-8
format.
|
static Writer |
getBufferedWriter(OutputStream out)
Create a buffered writer to write to an output stream using the UTF-8
format.
|
static InputStream |
getInputStreamFromString(String s)
Create an input stream to read from a string.
|
static Reader |
getReader(InputStream in)
Create a reader to read from an input stream using the UTF-8 format.
|
static Reader |
getReaderFromString(String s)
Create a reader to read from a string.
|
static byte[] |
readBytesAndClose(InputStream in,
int length)
Read a number of bytes from an input stream and close the stream.
|
static int |
readFully(InputStream in,
byte[] buffer,
int off,
int max)
Try to read the given number of bytes to the buffer.
|
static int |
readFully(Reader in,
char[] buffer,
int max)
Try to read the given number of characters to the buffer.
|
static String |
readStringAndClose(Reader in,
int length)
Read a number of characters from a reader and close it.
|
static void |
skipFully(InputStream in,
long skip)
Skip a number of bytes in an input stream.
|
static void |
skipFully(Reader reader,
long skip)
Skip a number of characters in a reader.
|
static void |
trace(String method,
String fileName,
Object o)
Trace input or output operations if enabled.
|
public static void closeSilently(OutputStream out)
out - the output stream or nullpublic static void skipFully(InputStream in, long skip) throws IOException
in - the input streamskip - the number of bytes to skipEOFException - if the end of file has been reached before all bytes
could be skippedIOException - if an IO exception occurred while skippingpublic static void skipFully(Reader reader, long skip) throws IOException
reader - the readerskip - the number of characters to skipEOFException - if the end of file has been reached before all
characters could be skippedIOException - if an IO exception occurred while skippingpublic static long copyAndClose(InputStream in, OutputStream out) throws IOException
in - the input streamout - the output streamIOExceptionpublic static long copyAndCloseInput(InputStream in, OutputStream out) throws IOException
in - the input streamout - the output stream (null if writing is not required)IOExceptionpublic static long copy(InputStream in, OutputStream out) throws IOException
in - the input streamout - the output stream (null if writing is not required)IOExceptionpublic static long copy(InputStream in, OutputStream out, long length) throws IOException
in - the input streamout - the output stream (null if writing is not required)length - the maximum number of bytes to copyIOExceptionpublic static long copyAndCloseInput(Reader in, Writer out, long length) throws IOException
in - the readerout - the writer (null if writing is not required)length - the maximum number of bytes to copyIOExceptionpublic static void closeSilently(InputStream in)
in - the input stream or nullpublic static void closeSilently(Reader reader)
reader - the reader or nullpublic static void closeSilently(Writer writer)
writer - the writer or nullpublic static byte[] readBytesAndClose(InputStream in, int length) throws IOException
in - the input streamlength - the maximum number of bytes to read, or -1 to read until
the end of fileIOExceptionpublic static String readStringAndClose(Reader in, int length) throws IOException
in - the readerlength - the maximum number of characters to read, or -1 to read
until the end of fileIOExceptionpublic static int readFully(InputStream in, byte[] buffer, int off, int max) throws IOException
in - the input streambuffer - the output bufferoff - the offset in the buffermax - the number of bytes to read at mostIOExceptionpublic static int readFully(Reader in, char[] buffer, int max) throws IOException
in - the readerbuffer - the output buffermax - the number of characters to read at mostIOExceptionpublic static Reader getBufferedReader(InputStream in)
in - the input stream or nullpublic static Reader getReader(InputStream in)
in - the input stream or nullpublic static Writer getBufferedWriter(OutputStream out)
out - the output stream or nullpublic static Reader getReaderFromString(String s)
s - the string or nullpublic static Reader getAsciiReader(InputStream in)
in - the input streampublic static void trace(String method, String fileName, Object o)
method - the method from where this method was calledfileName - the file nameo - the object to append to the messagepublic static InputStream getInputStreamFromString(String s)
s - the stringCopyright © 2012 JBoss by Red Hat. All Rights Reserved.