public class IOUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static void |
closeSilently(java.lang.AutoCloseable out)
Close an AutoCloseable without throwing an exception.
|
static void |
closeSilently(java.io.Closeable out)
Close a Closeable without throwing an exception.
|
static void |
closeSilently(java.io.InputStream in)
Close an input stream without throwing an exception.
|
static void |
closeSilently(java.io.Reader reader)
Close a reader without throwing an exception.
|
static void |
closeSilently(java.io.Writer writer)
Close a writer without throwing an exception.
|
static long |
copy(java.io.InputStream in,
java.io.OutputStream out)
Copy all data from the input stream to the output stream.
|
static long |
copy(java.io.InputStream in,
java.io.OutputStream out,
long length)
Copy all data from the input stream to the output stream.
|
static long |
copyAndClose(java.io.InputStream in,
java.io.OutputStream out)
Copy all data from the input stream to the output stream and close both
streams.
|
static long |
copyAndCloseInput(java.io.InputStream in,
java.io.OutputStream out)
Copy all data from the input stream to the output stream and close the
input stream.
|
static long |
copyAndCloseInput(java.io.Reader in,
java.io.Writer out,
long length)
Copy all data from the reader to the writer and close the reader.
|
static void |
copyFiles(java.lang.String original,
java.lang.String copy)
Copy a file from one directory to another, or to another file.
|
static java.io.Reader |
getAsciiReader(java.io.InputStream in)
Wrap an input stream in a reader.
|
static java.io.Reader |
getBufferedReader(java.io.InputStream in)
Create a buffered reader to read from an input stream using the UTF-8
format.
|
static java.io.Writer |
getBufferedWriter(java.io.OutputStream out)
Create a buffered writer to write to an output stream using the UTF-8
format.
|
static java.io.InputStream |
getInputStreamFromString(java.lang.String s)
Create an input stream to read from a string.
|
static java.io.Reader |
getReader(java.io.InputStream in)
Create a reader to read from an input stream using the UTF-8 format.
|
static byte[] |
readBytesAndClose(java.io.InputStream in,
int length)
Read a number of bytes from an input stream and close the stream.
|
static int |
readFully(java.io.InputStream in,
byte[] buffer,
int max)
Try to read the given number of bytes to the buffer.
|
static int |
readFully(java.io.Reader in,
char[] buffer,
int max)
Try to read the given number of characters to the buffer.
|
static java.lang.String |
readStringAndClose(java.io.Reader in,
int length)
Read a number of characters from a reader and close it.
|
static void |
skipFully(java.io.InputStream in,
long skip)
Skip a number of bytes in an input stream.
|
static void |
skipFully(java.io.Reader reader,
long skip)
Skip a number of characters in a reader.
|
static void |
trace(java.lang.String method,
java.lang.String fileName,
java.lang.Object o)
Trace input or output operations if enabled.
|
public static void closeSilently(java.io.Closeable out)
out - the Closeable or nullpublic static void closeSilently(java.lang.AutoCloseable out)
out - the AutoCloseable or nullpublic static void skipFully(java.io.InputStream in,
long skip)
throws java.io.IOException
in - the input streamskip - the number of bytes to skipjava.io.EOFException - if the end of file has been reached before all bytes
could be skippedjava.io.IOException - if an IO exception occurred while skippingpublic static void skipFully(java.io.Reader reader,
long skip)
throws java.io.IOException
reader - the readerskip - the number of characters to skipjava.io.EOFException - if the end of file has been reached before all
characters could be skippedjava.io.IOException - if an IO exception occurred while skippingpublic static long copyAndClose(java.io.InputStream in,
java.io.OutputStream out)
throws java.io.IOException
in - the input streamout - the output streamjava.io.IOExceptionpublic static long copyAndCloseInput(java.io.InputStream in,
java.io.OutputStream out)
throws java.io.IOException
in - the input streamout - the output stream (null if writing is not required)java.io.IOExceptionpublic static long copy(java.io.InputStream in,
java.io.OutputStream out)
throws java.io.IOException
in - the input streamout - the output stream (null if writing is not required)java.io.IOExceptionpublic static long copy(java.io.InputStream in,
java.io.OutputStream out,
long length)
throws java.io.IOException
in - the input streamout - the output stream (null if writing is not required)length - the maximum number of bytes to copyjava.io.IOExceptionpublic static long copyAndCloseInput(java.io.Reader in,
java.io.Writer out,
long length)
throws java.io.IOException
in - the readerout - the writer (null if writing is not required)length - the maximum number of bytes to copyjava.io.IOExceptionpublic static void closeSilently(java.io.InputStream in)
in - the input stream or nullpublic static void closeSilently(java.io.Reader reader)
reader - the reader or nullpublic static void closeSilently(java.io.Writer writer)
writer - the writer or nullpublic static byte[] readBytesAndClose(java.io.InputStream in,
int length)
throws java.io.IOException
in - the input streamlength - the maximum number of bytes to read, or -1 to read until
the end of filejava.io.IOExceptionpublic static java.lang.String readStringAndClose(java.io.Reader in,
int length)
throws java.io.IOException
in - the readerlength - the maximum number of characters to read, or -1 to read
until the end of filejava.io.IOExceptionpublic static int readFully(java.io.InputStream in,
byte[] buffer,
int max)
throws java.io.IOException
in - the input streambuffer - the output buffermax - the number of bytes to read at mostjava.io.IOExceptionpublic static int readFully(java.io.Reader in,
char[] buffer,
int max)
throws java.io.IOException
in - the readerbuffer - the output buffermax - the number of characters to read at mostjava.io.IOExceptionpublic static java.io.Reader getBufferedReader(java.io.InputStream in)
in - the input stream or nullpublic static java.io.Reader getReader(java.io.InputStream in)
in - the input stream or nullpublic static java.io.Writer getBufferedWriter(java.io.OutputStream out)
out - the output stream or nullpublic static java.io.Reader getAsciiReader(java.io.InputStream in)
in - the input streampublic static void trace(java.lang.String method,
java.lang.String fileName,
java.lang.Object o)
method - the method from where this method was calledfileName - the file nameo - the object to append to the messagepublic static java.io.InputStream getInputStreamFromString(java.lang.String s)
s - the stringpublic static void copyFiles(java.lang.String original,
java.lang.String copy)
throws java.io.IOException
original - the original file namecopy - the file name of the copyjava.io.IOException