|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
it.unimi.dsi.fastutil.io.MeasurableInputStream
it.unimi.dsi.io.SegmentedInputStream
public class SegmentedInputStream
Exhibits a single InputStream
as a number of streams divided into reset()
-separated
segments.
An instance of this class wraps a given input stream (usually a replicable one, such as
a FileInputStream
) and exposes its contents as a number of separated input
streams. Each such stream, called a block, is defined by a start and a stop position (gaps
between blocks are possible). Inside each block we can have one or more segments: each
segment is again a separate input stream, but calling reset()
moves
from one segment to the following one, whereas calling close()
moves from a block to the following one.
An instance of this class is enriched with blocks by calling addBlock(long[])
. This
can also be done on-the-fly, while the underlying input stream is being scanned.
Constructor Summary | |
---|---|
SegmentedInputStream(java.io.InputStream in)
Creates a segmented input stream with no markers. |
|
SegmentedInputStream(java.io.InputStream in,
long... delimiter)
Creats a stream with one marker in. |
Method Summary | |
---|---|
void |
addBlock(long... delimiter)
Adds a new block defined by its array of segment delimiters. |
int |
available()
|
void |
close()
Skips to the next block, closing this segmented input stream if there are no more blocks. |
boolean |
hasMoreBlocks()
Checks whether there are more blocks. |
long |
length()
|
void |
nextBlock()
Skips to the first segment of the next block, if any. |
long |
position()
|
int |
read()
|
int |
read(byte[] b,
int off,
int len)
|
void |
reset()
Moves into the next segment of the current block. |
long |
skip(long n)
|
Methods inherited from class java.io.InputStream |
---|
mark, markSupported, read |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SegmentedInputStream(java.io.InputStream in)
in
- the underlying input stream.public SegmentedInputStream(java.io.InputStream in, long... delimiter) throws java.lang.NullPointerException, java.io.IOException, java.lang.IllegalStateException
in
- the underlying input stream.delimiter
- an array of segment delimiters.
java.lang.NullPointerException
java.io.IOException
java.lang.IllegalStateException
Method Detail |
---|
public void nextBlock() throws java.io.IOException
java.io.IOException
public boolean hasMoreBlocks()
public void addBlock(long... delimiter) throws java.lang.IllegalArgumentException, java.io.IOException
The block has length defined by the difference between the last and first delimiter.
This method performs the initial call to nextBlock()
when the first marker
is put in.
delimiter
- a list of segment delimiters.
java.lang.IllegalArgumentException
- if the elements of delimiter
are negative or not increasing.
java.io.IOException
public int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public int read(byte[] b, int off, int len) throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public long skip(long n) throws java.io.IOException
skip
in class java.io.InputStream
java.io.IOException
public int available() throws java.io.IOException
available
in class java.io.InputStream
java.io.IOException
public long length() throws java.io.IOException
length
in class MeasurableInputStream
java.io.IOException
public long position() throws java.io.IOException
position
in class MeasurableInputStream
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in class java.io.InputStream
java.io.IOException
public void reset() throws java.io.IOException
reset
in class java.io.InputStream
java.io.IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |