| Modifier and Type | Field and Description |
|---|---|
| private static int | BYTE_ARRAY_MAX_OVERRIDE
The current set global allocation limit override, -1 means limits are applied per record type. |
| private static final int | DEFAULT_BUFFER_SIZE
The default size of the bytearray used while reading input streams. |
| private static final Logger | |
| private static int | MAX_BYTE_ARRAY_INIT_SIZE
The max init size of ByteArrayOutputStream. |
| private static final int | SKIP_BUFFER_SIZE
The default buffer size to use for the skip() methods. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv static int | |
| public static long | |
| public static long | |
| private static void | |
| private static void | |
| private static void | |
| public static void | closeQuietly(final Closeable
resource to close closeable)Quietly (no exceptions) close Closable resource. |
| public static long | Returns: the amount of bytes copiedThe inp, OutputStream InputStream which provides the dataThe out)OutputStream to write the data toCopies all the data from the given InputStream to the OutputStream. |
| public static long | Returns: the amount of bytes copiedThe inp, OutputStream InputStream which provides the dataThe out, long OutputStream to write the data tolimit the copied bytes - use limit)-1 for no limitCopies all the data from the given InputStream to the OutputStream. |
| public static long | Returns: the amount of bytes copiedThe srcStream, File InputStream which provides the dataThe file where the data should be stored destFile)Copy the contents of the stream to a new file. |
| public static int | Returns: the max init size of ByteArrayOutputStream. -1 (the default) means init size of ByteArrayOutputStream could be up toInteger#MAX_VALUE
|
| public static byte[] | |
| public static byte[] | |
| public static int | Returns: byte read, unlessinput stream to read is)Simple utility function to check that you haven't hit EOF when reading a byte. |
| public static int | Returns: the number of bytes read or -1 if no bytes were readthe stream from which the data is read. in, byte[] the buffer into which the data is read. b)Helper method, just calls |
| public static int | Returns: the number of bytes read or -1 if no bytes were readthe stream from which the data is read. in, byte[] the buffer into which the data is read. b, int the start offset in array off, int b at which the data is written.the maximum number of bytes to read. len)Same as the normal |
| public static int | Returns: the number of bytes read or -1 if no bytes were readThe byte-channel to read data from channel, ByteBuffer the buffer into which the data is read. b)Same as the normal |
| public static byte[] | |
| public static void | |
| public static byte[] | |
| public static void | setByteArrayMaxOverride(int
The maximum number of bytes that should be possible to be allocated in one step. maxOverride)If this value is set to > 0, |
| public static void | setMaxByteArrayInitSize(final int
the max init size of ByteArrayOutputStream.
-1 (the default) means init size of ByteArrayOutputStream could be up to maxOverride)Integer#MAX_VALUE
|
| public static long | Returns: number of bytes actually skipped.byte stream to skip input, final long number of bytes to skip. toSkip)Skips bytes from an input byte stream. |
| private static void | |
| private static void | |
| public static byte[] | Returns: A byte array with the read bytes.The byte stream of data to read. stream)Reads all the data from the input stream, and returns the bytes read. |
| public static byte[] | Returns: A byte array with the read bytes.The byte stream of data to read. stream, final int The maximum length to read, use length)Integer#MAX_VALUE to read the stream
until EOF.Reads up to |
| public static byte[] | Returns: A byte array with the read bytes.The byte stream of data to read. stream, final int The maximum length to read, use length, final int Integer#MAX_VALUE to read the stream
until EOFif the input is equal to/longer than maxLength)maxLength bytes,
then throw an IOException complaining about the length.
use Integer#MAX_VALUE to disable the check - if setByteArrayMaxOverride(int) is
set then that max of that value and this maxLength is usedReads up to |
| private static byte[] | toByteArray(InputStream stream, final int length, final int maxLength, final boolean checkEOFException, final boolean isLengthKnown)
|
| public static byte[] | toByteArray(ByteBuffer buffer, int length)
Returns an array (that shouldn't be written to!) of the ByteBuffer. |
| public static byte[] | Returns: A byte array with the read bytes.The byte stream of data to read. stream, final int if the input is equal to/longer than maxLength)maxLength bytes,
then throw an IOException complaining about the length.
use Integer#MAX_VALUE to disable the check - if setByteArrayMaxOverride(int) is
set then that max of that value and this maxLength is usedReads the input stream, and returns the bytes read. |
| BYTE_ARRAY_MAX_OVERRIDE | back to summary |
|---|---|
| private static int BYTE_ARRAY_MAX_OVERRIDE The current set global allocation limit override, -1 means limits are applied per record type. | |
| DEFAULT_BUFFER_SIZE | back to summary |
|---|---|
| private static final int DEFAULT_BUFFER_SIZE The default size of the bytearray used while reading input streams. This is meant to be pretty small. | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| MAX_BYTE_ARRAY_INIT_SIZE | back to summary |
|---|---|
| private static int MAX_BYTE_ARRAY_INIT_SIZE The max init size of ByteArrayOutputStream. -1 means init size of ByteArrayOutputStream could be up to Integer.MAX_VALUE | |
| SKIP_BUFFER_SIZE | back to summary |
|---|---|
| private static final int SKIP_BUFFER_SIZE The default buffer size to use for the skip() methods. | |
| IOUtils | back to summary |
|---|---|
| private IOUtils() | |
| calculateByteArrayInitLength | back to summary |
|---|---|
| pack-priv static int calculateByteArrayInitLength(final boolean isLengthKnown, final int length, final int maxLength) | |
| calculateChecksum | back to summary |
|---|---|
| public static long calculateChecksum(byte[] data) Calculate checksum on input data | |
| calculateChecksum | back to summary |
|---|---|
| public static long calculateChecksum(InputStream stream) throws IOException Calculate checksum on all the data read from input stream.
This should be more efficient than the equivalent code
| |
| checkByteSizeLimit | back to summary |
|---|---|
| private static void checkByteSizeLimit(int length) | |
| checkByteSizeLimit | back to summary |
|---|---|
| private static void checkByteSizeLimit(long length) | |
| checkLength | back to summary |
|---|---|
| private static void checkLength(long length, int maxLength) | |
| closeQuietly | back to summary |
|---|---|
| public static void closeQuietly(final Closeable closeable) Quietly (no exceptions) close Closable resource. In case of error it will be printed to IOUtils class logger.
| |
| copy | back to summary |
|---|---|
| public static long copy(InputStream inp, OutputStream out) throws IOException Copies all the data from the given InputStream to the OutputStream. It leaves both streams open, so you will still need to close them once done.
| |
| copy | back to summary |
|---|---|
| public static long copy(InputStream inp, OutputStream out, long limit) throws IOException Copies all the data from the given InputStream to the OutputStream. It leaves both streams open, so you will still need to close them once done.
| |
| copy | back to summary |
|---|---|
| public static long copy(InputStream srcStream, File destFile) throws IOException Copy the contents of the stream to a new file.
| |
| getMaxByteArrayInitSize | back to summary |
|---|---|
public static int getMaxByteArrayInitSize()
| |
| peekFirst8Bytes | back to summary |
|---|---|
| public static byte[] peekFirst8Bytes(InputStream stream) throws IOException, EmptyFileException Peeks at the first 8 bytes of the stream. Returns those bytes, but with the stream unaffected. Requires a stream that supports mark/reset, or a PushbackInputStream. If the stream has >0 but <8 bytes, remaining bytes will be zero.
| |
| peekFirstNBytes | back to summary |
|---|---|
| public static byte[] peekFirstNBytes(InputStream stream, int limit) throws IOException, EmptyFileException Peeks at the first N bytes of the stream. Returns those bytes, but with the stream unaffected. Requires a stream that supports mark/reset, or a PushbackInputStream. If the stream has >0 but <N bytes, remaining bytes will be zero.
| |
| readByte | back to summary |
|---|---|
| public static int readByte(InputStream is) throws IOException Simple utility function to check that you haven't hit EOF when reading a byte.
| |
| readFully | back to summary |
|---|---|
| public static int readFully(InputStream in, byte[] b) throws IOException Helper method, just calls
| |
| readFully | back to summary |
|---|---|
| public static int readFully(InputStream in, byte[] b, int off, int len) throws IOException Same as the normal If the end of file is reached before any bytes are read, returns
| |
| readFully | back to summary |
|---|---|
| public static int readFully(ReadableByteChannel channel, ByteBuffer b) throws IOException Same as the normal If the end of file is reached before any bytes are read, returns -1. If the end of the file is reached after some bytes are read, returns the number of bytes read. If the end of the file isn't reached before the buffer has no more remaining capacity, will return the number of bytes that were read.
| |
| safelyAllocate | back to summary |
|---|---|
| public static byte[] safelyAllocate(long length, int maxLength) | |
| safelyAllocateCheck | back to summary |
|---|---|
| public static void safelyAllocateCheck(long length, int maxLength) | |
| safelyClone | back to summary |
|---|---|
| public static byte[] safelyClone(byte[] src, int offset, int length, int maxLength) | |
| setByteArrayMaxOverride | back to summary |
|---|---|
| public static void setByteArrayMaxOverride(int maxOverride) If this value is set to > 0, Note This is a per-allocation limit and does not allow you to limit the overall sum of allocations! Use -1 for using the limits specified per record-type.
| |
| setMaxByteArrayInitSize | back to summary |
|---|---|
public static void setMaxByteArrayInitSize(final int maxOverride)
| |
| skipFully | back to summary |
|---|---|
| public static long skipFully(final InputStream input, final long toSkip) throws IOException Skips bytes from an input byte stream.
This implementation guarantees that it will read as many bytes
as possible before giving up; this may not always be the case for
skip() implementations in subclasses of
Note that the implementation uses
This mimics POI's Copied nearly verbatim from commons-io 41a3e9c
| |
| throwRecordTruncationException | back to summary |
|---|---|
| private static void throwRecordTruncationException(final int maxLength) | |
| throwRFE | back to summary |
|---|---|
| private static void throwRFE(long length, int maxLength) | |
| toByteArray | back to summary |
|---|---|
| public static byte[] toByteArray(InputStream stream) throws IOException Reads all the data from the input stream, and returns the bytes read.
| |
| toByteArray | back to summary |
|---|---|
| public static byte[] toByteArray(InputStream stream, final int length) throws IOException Reads up to
| |
| toByteArray | back to summary |
|---|---|
| public static byte[] toByteArray(InputStream stream, final int length, final int maxLength) throws IOException Reads up to
| |
| toByteArray | back to summary |
|---|---|
| private static byte[] toByteArray(InputStream stream, final int length, final int maxLength, final boolean checkEOFException, final boolean isLengthKnown) throws IOException | |
| toByteArray | back to summary |
|---|---|
| public static byte[] toByteArray(ByteBuffer buffer, int length) Returns an array (that shouldn't be written to!) of the ByteBuffer. Will be of the requested length, or possibly longer if that's easier. | |
| toByteArrayWithMaxLength | back to summary |
|---|---|
| public static byte[] toByteArrayWithMaxLength(InputStream stream, final int maxLength) throws IOException Reads the input stream, and returns the bytes read.
| |