Package it.unimi.dsi.fastutil.io
Class FastMultiByteArrayInputStream
java.lang.Object
java.io.InputStream
it.unimi.dsi.fastutil.io.MeasurableInputStream
it.unimi.dsi.fastutil.io.FastMultiByteArrayInputStream
- All Implemented Interfaces:
MeasurableStream,RepositionableStream,java.io.Closeable,java.lang.AutoCloseable
public class FastMultiByteArrayInputStream extends MeasurableInputStream implements RepositionableStream
Simple, fast and repositionable byte array input stream that multiplexes its content among several arrays.
This class is significantly slower than
FastByteArrayInputStream,
but it can hold 256 PiB of data. The relevant constructor is FastMultiByteArrayInputStream(InputStream, long),
which fetches a stream and loads it into a sequence of byte arrays.- Author:
- Sebastiano Vigna, Paolo Boldi s
-
Field Summary
Fields Modifier and Type Field Description byte[][]arrayThe array of arrays backing the input stream, plus an additionalnullentry.byte[]currentThe current array.longlengthThe number of valid bytes inarray.static intSLICE_BITSThe number of bits of an array slice index.static intSLICE_MASKThe mask to retrieve a slice offset.static intSLICE_SIZEThe maximum length of an array slice. -
Constructor Summary
Constructors Constructor Description FastMultiByteArrayInputStream(byte[] array)Creates a new multi-array input stream using a given array.FastMultiByteArrayInputStream(FastMultiByteArrayInputStream is)Creates a new multi-array input stream sharing the backing arrays of another multi-array input stream.FastMultiByteArrayInputStream(MeasurableInputStream is)Creates a new multi-array input stream loading it from a measurable input stream.FastMultiByteArrayInputStream(java.io.InputStream is, long size)Creates a new multi-array input stream loading it from an input stream. -
Method Summary
Modifier and Type Method Description intavailable()Returns the number of bytes that can be read (or skipped over) from this input stream without blocking.voidclose()NOP.longlength()Returns the overall length of this stream (optional operation).voidmark(int dummy)booleanmarkSupported()longposition()Returns the current stream position.voidposition(long newPosition)Sets the current stream position.intread()intread(byte[] b, int offset, int length)voidreset()longskip(long n)Methods inherited from class java.io.InputStream
nullInputStream, read, readAllBytes, readNBytes, readNBytes, skipNBytes, transferToMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
SLICE_BITS
public static final int SLICE_BITSThe number of bits of an array slice index.- See Also:
- Constant Field Values
-
SLICE_SIZE
public static final int SLICE_SIZEThe maximum length of an array slice.- See Also:
- Constant Field Values
-
SLICE_MASK
public static final int SLICE_MASKThe mask to retrieve a slice offset.- See Also:
- Constant Field Values
-
array
public byte[][] arrayThe array of arrays backing the input stream, plus an additionalnullentry. -
current
public byte[] currentThe current array. -
length
public long lengthThe number of valid bytes inarray.
-
-
Constructor Details
-
FastMultiByteArrayInputStream
Creates a new multi-array input stream loading it from a measurable input stream.- Parameters:
is- the input stream that will fill the array.- Throws:
java.io.IOException
-
FastMultiByteArrayInputStream
public FastMultiByteArrayInputStream(java.io.InputStream is, long size) throws java.io.IOExceptionCreates a new multi-array input stream loading it from an input stream.- Parameters:
is- the input stream that will fill the array.size- the number of bytes to be read fromis.- Throws:
java.io.IOException
-
FastMultiByteArrayInputStream
Creates a new multi-array input stream sharing the backing arrays of another multi-array input stream.- Parameters:
is- the multi-array input stream to replicate.
-
FastMultiByteArrayInputStream
public FastMultiByteArrayInputStream(byte[] array)Creates a new multi-array input stream using a given array.- Parameters:
array- the backing array.
-
-
Method Details
-
available
public int available()Returns the number of bytes that can be read (or skipped over) from this input stream without blocking.Note that this number may be smaller than the number of bytes actually available from the stream if this number exceeds
Integer.MAX_VALUE.- Overrides:
availablein classjava.io.InputStream- Returns:
- the minimum among the number of available bytes and
Integer.MAX_VALUE.
-
skip
public long skip(long n)- Overrides:
skipin classjava.io.InputStream
-
read
public int read()- Specified by:
readin classjava.io.InputStream
-
read
public int read(byte[] b, int offset, int length)- Overrides:
readin classjava.io.InputStream
-
position
public long position()Description copied from interface:RepositionableStreamReturns the current stream 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() throws java.io.IOExceptionDescription 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- Throws:
java.io.IOException
-
close
public void close()NOP.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.InputStream
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classjava.io.InputStream
-
mark
public void mark(int dummy)- Overrides:
markin classjava.io.InputStream
-
reset
public void reset()- Overrides:
resetin classjava.io.InputStream
-