Class RopeByteString.RopeInputStream

java.lang.Object
java.io.InputStream
com.google.protobuf.RopeByteString.RopeInputStream
All Implemented Interfaces:
Closeable, AutoCloseable
Enclosing class:
RopeByteString

private class RopeByteString.RopeInputStream extends InputStream
This class is the RopeByteString equivalent for ByteArrayInputStream.
  • Field Details

    • 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
  • Constructor Details

    • RopeInputStream

      public RopeInputStream()
  • Method Details

    • read

      public int read(byte[] b, int offset, int length)
      Reads up to len bytes of data into array b.

      Note that InputStream.read(byte[], int, int) and ByteArrayInputStream.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 class InputStream
      Returns:
      -1 if at EOF, otherwise the actual number of bytes read.
    • skip

      public long skip(long length)
      Overrides:
      skip in class InputStream
    • readSkipInternal

      private int readSkipInternal(byte[] b, int offset, int length)
      Internal implementation of read and skip. If b != null, then read the next length bytes into the buffer b at offset offset. If b == null, then skip the next length 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 IOException
      Specified by:
      read in class InputStream
      Throws:
      IOException
    • available

      public int available() throws IOException
      Overrides:
      available in class InputStream
      Throws:
      IOException
    • markSupported

      public boolean markSupported()
      Overrides:
      markSupported in class InputStream
    • mark

      public void mark(int readAheadLimit)
      Overrides:
      mark in class InputStream
    • reset

      public void reset()
      Overrides:
      reset in class 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.