public abstract class BufferedInput extends InputStream implements ObjectInput
null
.
seek(long)
, skip(long)
, rewind(long)
and other.
All BufferedInput implementations are required to support marking because proper marking plays a vital role in definition and implementation of certain reposition methods.
Modifier and Type | Field and Description |
---|---|
protected byte[] |
buffer |
protected static byte[] |
EMPTY_BYTE_ARRAY |
protected int |
limit |
protected long |
markLimit |
protected long |
markPosition |
protected int |
position |
protected long |
totalPositionBase |
Modifier | Constructor and Description |
---|---|
protected |
BufferedInput()
Creates new instance with empty buffer.
|
Modifier and Type | Method and Description |
---|---|
int |
available() |
protected void |
checkEOB()
Throws
IllegalStateException if expression (position ! |
protected void |
checkRewind(long n)
Throws appropriate exception if rewind for specified distance is impossible.
|
void |
mark(int readLimit)
Marks the current position in this input stream.
|
void |
mark(long readLimit)
Marks the current position in this input stream.
|
boolean |
markSupported()
|
protected void |
needData()
This method is invoked when input methods need more bytes to read data.
|
int |
read() |
int |
read(byte[] b) |
int |
read(byte[] b,
int off,
int len) |
boolean |
readBoolean() |
byte |
readByte() |
byte[] |
readByteArray()
Reads an array of bytes in a compact encapsulation format.
|
char |
readChar() |
int |
readCompactInt()
Reads an
int value in a compact format (see IOUtil ). |
long |
readCompactLong()
Reads a
long value in a compact format (see IOUtil ). |
protected abstract int |
readData()
This method is invoked when input methods need more bytes to read data.
|
double |
readDouble() |
float |
readFloat() |
void |
readFully(byte[] b) |
void |
readFully(byte[] b,
int off,
int len) |
int |
readInt() |
String |
readLine() |
long |
readLong() |
Object |
readObject() |
short |
readShort() |
int |
readUnsignedByte() |
int |
readUnsignedShort() |
String |
readUTF() |
int |
readUTFChar()
Reads Unicode code point in a UTF-8 format.
|
String |
readUTFString()
Reads Unicode string in a UTF-8 format with compact encapsulation (see
IOUtil ). |
void |
reset()
Repositions this stream to the position at the time the
mark(int) method was last called on this input stream. |
abstract void |
rewind(long n)
Rewinds specified number of bytes.
|
void |
seek(long totalPosition)
Repositions this buffered input to specified total position.
|
long |
skip(long n) |
int |
skipBytes(int n) |
protected void |
throwEOFException()
Throws
EOFException when requested by needData() method. |
long |
totalPosition()
Returns total position of this input stream.
|
close
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close
protected static final byte[] EMPTY_BYTE_ARRAY
protected byte[] buffer
protected int position
protected int limit
protected long totalPositionBase
protected long markPosition
protected long markLimit
protected void needData() throws IOException
(position < limit)
is true or throw an exception.
This method may block if needed.
This method is allowed to update buffer, position, limit and totalPositionBase fields as needed.
This method shall throw an EOFException
if the end of stream is reached.
IOException
- if an I/O error occurs or end of stream is reachedprotected abstract int readData() throws IOException
-1
if no bytes can be read because the end of the stream has been reached.
This method may block if needed.
This method is allowed to update buffer, position, limit and totalPositionBase fields as needed.
This method shall never throw an EOFException
.
-1
if there is no more data because the end of the stream has been reachedIOException
- if an I/O error occursprotected void throwEOFException() throws EOFException
EOFException
when requested by needData()
method.
This implementation throws same reused instance with truncated stack trace to avoid garbage.EOFException
protected final void checkEOB()
IllegalStateException
if expression (position != limit)
is true.public final int read() throws IOException
read
in interface ObjectInput
read
in class InputStream
IOException
public final int read(byte[] b) throws IOException
read
in interface ObjectInput
read
in class InputStream
IOException
public int read(byte[] b, int off, int len) throws IOException
read
in interface ObjectInput
read
in class InputStream
IOException
public long skip(long n) throws IOException
skip
in interface ObjectInput
skip
in class InputStream
IOException
public int available() throws IOException
available
in interface ObjectInput
available
in class InputStream
IOException
public final void readFully(byte[] b) throws IOException
readFully
in interface DataInput
IOException
public void readFully(byte[] b, int off, int len) throws IOException
readFully
in interface DataInput
IOException
public final int skipBytes(int n) throws IOException
skipBytes
in interface DataInput
IOException
public final boolean readBoolean() throws IOException
readBoolean
in interface DataInput
IOException
public final byte readByte() throws IOException
readByte
in interface DataInput
IOException
public final int readUnsignedByte() throws IOException
readUnsignedByte
in interface DataInput
IOException
public final short readShort() throws IOException
readShort
in interface DataInput
IOException
public final int readUnsignedShort() throws IOException
readUnsignedShort
in interface DataInput
IOException
public final char readChar() throws IOException
readChar
in interface DataInput
IOException
public final int readInt() throws IOException
readInt
in interface DataInput
IOException
public final long readLong() throws IOException
readLong
in interface DataInput
IOException
public final float readFloat() throws IOException
readFloat
in interface DataInput
IOException
public final double readDouble() throws IOException
readDouble
in interface DataInput
IOException
public final String readLine() throws IOException
readLine
in interface DataInput
IOException
public final String readUTF() throws IOException
readUTF
in interface DataInput
IOException
public final Object readObject() throws IOException
readObject
in interface ObjectInput
IOException
public final int readCompactInt() throws IOException
int
value in a compact format (see IOUtil
).
If actual encoded value does not fit into an int
data type,
then it is truncated to int
value (only lower 32 bits are returned);
the number is read entirely in this case.
Equivalent to IOUtil.readCompactInt(java.io.DataInput)
method.int
value readIOException
- if an I/O error occurspublic final long readCompactLong() throws IOException
long
value in a compact format (see IOUtil
).
Equivalent to IOUtil.readCompactLong(java.io.DataInput)
method.long
value readIOException
- if an I/O error occurspublic final byte[] readByteArray() throws IOException
IOUtil.readByteArray(java.io.DataInput)
method.IOException
- if an I/O error occurspublic final int readUTFChar() throws IOException
IOUtil.readUTFChar(java.io.DataInput)
method.UTFDataFormatException
- if the bytes do not represent a valid UTF-8 encoding of a characterIOException
- if an I/O error occurspublic final String readUTFString() throws IOException
IOUtil
).
Overlong UTF-8 and CESU-8-encoded surrogates are accepted and read without errors.
This method defines length as a number of bytes.
Equivalent to IOUtil.readUTFString(java.io.DataInput)
method.UTFDataFormatException
- if the bytes do not represent a valid UTF-8 encoding of a stringIOException
- if an I/O error occurspublic final long totalPosition()
seek(long)
, skip(long)
, rewind(long)
, reset()
, etc.public final void seek(long totalPosition) throws IOException
rewind(long)
operation
for appropriate distance is performed; the stream has to be properly marked to support this operation.
If specified total position is larger than current total position, then skip(long)
operation
for appropriate distance is performed until requested total position is reached; if end of stream
happens before this operation can be completed then EOFException
is thrown.IllegalArgumentException
- if total position is negativeIllegalStateException
- if this stream is not marked or if attempting to rewind past the marked positionIOException
- if an I/O error occursEOFException
- if end of stream is reachedpublic final boolean markSupported()
mark(int)
and reset()
,
so this method always returns true.markSupported
in class InputStream
public final void mark(int readLimit)
reset()
method repositions this stream at the last marked
position so that subsequent reads re-read the same bytes.
The readlimit
argument tells this input stream to allow
that many bytes to be read before the mark position gets invalidated.
Negative value for readLimit
may be used in order to invalidate the mark.
mark
in class InputStream
public void mark(long readLimit)
reset()
method repositions this stream at the last marked
position so that subsequent reads re-read the same bytes.
The readlimit
argument tells this input stream to allow
that many bytes to be read before the mark position gets invalidated.
Negative value for readLimit
may be used in order to invalidate the mark.
public void reset()
mark(int)
method was last called on this input stream.
The general contract of reset
is:
mark(int)
method has not been called since
the stream was created, or the number of bytes read from the stream
since mark(int)
was last called is larger than the argument
to mark(int)
at that last call, then an
IllegalStateException
will be thrown.
IllegalStateException
is not thrown, then the
stream is reset to a state such that all the bytes read since the
most recent call to mark(int)
(or since the start of the
stream, if mark(int)
has not been called) will be resupplied
to subsequent callers of the read
method, followed by
any bytes that otherwise would have been the next input data as of
the time of the call to reset
. reset
in class InputStream
IllegalStateException
- if this stream is not markedpublic abstract void rewind(long n)
n
- the number of bytes to rewindIllegalStateException
- if this stream is not marked or if attempting to rewind past the marked positionprotected final void checkRewind(long n)
Copyright © 2014 Devexperts. All Rights Reserved.