Class IOUtils
- Author:
- theonefx
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic longcopy(InputStream input, OutputStream output, int bufferSize) Copies bytes from anInputStreamto anOutputStreamusing an internal buffer of the given size.static voidcopy(InputStream input, Writer output, Charset inputEncoding) Copies bytes from anInputStreamto chars on aWriterusing the specified character encoding.static intCopies chars from aReaderto aWriter.static longcopyLarge(InputStream input, OutputStream output) Copies bytes from a large (over 2GB)InputStreamto anOutputStream.static longcopyLarge(InputStream input, OutputStream output, byte[] buffer) Copies bytes from a large (over 2GB)InputStreamto anOutputStream.static longCopies chars from a large (over 2GB)Readerto aWriter.static longCopies chars from a large (over 2GB)Readerto aWriter.static StringtoString(InputStream input, Charset encoding) Gets the contents of anInputStreamas a String using the specified character encoding.
-
Field Details
-
EOF
public static final int EOFRepresents the end-of-file (or stream).- Since:
- 2.5 (made public)
- See Also:
-
-
Method Details
-
toString
Gets the contents of anInputStreamas a String using the specified character encoding.This method buffers the input internally, so there is no need to use a
BufferedInputStream.- Parameters:
input- theInputStreamto read fromencoding- the encoding to use, null means platform default- Returns:
- the requested String
- Throws:
NullPointerException- if the input is nullIOException- if an I/O error occurs- Since:
- 2.3
-
copy
Copies chars from aReaderto aWriter.This method buffers the input internally, so there is no need to use a
BufferedReader.Large streams (over 2GB) will return a chars copied value of
-1after the copy has completed since the correct number of chars cannot be returned as an int. For large streams use thecopyLarge(Reader, Writer)method.- Parameters:
input- theReaderto read fromoutput- theWriterto write to- Returns:
- the number of characters copied, or -1 if > Integer.MAX_VALUE
- Throws:
NullPointerException- if the input or output is nullIOException- if an I/O error occurs- Since:
- 1.1
-
copy
Copies bytes from anInputStreamto chars on aWriterusing the specified character encoding.This method buffers the input internally, so there is no need to use a
BufferedInputStream.This method uses
InputStreamReader.- Parameters:
input- theInputStreamto read fromoutput- theWriterto write toinputEncoding- the encoding to use for the input stream, null means platform default- Throws:
NullPointerException- if the input or output is nullIOException- if an I/O error occurs- Since:
- 2.3
-
copy
Copies bytes from anInputStreamto anOutputStreamusing an internal buffer of the given size.This method buffers the input internally, so there is no need to use a
BufferedInputStream.- Parameters:
input- theInputStreamto read fromoutput- theOutputStreamto write tobufferSize- the bufferSize used to copy from the input to the output- Returns:
- the number of bytes copied
- Throws:
NullPointerException- if the input or output is nullIOException- if an I/O error occurs- Since:
- 2.5
-
copyLarge
Copies chars from a large (over 2GB)Readerto aWriter.This method buffers the input internally, so there is no need to use a
BufferedReader.The buffer size is given by
DEFAULT_BUFFER_SIZE.- Parameters:
input- theReaderto read fromoutput- theWriterto write to- Returns:
- the number of characters copied
- Throws:
NullPointerException- if the input or output is nullIOException- if an I/O error occurs- Since:
- 1.3
-
copyLarge
Copies chars from a large (over 2GB)Readerto aWriter.This method uses the provided buffer, so there is no need to use a
BufferedReader.- Parameters:
input- theReaderto read fromoutput- theWriterto write tobuffer- the buffer to be used for the copy- Returns:
- the number of characters copied
- Throws:
NullPointerException- if the input or output is nullIOException- if an I/O error occurs- Since:
- 2.2
-
copyLarge
Copies bytes from a large (over 2GB)InputStreamto anOutputStream.This method buffers the input internally, so there is no need to use a
BufferedInputStream.The buffer size is given by
DEFAULT_BUFFER_SIZE.- Parameters:
input- theInputStreamto read fromoutput- theOutputStreamto write to- Returns:
- the number of bytes copied
- Throws:
NullPointerException- if the input or output is nullIOException- if an I/O error occurs- Since:
- 1.3
-
copyLarge
public static long copyLarge(InputStream input, OutputStream output, byte[] buffer) throws IOException Copies bytes from a large (over 2GB)InputStreamto anOutputStream.This method uses the provided buffer, so there is no need to use a
BufferedInputStream.- Parameters:
input- theInputStreamto read fromoutput- theOutputStreamto write tobuffer- the buffer to use for the copy- Returns:
- the number of bytes copied
- Throws:
NullPointerException- if the input or output is nullIOException- if an I/O error occurs- Since:
- 2.2
-