public class RewindableDataInputStreamPlus extends java.io.FilterInputStream implements RewindableDataInput, java.io.Closeable
this#mark()
or this#mark(int)
, up to
maxMemBufferSize
will be cached in memory (heap). If more than
maxMemBufferSize
bytes are read while the stream is marked, the
following bytes are cached on the spillFile
for up to maxDiskBufferSize
.
Please note that successive calls to this#mark()
and this#reset()
will write
sequentially to the same spillFile
until maxDiskBufferSize
is reached.
At this point, if less than maxDiskBufferSize
bytes are currently cached on the
spillFile
, the remaining bytes are written to the beginning of the file,
treating the spillFile
as a circular buffer.
If more than maxMemBufferSize + maxDiskBufferSize
are cached while the stream is marked,
the following this#reset()
invocation will throw a IllegalStateException
.Modifier and Type | Class and Description |
---|---|
protected static class |
RewindableDataInputStreamPlus.RewindableDataInputPlusMark |
DataInputPlus.DataInputStreamPlus
Modifier and Type | Field and Description |
---|---|
protected int |
diskHeadAvailable |
protected int |
diskTailAvailable |
protected int |
memAvailable |
Constructor and Description |
---|
RewindableDataInputStreamPlus(java.io.InputStream in,
int initialMemBufferSize,
int maxMemBufferSize,
java.io.File spillFile,
int maxDiskBufferSize) |
Modifier and Type | Method and Description |
---|---|
int |
available() |
long |
bytesPastMark(DataPosition mark) |
void |
close() |
void |
close(boolean closeUnderlying) |
DataPosition |
mark()
Marks the current position of a stream to return to this position later via the
this#reset(DataPosition) method. |
void |
mark(int readlimit)
Marks the current position of a stream to return to this position
later via the
this#reset() method. |
boolean |
markSupported() |
int |
read() |
int |
read(byte[] b) |
int |
read(byte[] b,
int off,
int len) |
boolean |
readBoolean() |
byte |
readByte() |
char |
readChar() |
double |
readDouble() |
float |
readFloat() |
void |
readFully(byte[] b) |
void |
readFully(byte[] b,
int off,
int len) |
int |
readInt() |
java.lang.String |
readLine() |
long |
readLong() |
short |
readShort() |
int |
readUnsignedByte() |
int |
readUnsignedShort() |
java.lang.String |
readUTF() |
void |
reset() |
void |
reset(DataPosition mark)
Rewinds to the previously marked position via the
this#mark() method. |
long |
skip(long n) |
int |
skipBytes(int n)
Always skips the requested number of bytes, unless EOF is reached
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
readUnsignedVInt, readVInt, skipBytesFully
protected int memAvailable
protected int diskTailAvailable
protected int diskHeadAvailable
public RewindableDataInputStreamPlus(java.io.InputStream in, int initialMemBufferSize, int maxMemBufferSize, java.io.File spillFile, int maxDiskBufferSize)
public DataPosition mark()
this#reset(DataPosition)
method.mark
in interface RewindableDataInput
public void reset(DataPosition mark) throws java.io.IOException
this#mark()
method.reset
in interface RewindableDataInput
mark
- it's not possible to return to a custom position, so this parameter is ignored.java.io.IOException
- if an error ocurs while resettingpublic long bytesPastMark(DataPosition mark)
bytesPastMark
in interface RewindableDataInput
public boolean markSupported()
markSupported
in class java.io.FilterInputStream
public void mark(int readlimit)
this#reset()
method.mark
in class java.io.FilterInputStream
readlimit
- the maximum amount of bytes to cachepublic void reset() throws java.io.IOException
reset
in class java.io.FilterInputStream
java.io.IOException
public int available() throws java.io.IOException
available
in class java.io.FilterInputStream
java.io.IOException
public int read() throws java.io.IOException
read
in class java.io.FilterInputStream
java.io.IOException
public int read(byte[] b, int off, int len) throws java.io.IOException
read
in class java.io.FilterInputStream
java.io.IOException
public int read(byte[] b) throws java.io.IOException
read
in class java.io.FilterInputStream
java.io.IOException
public long skip(long n) throws java.io.IOException
skip
in class java.io.FilterInputStream
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.FilterInputStream
java.io.IOException
public void close(boolean closeUnderlying) throws java.io.IOException
java.io.IOException
public void readFully(byte[] b) throws java.io.IOException
readFully
in interface java.io.DataInput
java.io.IOException
public void readFully(byte[] b, int off, int len) throws java.io.IOException
readFully
in interface java.io.DataInput
java.io.IOException
public int skipBytes(int n) throws java.io.IOException
DataInputPlus
skipBytes
in interface java.io.DataInput
skipBytes
in interface DataInputPlus
n
- number of bytes to skipjava.io.IOException
public boolean readBoolean() throws java.io.IOException
readBoolean
in interface java.io.DataInput
java.io.IOException
public byte readByte() throws java.io.IOException
readByte
in interface java.io.DataInput
java.io.IOException
public int readUnsignedByte() throws java.io.IOException
readUnsignedByte
in interface java.io.DataInput
java.io.IOException
public short readShort() throws java.io.IOException
readShort
in interface java.io.DataInput
java.io.IOException
public int readUnsignedShort() throws java.io.IOException
readUnsignedShort
in interface java.io.DataInput
java.io.IOException
public char readChar() throws java.io.IOException
readChar
in interface java.io.DataInput
java.io.IOException
public int readInt() throws java.io.IOException
readInt
in interface java.io.DataInput
java.io.IOException
public long readLong() throws java.io.IOException
readLong
in interface java.io.DataInput
java.io.IOException
public float readFloat() throws java.io.IOException
readFloat
in interface java.io.DataInput
java.io.IOException
public double readDouble() throws java.io.IOException
readDouble
in interface java.io.DataInput
java.io.IOException
public java.lang.String readLine() throws java.io.IOException
readLine
in interface java.io.DataInput
java.io.IOException
public java.lang.String readUTF() throws java.io.IOException
readUTF
in interface java.io.DataInput
java.io.IOException
Copyright © 2017 The Apache Software Foundation