Package com.google.protobuf
Class RopeByteString.RopeInputStream
- java.lang.Object
-
- java.io.InputStream
-
- com.google.protobuf.RopeByteString.RopeInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
- Enclosing class:
- RopeByteString
private class RopeByteString.RopeInputStream extends java.io.InputStreamThis class is theRopeByteStringequivalent forByteArrayInputStream.
-
-
Field Summary
Fields Modifier and Type Field Description private ByteString.LeafByteStringcurrentPieceprivate intcurrentPieceIndexprivate intcurrentPieceOffsetInRopeprivate intcurrentPieceSizeprivate intmarkprivate RopeByteString.PieceIteratorpieceIterator
-
Constructor Summary
Constructors Constructor Description RopeInputStream()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidadvanceIfCurrentPieceFullyRead()Skips to the next piece if we have read all the data in the current piece.intavailable()private intavailableInternal()Computes the number of bytes still available to read.private voidinitialize()Common initialization code used by both the constructor and reset()voidmark(int readAheadLimit)booleanmarkSupported()intread()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)
-
-
-
Field Detail
-
pieceIterator
private RopeByteString.PieceIterator pieceIterator
-
currentPiece
private ByteString.LeafByteString currentPiece
-
currentPieceSize
private int currentPieceSize
-
currentPieceIndex
private int currentPieceIndex
-
currentPieceOffsetInRope
private int currentPieceOffsetInRope
-
mark
private int mark
-
-
Method Detail
-
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 classjava.io.InputStream- Returns:
- -1 if at EOF, otherwise the actual number of bytes read.
-
skip
public long skip(long length)
- Overrides:
skipin classjava.io.InputStream
-
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
public int read() throws java.io.IOException- Specified by:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
available
public int available() throws java.io.IOException- Overrides:
availablein classjava.io.InputStream- Throws:
java.io.IOException
-
markSupported
public boolean markSupported()
- Overrides:
markSupportedin classjava.io.InputStream
-
mark
public void mark(int readAheadLimit)
- Overrides:
markin classjava.io.InputStream
-
reset
public void reset()
- Overrides:
resetin classjava.io.InputStream
-
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.
-
-