Package com.google.protobuf
Class RopeByteString.RopeInputStream
java.lang.Object
java.io.InputStream
com.google.protobuf.RopeByteString.RopeInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Enclosing class:
RopeByteString
This class is the
RopeByteString
equivalent for ByteArrayInputStream
.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ByteString.LeafByteString
private int
private int
private int
private int
private RopeByteString.PieceIterator
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
Skips to the next piece if we have read all the data in the current piece.int
private int
Computes the number of bytes still available to read.private void
Common initialization code used by both the constructor and reset()void
mark
(int readAheadLimit) boolean
int
read()
int
read
(byte[] b, int offset, int length) Reads up tolen
bytes of data into arrayb
.private int
readSkipInternal
(byte[] b, int offset, int length) Internal implementation of read and skip.void
reset()
long
skip
(long length) Methods inherited from class java.io.InputStream
close, nullInputStream, read, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
pieceIterator
-
currentPiece
-
currentPieceSize
private int currentPieceSize -
currentPieceIndex
private int currentPieceIndex -
currentPieceOffsetInRope
private int currentPieceOffsetInRope -
mark
private int mark
-
-
Constructor Details
-
RopeInputStream
public RopeInputStream()
-
-
Method Details
-
read
public int read(byte[] b, int offset, int length) Reads up tolen
bytes of data into arrayb
.Note that
InputStream.read(byte[], int, int)
andByteArrayInputStream.read(byte[], int, int)
behave inconsistently when reading 0 bytes at EOF; the interface defines the return value to be 0 and the latter returns -1. We use the latter behavior so that all ByteString streams are consistent.- Overrides:
read
in classInputStream
- Returns:
- -1 if at EOF, otherwise the actual number of bytes read.
-
skip
public long skip(long length) - Overrides:
skip
in classInputStream
-
readSkipInternal
private int readSkipInternal(byte[] b, int offset, int length) Internal implementation of read and skip. If b != null, then read the nextlength
bytes into the bufferb
at offsetoffset
. If b == null, then skip the nextlength
bytes.This method assumes that all error checking has already happened.
Returns the actual number of bytes read or skipped.
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
available
- Overrides:
available
in classInputStream
- Throws:
IOException
-
markSupported
public boolean markSupported()- Overrides:
markSupported
in classInputStream
-
mark
public void mark(int readAheadLimit) - Overrides:
mark
in classInputStream
-
reset
public void reset()- Overrides:
reset
in classInputStream
-
initialize
private void initialize()Common initialization code used by both the constructor and reset() -
advanceIfCurrentPieceFullyRead
private void advanceIfCurrentPieceFullyRead()Skips to the next piece if we have read all the data in the current piece. Sets currentPiece to null if we have reached the end of the input. -
availableInternal
private int availableInternal()Computes the number of bytes still available to read.
-