Class IOUtils
- java.lang.Object
-
- org.apache.commons.compress.utils.IOUtils
-
public final class IOUtils extends java.lang.ObjectUtility functions.
-
-
Field Summary
Fields Modifier and Type Field Description static java.nio.file.LinkOption[]EMPTY_LINK_OPTIONSEmpty array of typeLinkOption.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidcloseQuietly(java.io.Closeable c)Deprecated.static voidcopy(java.io.File sourceFile, java.io.OutputStream outputStream)Deprecated.static longcopy(java.io.InputStream input, java.io.OutputStream output)Deprecated.static longcopy(java.io.InputStream input, java.io.OutputStream output, int bufferSize)Deprecated.static longcopyRange(java.io.InputStream input, long len, java.io.OutputStream output)Deprecated.static longcopyRange(java.io.InputStream input, long length, java.io.OutputStream output, int bufferSize)Deprecated.No longer used.static intread(java.io.File file, byte[] array)Deprecated.UseFiles.readAllBytes(java.nio.file.Path).static intreadFully(java.io.InputStream input, byte[] array)Reads as much from input as possible to fill the given array.static intreadFully(java.io.InputStream input, byte[] array, int offset, int length)Reads as much from input as possible to fill the given array with the given amount of bytes.static voidreadFully(java.nio.channels.ReadableByteChannel channel, java.nio.ByteBuffer byteBuffer)Readsb.remaining()bytes from the given channel starting at the current channel's position.static byte[]readRange(java.io.InputStream input, int length)Gets part of the contents of anInputStreamas abyte[].static byte[]readRange(java.nio.channels.ReadableByteChannel input, int length)Gets part of the contents of anReadableByteChannelas abyte[].static longskip(java.io.InputStream input, long toSkip)Skips bytes from an input byte stream.static byte[]toByteArray(java.io.InputStream input)Deprecated.
-
-
-
Method Detail
-
closeQuietly
@Deprecated public static void closeQuietly(java.io.Closeable c)
Deprecated.Closes the given Closeable and swallows any IOException that may occur.- Parameters:
c- Closeable to close, can be null- Since:
- 1.7
-
copy
@Deprecated public static void copy(java.io.File sourceFile, java.io.OutputStream outputStream) throws java.io.IOExceptionDeprecated.Copies the source file to the given output stream.- Parameters:
sourceFile- The file to read.outputStream- The output stream to write.- Throws:
java.io.IOException- if an I/O error occurs when reading or writing.- Since:
- 1.21
-
copy
@Deprecated public static long copy(java.io.InputStream input, java.io.OutputStream output) throws java.io.IOExceptionDeprecated.Copies the content of a InputStream into an OutputStream. Uses a default buffer size of 8024 bytes.- Parameters:
input- the InputStream to copyoutput- the target, may be null to simulate output to dev/null on Linux and NUL on Windows- Returns:
- the number of bytes copied
- Throws:
java.io.IOException- if an error occurs
-
copy
@Deprecated public static long copy(java.io.InputStream input, java.io.OutputStream output, int bufferSize) throws java.io.IOExceptionDeprecated.Copies the content of a InputStream into an OutputStream- Parameters:
input- the InputStream to copyoutput- the target, may be null to simulate output to dev/null on Linux and NUL on WindowsbufferSize- the buffer size to use, must be bigger than 0- Returns:
- the number of bytes copied
- Throws:
java.io.IOException- if an error occursjava.lang.IllegalArgumentException- if bufferSize is smaller than or equal to 0
-
copyRange
@Deprecated public static long copyRange(java.io.InputStream input, long len, java.io.OutputStream output) throws java.io.IOExceptionDeprecated.Copies part of the content of a InputStream into an OutputStream. Uses a default buffer size of 8024 bytes.- Parameters:
input- the InputStream to copyoutput- the target Streamlen- maximum amount of bytes to copy- Returns:
- the number of bytes copied
- Throws:
java.io.IOException- if an error occurs- Since:
- 1.21
-
copyRange
@Deprecated public static long copyRange(java.io.InputStream input, long length, java.io.OutputStream output, int bufferSize) throws java.io.IOExceptionDeprecated.No longer used.Copies part of the content of a InputStream into an OutputStream- Parameters:
input- the InputStream to copylength- maximum amount of bytes to copyoutput- the target, may be null to simulate output to dev/null on Linux and NUL on WindowsbufferSize- the buffer size to use, must be bigger than 0- Returns:
- the number of bytes copied
- Throws:
java.io.IOException- if an error occursjava.lang.IllegalArgumentException- if bufferSize is smaller than or equal to 0- Since:
- 1.21
-
read
@Deprecated public static int read(java.io.File file, byte[] array) throws java.io.IOExceptionDeprecated.UseFiles.readAllBytes(java.nio.file.Path).Reads as much from the file as possible to fill the given array.This method may invoke read repeatedly to fill the array and only read less bytes than the length of the array if the end of the stream has been reached.
- Parameters:
file- file to readarray- buffer to fill- Returns:
- the number of bytes actually read
- Throws:
java.io.IOException- on error- Since:
- 1.20
-
readFully
public static int readFully(java.io.InputStream input, byte[] array) throws java.io.IOExceptionReads as much from input as possible to fill the given array.This method may invoke read repeatedly to fill the array and only read less bytes than the length of the array if the end of the stream has been reached.
- Parameters:
input- stream to read fromarray- buffer to fill- Returns:
- the number of bytes actually read
- Throws:
java.io.IOException- on error
-
readFully
public static int readFully(java.io.InputStream input, byte[] array, int offset, int length) throws java.io.IOExceptionReads as much from input as possible to fill the given array with the given amount of bytes.This method may invoke read repeatedly to read the bytes and only read less bytes than the requested length if the end of the stream has been reached.
- Parameters:
input- stream to read fromarray- buffer to filloffset- offset into the buffer to start filling atlength- of bytes to read- Returns:
- the number of bytes actually read
- Throws:
java.io.IOException- if an I/O error has occurred
-
readFully
public static void readFully(java.nio.channels.ReadableByteChannel channel, java.nio.ByteBuffer byteBuffer) throws java.io.IOExceptionReadsb.remaining()bytes from the given channel starting at the current channel's position.This method reads repeatedly from the channel until the requested number of bytes are read. This method blocks until the requested number of bytes are read, the end of the channel is detected, or an exception is thrown.
- Parameters:
channel- the channel to read frombyteBuffer- the buffer into which the data is read.- Throws:
java.io.IOException- if an I/O error occurs.java.io.EOFException- if the channel reaches the end before reading all the bytes.
-
readRange
public static byte[] readRange(java.io.InputStream input, int length) throws java.io.IOExceptionGets part of the contents of anInputStreamas abyte[].- Parameters:
input- theInputStreamto read fromlength- maximum amount of bytes to copy- Returns:
- the requested byte array
- Throws:
java.lang.NullPointerException- if the input is nulljava.io.IOException- if an I/O error occurs- Since:
- 1.21
-
readRange
public static byte[] readRange(java.nio.channels.ReadableByteChannel input, int length) throws java.io.IOExceptionGets part of the contents of anReadableByteChannelas abyte[].- Parameters:
input- theReadableByteChannelto read fromlength- maximum amount of bytes to copy- Returns:
- the requested byte array
- Throws:
java.lang.NullPointerException- if the input is nulljava.io.IOException- if an I/O error occurs- Since:
- 1.21
-
skip
public static long skip(java.io.InputStream input, long toSkip) throws java.io.IOExceptionSkips bytes from an input byte stream.This method will only skip less than the requested number of bytes if the end of the input stream has been reached.
- Parameters:
input- stream to skip bytes intoSkip- the number of bytes to skip- Returns:
- the number of bytes actually skipped
- Throws:
java.io.IOException- on error
-
toByteArray
@Deprecated public static byte[] toByteArray(java.io.InputStream input) throws java.io.IOExceptionDeprecated.Gets the contents of anInputStreamas abyte[].This method buffers the input internally, so there is no need to use a
BufferedInputStream.- Parameters:
input- theInputStreamto read from- Returns:
- the requested byte array
- Throws:
java.lang.NullPointerException- if the input is nulljava.io.IOException- if an I/O error occurs- Since:
- 1.5
-
-