Class FastByteArrayInputStream
java.lang.Object
java.io.InputStream
it.unimi.dsi.fastutil.io.MeasurableInputStream
it.unimi.dsi.fastutil.io.FastByteArrayInputStream
- All Implemented Interfaces:
MeasurableStream,RepositionableStream,Closeable,DataInput,ObjectInput,AutoCloseable
public class FastByteArrayInputStream
extends MeasurableInputStream
implements RepositionableStream, ObjectInput
Simple, fast and repositionable byte-array input stream with built-in
ObjectInput
support.
Warning: this class implements the correct semantics of
read(byte[], int, int) as described in InputStream. The implementation
given in ByteArrayInputStream is broken, but it will never be fixed because it's
too late.
- Author:
- Sebastiano Vigna
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionFastByteArrayInputStream(byte[] array) Creates a new array input stream using a given array.FastByteArrayInputStream(byte[] array, int offset, int length) Creates a new array input stream using a given array fragment. -
Method Summary
Modifier and TypeMethodDescriptionintvoidclose()Closing a fast byte array input stream has no effect.longlength()Returns the overall length of this stream (optional operation).voidmark(int dummy) booleanintpeek()longposition()Returns the current position in this stream (optional operation).voidposition(long newPosition) Sets the current stream position.intread()intread(byte[] b) intread(byte[] b, int offset, int length) Reads bytes from this byte-array input stream as specified inInputStream.read(byte[], int, int).booleanbytereadByte()charreadChar()doublefloatvoidreadFully(byte[] b) voidreadFully(byte[] b, int off, int len) intreadInt()readLine()Deprecated.longreadLong()not efficient!shortintintreadUTF()voidreset()longskip(long n) intskipBytes(int n) Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
array
public byte[] arrayThe array backing the input stream. -
offset
public int offsetThe first valid entry. -
length
-
-
Constructor Details
-
FastByteArrayInputStream
public FastByteArrayInputStream(byte[] array, int offset, int length) Creates a new array input stream using a given array fragment.- Parameters:
array- the backing array.offset- the first valid entry of the array.length- the number of valid bytes.
-
FastByteArrayInputStream
public FastByteArrayInputStream(byte[] array) Creates a new array input stream using a given array.- Parameters:
array- the backing array.
-
-
Method Details
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classInputStream
-
reset
public void reset()- Overrides:
resetin classInputStream
-
close
public void close()Closing a fast byte array input stream has no effect.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceObjectInput- Overrides:
closein classInputStream
-
mark
public void mark(int dummy) - Overrides:
markin classInputStream
-
available
public int available()- Specified by:
availablein interfaceObjectInput- Overrides:
availablein classInputStream
-
skip
public long skip(long n) - Specified by:
skipin interfaceObjectInput- Overrides:
skipin classInputStream
-
read
public int read()- Specified by:
readin interfaceObjectInput- Specified by:
readin classInputStream
-
read
public int read(byte[] b, int offset, int length) Reads bytes from this byte-array input stream as specified inInputStream.read(byte[], int, int). Note that the implementation given inByteArrayInputStream.read(byte[], int, int)will return -1 on a zero-length read at EOF, contrarily to the specification. We won't.- Specified by:
readin interfaceObjectInput- Overrides:
readin classInputStream
-
position
public long position()Description copied from interface:MeasurableStreamReturns the current position in this stream (optional operation).Usually, the position is just the number of bytes read or written since the stream was opened, but in the case of a
RepositionableStreamit represent the current position.- Specified by:
positionin interfaceMeasurableStream- Specified by:
positionin interfaceRepositionableStream- Returns:
- the current stream position.
-
position
public void position(long newPosition) Description copied from interface:RepositionableStreamSets the current stream position.- Specified by:
positionin interfaceRepositionableStream- Parameters:
newPosition- the new stream position.
-
length
public long length()Description copied from interface:MeasurableStreamReturns the overall length of this stream (optional operation). In most cases, this will require the stream to perform some extra action, possibly changing the state of the input stream itself (typically, reading all the bytes up to the end, or flushing on output stream). Implementing classes should always document what state will the input stream be in after calling this method, and which kind of exception could be thrown.- Specified by:
lengthin interfaceMeasurableStream
-
read
public int read(byte[] b) - Specified by:
readin interfaceObjectInput- Overrides:
readin classInputStream
-
peek
public int peek() -
readFully
-
readFully
-
skipBytes
-
readBoolean
public boolean readBoolean()- Specified by:
readBooleanin interfaceDataInput
-
readByte
-
readUnsignedByte
public int readUnsignedByte()- Specified by:
readUnsignedBytein interfaceDataInput
-
readShort
-
readUnsignedShort
public int readUnsignedShort()- Specified by:
readUnsignedShortin interfaceDataInput
-
readChar
-
readInt
-
readLong
-
readFloat
-
readDouble
public double readDouble()- Specified by:
readDoublein interfaceDataInput
-
readLine
-
readUTF
- Specified by:
readUTFin interfaceDataInput- Throws:
UTFDataFormatException
-
readObject
not efficient! Only added to support customExternalizable- Specified by:
readObjectin interfaceObjectInput- Throws:
ClassNotFoundExceptionIOException
-