Package org.apache.commons.io.input
Class UnsynchronizedByteArrayInputStream
java.lang.Object
java.io.InputStream
org.apache.commons.io.input.UnsynchronizedByteArrayInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
This is an alternative to
ByteArrayInputStream
which removes the synchronization overhead for non-concurrent
access; as such this class is not thread-safe.- Since:
- 2.7
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final byte[]
The underlying data buffer.static final int
The end of stream marker.private final int
End Of Data.private int
The current mark (if any).private int
Current offset in the data buffer. -
Constructor Summary
ConstructorsConstructorDescriptionUnsynchronizedByteArrayInputStream
(byte[] data) Creates a new byte array input stream.UnsynchronizedByteArrayInputStream
(byte[] data, int offset) Creates a new byte array input stream.UnsynchronizedByteArrayInputStream
(byte[] data, int offset, int length) Creates a new byte array input stream. -
Method Summary
Methods inherited from class java.io.InputStream
close, nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
END_OF_STREAM
public static final int END_OF_STREAMThe end of stream marker.- See Also:
-
data
private final byte[] dataThe underlying data buffer. -
eod
private final int eodEnd Of Data. Similar to data.length, i.e. the last readable offset + 1. -
offset
private int offsetCurrent offset in the data buffer. -
markedOffset
private int markedOffsetThe current mark (if any).
-
-
Constructor Details
-
UnsynchronizedByteArrayInputStream
public UnsynchronizedByteArrayInputStream(byte[] data) Creates a new byte array input stream.- Parameters:
data
- the buffer
-
UnsynchronizedByteArrayInputStream
public UnsynchronizedByteArrayInputStream(byte[] data, int offset) Creates a new byte array input stream.- Parameters:
data
- the bufferoffset
- the offset into the buffer- Throws:
IllegalArgumentException
- if the offset is less than zero
-
UnsynchronizedByteArrayInputStream
public UnsynchronizedByteArrayInputStream(byte[] data, int offset, int length) Creates a new byte array input stream.- Parameters:
data
- the bufferoffset
- the offset into the bufferlength
- the length of the buffer- Throws:
IllegalArgumentException
- if the offset or length less than zero
-
-
Method Details
-
available
public int available()- Overrides:
available
in classInputStream
-
read
public int read()- Specified by:
read
in classInputStream
-
read
public int read(byte[] dest) - Overrides:
read
in classInputStream
-
read
public int read(byte[] dest, int off, int len) - Overrides:
read
in classInputStream
-
skip
public long skip(long n) - Overrides:
skip
in classInputStream
-
markSupported
public boolean markSupported()- Overrides:
markSupported
in classInputStream
-
mark
public void mark(int readlimit) - Overrides:
mark
in classInputStream
-
reset
public void reset()- Overrides:
reset
in classInputStream
-