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.InputStream
This class is theRopeByteString
equivalent forByteArrayInputStream
.
-
-
Field Summary
Fields Modifier and Type Field Description private ByteString.LeafByteString
currentPiece
private int
currentPieceIndex
private int
currentPieceOffsetInRope
private int
currentPieceSize
private int
mark
private RopeByteString.PieceIterator
pieceIterator
-
Constructor Summary
Constructors Constructor Description RopeInputStream()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
advanceIfCurrentPieceFullyRead()
Skips to the next piece if we have read all the data in the current piece.int
available()
private void
initialize()
Common initialization code used by both the constructor and reset()void
mark(int readAheadLimit)
boolean
markSupported()
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)
-
-
-
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 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 classjava.io.InputStream
- Returns:
- -1 if at EOF, otherwise the actual number of bytes read.
-
skip
public long skip(long length)
- Overrides:
skip
in 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 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
public int read() throws java.io.IOException
- Specified by:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
available
public int available() throws java.io.IOException
- Overrides:
available
in classjava.io.InputStream
- Throws:
java.io.IOException
-
markSupported
public boolean markSupported()
- Overrides:
markSupported
in classjava.io.InputStream
-
mark
public void mark(int readAheadLimit)
- Overrides:
mark
in classjava.io.InputStream
-
reset
public void reset()
- Overrides:
reset
in 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.
-
-