public final class IOUtils extends Object
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BUFFER_SIZE |
Constructor and Description |
---|
IOUtils() |
Modifier and Type | Method and Description |
---|---|
static byte[] |
byteArray()
Returns a new byte array of size
DEFAULT_BUFFER_SIZE . |
static byte[] |
byteArray(int size)
Returns a new byte array of the given size.
|
static long |
skip(InputStream input,
long toSkip)
Skips bytes from an input byte stream.
|
static void |
skipFully(InputStream input,
long toSkip)
Skips the requested number of bytes or fail if there are not enough left.
|
public static final int DEFAULT_BUFFER_SIZE
public static byte[] byteArray()
DEFAULT_BUFFER_SIZE
.DEFAULT_BUFFER_SIZE
.public static byte[] byteArray(int size)
size
- array size.public static void skipFully(InputStream input, long toSkip) throws IOException
This allows for the possibility that InputStream.skip(long)
may
not skip as many bytes as requested (most likely because of reaching EOF).
Note that the implementation uses skip(InputStream, long)
.
This means that the method may be considerably less efficient than using the actual skip implementation,
this is done to guarantee that the correct number of characters are skipped.
input
- stream to skiptoSkip
- the number of bytes to skipIOException
- if there is a problem reading the fileIllegalArgumentException
- if toSkip is negativeEOFException
- if the number of bytes skipped was incorrectInputStream.skip(long)
public static long skip(InputStream input, long toSkip) throws IOException
InputStream
.
Note that the implementation uses InputStream.read(byte[], int, int)
rather
than delegating to InputStream.skip(long)
.
This means that the method may be considerably less efficient than using the actual skip implementation,
this is done to guarantee that the correct number of bytes are skipped.
input
- byte stream to skiptoSkip
- number of bytes to skip.IOException
- if there is a problem reading the fileIllegalArgumentException
- if toSkip is negativeCopyright © 2013–2023 The Apache Software Foundation. All rights reserved.