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.LeafByteStringprivate intprivate intprivate intprivate intprivate RopeByteString.PieceIterator -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidSkips to the next piece if we have read all the data in the current piece.intprivate intComputes the number of bytes still available to read.private voidCommon initialization code used by both the constructor and reset()voidmark(int readAheadLimit) booleanintread()intread(byte[] b, int offset, int length) Reads up tolenbytes of data into arrayb.private intreadSkipInternal(byte[] b, int offset, int length) Internal implementation of read and skip.voidreset()longskip(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 tolenbytes 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:
readin classInputStream- Returns:
- -1 if at EOF, otherwise the actual number of bytes read.
-
skip
public long skip(long length) - Overrides:
skipin classInputStream
-
readSkipInternal
private int readSkipInternal(byte[] b, int offset, int length) Internal implementation of read and skip. If b != null, then read the nextlengthbytes into the bufferbat offsetoffset. If b == null, then skip the nextlengthbytes.This method assumes that all error checking has already happened.
Returns the actual number of bytes read or skipped.
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
available
- Overrides:
availablein classInputStream- Throws:
IOException
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classInputStream
-
mark
public void mark(int readAheadLimit) - Overrides:
markin classInputStream
-
reset
public void reset()- Overrides:
resetin 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.
-