Package jodd.io
Class IOUtil
- java.lang.Object
-
- jodd.io.IOUtil
-
public class IOUtil extends java.lang.ObjectOptimized byte and character stream utilities.
-
-
Field Summary
Fields Modifier and Type Field Description static intioBufferSizeBuffer size for various I/O operations.
-
Constructor Summary
Constructors Constructor Description IOUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclose(java.io.Closeable closeable)Closes silently the closable object.static booleancompare(java.io.InputStream input1, java.io.InputStream input2)Compares the content of two byte streams (InputStreams).static booleancompare(java.io.Reader input1, java.io.Reader input2)Compares the content of two character streams (Readers).static java.io.CharArrayWritercopy(java.io.InputStream input)static java.io.CharArrayWritercopy(java.io.InputStream input, int count)static intcopy(java.io.InputStream input, java.io.OutputStream output)Copies bytes fromInputStreamtoOutputStreamusing buffer.static intcopy(java.io.InputStream input, java.io.OutputStream output, int count)Copies specified number of bytes fromInputStreamtoOutputStreamusing buffer.static java.io.CharArrayWritercopy(java.io.InputStream input, java.nio.charset.Charset encoding)static java.io.CharArrayWritercopy(java.io.InputStream input, java.nio.charset.Charset encoding, int count)CopiesInputStreamto a newCharArrayWriterusing buffer and specified encoding.static <T extends java.io.Writer>
Tcopy(java.io.InputStream input, T output)static <T extends java.io.Writer>
Tcopy(java.io.InputStream input, T output, int count)static <T extends java.io.Writer>
Tcopy(java.io.InputStream input, T output, java.nio.charset.Charset encoding)static <T extends java.io.Writer>
Tcopy(java.io.InputStream input, T output, java.nio.charset.Charset encoding, int count)CopiesInputStreamtoWriterusing buffer and specified encoding.static java.io.CharArrayWritercopy(java.io.Reader input)static java.io.CharArrayWritercopy(java.io.Reader input, int count)CopiesReaderto a newCharArrayWriterusing buffer and specified encoding.static intcopy(java.io.Reader input, java.io.Writer output)Copies bytes fromReadertoWriterusing buffer.static intcopy(java.io.Reader input, java.io.Writer output, int count)Copies specified number of characters fromReadertoWriterusing buffer.static <T extends java.io.OutputStream>
Tcopy(java.io.Reader input, T output)static <T extends java.io.OutputStream>
Tcopy(java.io.Reader input, T output, int count)static <T extends java.io.OutputStream>
Tcopy(java.io.Reader input, T output, java.nio.charset.Charset encoding)static <T extends java.io.OutputStream>
Tcopy(java.io.Reader input, T output, java.nio.charset.Charset encoding, int count)CopiesReadertoOutputStreamusing buffer and specified encoding.static java.io.ByteArrayOutputStreamcopyToOutputStream(java.io.InputStream input)static java.io.ByteArrayOutputStreamcopyToOutputStream(java.io.InputStream input, int count)CopiesInputStreamto a newByteArrayOutputStreamusing buffer and specified encoding.static java.io.ByteArrayOutputStreamcopyToOutputStream(java.io.Reader input)static java.io.ByteArrayOutputStreamcopyToOutputStream(java.io.Reader input, int count)static java.io.ByteArrayOutputStreamcopyToOutputStream(java.io.Reader input, java.nio.charset.Charset encoding)static java.io.ByteArrayOutputStreamcopyToOutputStream(java.io.Reader input, java.nio.charset.Charset encoding, int count)CopiesReaderto a newByteArrayOutputStreamusing buffer and specified encoding.static java.io.InputStreamReaderinputStreamReadeOf(java.io.InputStream input)static java.io.InputStreamReaderinputStreamReadeOf(java.io.InputStream input, java.nio.charset.Charset encoding)Returns newInputStreamReaderusing specifiedInputStreamand encoding.static java.io.OutputStreamWriteroutputStreamWriterOf(java.io.OutputStream output)static java.io.OutputStreamWriteroutputStreamWriterOf(java.io.OutputStream output, java.nio.charset.Charset encoding)Returns newOutputStreamWriterusing specifiedOutputStreamand encoding.static byte[]readAvailableBytes(java.io.InputStream input)Reads all available bytes fromInputStreamas a byte array.static byte[]readBytes(java.io.InputStream input)static byte[]readBytes(java.io.InputStream input, int count)static byte[]readBytes(java.io.Reader input)static byte[]readBytes(java.io.Reader input, int count)static byte[]readBytes(java.io.Reader input, java.nio.charset.Charset encoding)static byte[]readBytes(java.io.Reader input, java.nio.charset.Charset encoding, int count)static char[]readChars(java.io.InputStream input)static char[]readChars(java.io.InputStream input, int count)static char[]readChars(java.io.InputStream input, java.nio.charset.Charset encoding)static char[]readChars(java.io.InputStream input, java.nio.charset.Charset encoding, int count)static char[]readChars(java.io.Reader input)static char[]readChars(java.io.Reader input, int count)
-
-
-
Method Detail
-
close
public static void close(java.io.Closeable closeable)
Closes silently the closable object. If it isFlushable, it will be flushed first. No exception will be thrown if an I/O error occurs.
-
copy
public static int copy(java.io.Reader input, java.io.Writer output) throws java.io.IOExceptionCopies bytes fromReadertoWriterusing buffer.ReaderandWriterdon't have to be wrapped to buffered, since copying is already optimized.- Parameters:
input-Readerto read.output-Writerto write to.- Returns:
- The total number of characters read.
- Throws:
java.io.IOException- if there is an error reading or writing.
-
copy
public static int copy(java.io.InputStream input, java.io.OutputStream output) throws java.io.IOExceptionCopies bytes fromInputStreamtoOutputStreamusing buffer.InputStreamandOutputStreamdon't have to be wrapped to buffered, since copying is already optimized.- Parameters:
input-InputStreamto read.output-OutputStreamto write to.- Returns:
- The total number of bytes read.
- Throws:
java.io.IOException- if there is an error reading or writing.
-
copy
public static int copy(java.io.Reader input, java.io.Writer output, int count) throws java.io.IOExceptionCopies specified number of characters fromReadertoWriterusing buffer.ReaderandWriterdon't have to be wrapped to buffered, since copying is already optimized.- Parameters:
input-Readerto read.output-Writerto write to.count- The number of characters to read.- Returns:
- The total number of characters read.
- Throws:
java.io.IOException- if there is an error reading or writing.
-
copy
public static int copy(java.io.InputStream input, java.io.OutputStream output, int count) throws java.io.IOExceptionCopies specified number of bytes fromInputStreamtoOutputStreamusing buffer.InputStreamandOutputStreamdon't have to be wrapped to buffered, since copying is already optimized.- Parameters:
input-InputStreamto read.output-OutputStreamto write to.count- The number of bytes to read.- Returns:
- The total number of bytes read.
- Throws:
java.io.IOException- if there is an error reading or writing.
-
readAvailableBytes
public static byte[] readAvailableBytes(java.io.InputStream input) throws java.io.IOExceptionReads all available bytes fromInputStreamas a byte array. UsesInputStream.available()to determine the size of input stream. This is the fastest method for readingInputStreamto byte array, but depends onInputStreamimplementation ofInputStream.available().- Parameters:
input-InputStreamto read.- Returns:
- byte[]
- Throws:
java.io.IOException- if total read is less thanInputStream.available();
-
copy
public static <T extends java.io.OutputStream> T copy(java.io.Reader input, T output) throws java.io.IOException- Throws:
java.io.IOException- See Also:
copy(Reader, OutputStream, Charset)
-
copy
public static <T extends java.io.OutputStream> T copy(java.io.Reader input, T output, int count) throws java.io.IOException- Throws:
java.io.IOException- See Also:
copy(Reader, OutputStream, Charset, int)
-
copy
public static <T extends java.io.OutputStream> T copy(java.io.Reader input, T output, java.nio.charset.Charset encoding) throws java.io.IOException- Throws:
java.io.IOException- See Also:
copy(Reader, OutputStream, Charset, int)
-
copy
public static <T extends java.io.OutputStream> T copy(java.io.Reader input, T output, java.nio.charset.Charset encoding, int count) throws java.io.IOExceptionCopiesReadertoOutputStreamusing buffer and specified encoding.- Throws:
java.io.IOException- See Also:
copy(Reader, Writer, int)
-
copyToOutputStream
public static java.io.ByteArrayOutputStream copyToOutputStream(java.io.InputStream input) throws java.io.IOException- Throws:
java.io.IOException- See Also:
copyToOutputStream(InputStream, int)
-
copyToOutputStream
public static java.io.ByteArrayOutputStream copyToOutputStream(java.io.InputStream input, int count) throws java.io.IOExceptionCopiesInputStreamto a newByteArrayOutputStreamusing buffer and specified encoding.- Throws:
java.io.IOException- See Also:
copy(InputStream, OutputStream, int)
-
copyToOutputStream
public static java.io.ByteArrayOutputStream copyToOutputStream(java.io.Reader input) throws java.io.IOException- Throws:
java.io.IOException- See Also:
copyToOutputStream(Reader, Charset)
-
copyToOutputStream
public static java.io.ByteArrayOutputStream copyToOutputStream(java.io.Reader input, java.nio.charset.Charset encoding) throws java.io.IOException- Throws:
java.io.IOException- See Also:
copyToOutputStream(Reader, Charset, int)
-
copyToOutputStream
public static java.io.ByteArrayOutputStream copyToOutputStream(java.io.Reader input, int count) throws java.io.IOException- Throws:
java.io.IOException- See Also:
copyToOutputStream(Reader, Charset, int)
-
copyToOutputStream
public static java.io.ByteArrayOutputStream copyToOutputStream(java.io.Reader input, java.nio.charset.Charset encoding, int count) throws java.io.IOExceptionCopiesReaderto a newByteArrayOutputStreamusing buffer and specified encoding.- Throws:
java.io.IOException- See Also:
copy(Reader, OutputStream, Charset, int)
-
copy
public static <T extends java.io.Writer> T copy(java.io.InputStream input, T output) throws java.io.IOException- Throws:
java.io.IOException- See Also:
copy(InputStream, Writer, Charset)
-
copy
public static <T extends java.io.Writer> T copy(java.io.InputStream input, T output, int count) throws java.io.IOException- Throws:
java.io.IOException- See Also:
copy(InputStream, Writer, Charset, int)
-
copy
public static <T extends java.io.Writer> T copy(java.io.InputStream input, T output, java.nio.charset.Charset encoding) throws java.io.IOException- Throws:
java.io.IOException- See Also:
copy(InputStream, Writer, Charset, int)
-
copy
public static <T extends java.io.Writer> T copy(java.io.InputStream input, T output, java.nio.charset.Charset encoding, int count) throws java.io.IOExceptionCopiesInputStreamtoWriterusing buffer and specified encoding.- Throws:
java.io.IOException- See Also:
copy(Reader, Writer, int)
-
copy
public static java.io.CharArrayWriter copy(java.io.InputStream input) throws java.io.IOException- Throws:
java.io.IOException- See Also:
copy(InputStream, Charset)
-
copy
public static java.io.CharArrayWriter copy(java.io.InputStream input, int count) throws java.io.IOException- Throws:
java.io.IOException- See Also:
copy(InputStream, Charset, int)
-
copy
public static java.io.CharArrayWriter copy(java.io.InputStream input, java.nio.charset.Charset encoding) throws java.io.IOException- Throws:
java.io.IOException- See Also:
copy(InputStream, Charset, int)
-
copy
public static java.io.CharArrayWriter copy(java.io.InputStream input, java.nio.charset.Charset encoding, int count) throws java.io.IOExceptionCopiesInputStreamto a newCharArrayWriterusing buffer and specified encoding.- Throws:
java.io.IOException- See Also:
copy(InputStream, Writer, Charset, int)
-
copy
public static java.io.CharArrayWriter copy(java.io.Reader input) throws java.io.IOException- Throws:
java.io.IOException- See Also:
copy(Reader, int)
-
copy
public static java.io.CharArrayWriter copy(java.io.Reader input, int count) throws java.io.IOExceptionCopiesReaderto a newCharArrayWriterusing buffer and specified encoding.- Throws:
java.io.IOException- See Also:
copy(Reader, Writer, int)
-
readBytes
public static byte[] readBytes(java.io.InputStream input) throws java.io.IOException- Throws:
java.io.IOException- See Also:
readBytes(InputStream, int)
-
readBytes
public static byte[] readBytes(java.io.InputStream input, int count) throws java.io.IOException- Throws:
java.io.IOException- See Also:
copyToOutputStream(InputStream, int)
-
readBytes
public static byte[] readBytes(java.io.Reader input) throws java.io.IOException- Throws:
java.io.IOException- See Also:
readBytes(Reader, Charset)
-
readBytes
public static byte[] readBytes(java.io.Reader input, int count) throws java.io.IOException- Throws:
java.io.IOException- See Also:
readBytes(Reader, Charset, int)
-
readBytes
public static byte[] readBytes(java.io.Reader input, java.nio.charset.Charset encoding) throws java.io.IOException- Throws:
java.io.IOException- See Also:
readBytes(Reader, Charset, int)
-
readBytes
public static byte[] readBytes(java.io.Reader input, java.nio.charset.Charset encoding, int count) throws java.io.IOException- Throws:
java.io.IOException- See Also:
copyToOutputStream(Reader, Charset, int)
-
readChars
public static char[] readChars(java.io.Reader input) throws java.io.IOException- Throws:
java.io.IOException- See Also:
readChars(Reader, int)
-
readChars
public static char[] readChars(java.io.Reader input, int count) throws java.io.IOException- Throws:
java.io.IOException- See Also:
copy(Reader, int)
-
readChars
public static char[] readChars(java.io.InputStream input) throws java.io.IOException- Throws:
java.io.IOException- See Also:
readChars(InputStream, int)
-
readChars
public static char[] readChars(java.io.InputStream input, java.nio.charset.Charset encoding) throws java.io.IOException- Throws:
java.io.IOException- See Also:
readChars(InputStream, Charset, int)
-
readChars
public static char[] readChars(java.io.InputStream input, int count) throws java.io.IOException- Throws:
java.io.IOException- See Also:
readChars(InputStream, Charset, int)
-
readChars
public static char[] readChars(java.io.InputStream input, java.nio.charset.Charset encoding, int count) throws java.io.IOException- Throws:
java.io.IOException- See Also:
copy(InputStream, Charset, int)
-
compare
public static boolean compare(java.io.InputStream input1, java.io.InputStream input2) throws java.io.IOExceptionCompares the content of two byte streams (InputStreams).- Returns:
trueif the content of the firstInputStreamis equal to the content of the secondInputStream.- Throws:
java.io.IOException
-
compare
public static boolean compare(java.io.Reader input1, java.io.Reader input2) throws java.io.IOExceptionCompares the content of two character streams (Readers).- Returns:
trueif the content of the firstReaderis equal to the content of the secondReader.- Throws:
java.io.IOException
-
inputStreamReadeOf
public static java.io.InputStreamReader inputStreamReadeOf(java.io.InputStream input)
- See Also:
inputStreamReadeOf(InputStream, Charset)
-
inputStreamReadeOf
public static java.io.InputStreamReader inputStreamReadeOf(java.io.InputStream input, java.nio.charset.Charset encoding)Returns newInputStreamReaderusing specifiedInputStreamand encoding.- Parameters:
input-InputStreamencoding- Encoding asStringto use forInputStreamReader.- Returns:
- new
InputStreamReader
-
outputStreamWriterOf
public static java.io.OutputStreamWriter outputStreamWriterOf(java.io.OutputStream output)
-
outputStreamWriterOf
public static java.io.OutputStreamWriter outputStreamWriterOf(java.io.OutputStream output, java.nio.charset.Charset encoding)Returns newOutputStreamWriterusing specifiedOutputStreamand encoding.- Parameters:
output-OutputStreamencoding- Encoding asStringto use forOutputStreamWriter.- Returns:
- new
OutputStreamWriter
-
-