-
public final class IOUtilsUtility functions
-
-
Method Summary
Modifier and Type Method Description static voidcloseQuietly(Closeable c)Closes the given Closeable and swallows any IOException that may occur. static longcopy(InputStream input, OutputStream output)Copies the content of a InputStream into an OutputStream.Uses a default buffer size of 8024 bytes. static longcopy(InputStream input, OutputStream output, int buffersize)Copies the content of a InputStream into an OutputStream static longcopyRange(InputStream input, long len, OutputStream output)Copies part of the content of a InputStream into an OutputStream.Uses a default buffer size of 8024 bytes. static longcopyRange(InputStream input, long len, OutputStream output, int buffersize)Copies part of the content of a InputStream into an OutputStream static intreadFully(InputStream input, Array<byte> array)Reads as much from input as possible to fill the given array. static intreadFully(InputStream input, Array<byte> array, int offset, int len)Reads as much from input as possible to fill the given arraywith the given amount of bytes. static voidreadFully(ReadableByteChannel channel, ByteBuffer byteBuffer)Reads {@code b.remaining()}bytes from the given channelstarting at the current channel's position.static Array<byte>readRange(InputStream input, int len)Gets part of the contents of an {@code InputStream}as a{@code byte[]}.static Array<byte>readRange(ReadableByteChannel input, int len)Gets part of the contents of an {@code ReadableByteChannel}as a{@code byte[]}.static longskip(InputStream input, long numToSkip)Skips the given number of bytes by repeatedly invoking skip onthe given input stream if necessary. static Array<byte>toByteArray(InputStream input)Gets the contents of an {@code InputStream}as a{@code byte[]}.-
-
Method Detail
-
closeQuietly
static void closeQuietly(Closeable c)
Closes the given Closeable and swallows any IOException that may occur.
- Parameters:
c- Closeable to close, can be null
-
copy
static long copy(InputStream input, OutputStream output)
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
-
copy
static long copy(InputStream input, OutputStream output, int buffersize)
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
-
copyRange
static long copyRange(InputStream input, long len, OutputStream output)
Copies part of the content of a InputStream into an OutputStream.Uses a default buffer size of 8024 bytes.
- Parameters:
input- the InputStream to copylen- maximum amount of bytes to copyoutput- the target Stream
-
copyRange
static long copyRange(InputStream input, long len, OutputStream output, int buffersize)
Copies part of the content of a InputStream into an OutputStream
- Parameters:
input- the InputStream to copylen- 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
-
readFully
static int readFully(InputStream input, Array<byte> array)
Reads as much from input as possible to fill the given array.
This method may invoke read repeatedly to fill the array andonly read less bytes than the length of the array if the end ofthe stream has been reached.
- Parameters:
input- stream to read fromarray- buffer to fill
-
readFully
static int readFully(InputStream input, Array<byte> array, int offset, int len)
Reads as much from input as possible to fill the given arraywith the given amount of bytes.
This method may invoke read repeatedly to read the bytes andonly read less bytes than the requested length if the end ofthe stream has been reached.
- Parameters:
input- stream to read fromarray- buffer to filloffset- offset into the buffer to start filling atlen- of bytes to read
-
readFully
static void readFully(ReadableByteChannel channel, ByteBuffer byteBuffer)
Reads
{@code b.remaining()}bytes from the given channelstarting at the current channel's position.This method reads repeatedly from the channel until therequested number of bytes are read. This method blocks untilthe requested number of bytes are read, the end of the channelis detected, or an exception is thrown.
- Parameters:
channel- the channel to read frombyteBuffer- the buffer into which the data is read.
-
readRange
static Array<byte> readRange(InputStream input, int len)
Gets part of the contents of an
{@code InputStream}as a{@code byte[]}.- Parameters:
input- the{@code InputStream}to read fromlen- maximum amount of bytes to copy
-
readRange
static Array<byte> readRange(ReadableByteChannel input, int len)
Gets part of the contents of an
{@code ReadableByteChannel}as a{@code byte[]}.- Parameters:
input- the{@code ReadableByteChannel}to read fromlen- maximum amount of bytes to copy
-
skip
static long skip(InputStream input, long numToSkip)
Skips the given number of bytes by repeatedly invoking skip onthe given input stream if necessary.
In a case where the stream's skip() method returns 0 beforethe requested number of bytes has been skip this implementationwill fall back to using the read() method.
This method will only skip less than the requested number ofbytes if the end of the input stream has been reached.
- Parameters:
input- stream to skip bytes innumToSkip- the number of bytes to skip
-
toByteArray
static Array<byte> toByteArray(InputStream input)
Gets the contents of an
{@code InputStream}as a{@code byte[]}.This method buffers the input internally, so there is no need to use a
{@code BufferedInputStream}.- Parameters:
input- the{@code InputStream}to read from
-
-
-
-