Class 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 the RopeByteString equivalent for ByteArrayInputStream.
    • Field Detail

      • currentPieceSize

        private int currentPieceSize
      • currentPieceIndex

        private int currentPieceIndex
      • currentPieceOffsetInRope

        private int currentPieceOffsetInRope
      • mark

        private int mark
    • Constructor Detail

      • RopeInputStream

        public RopeInputStream()
    • Method Detail

      • 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 java.io.InputStream
        Returns:
        -1 if at EOF, otherwise the actual number of bytes read.
      • skip

        public long skip​(long length)
        Overrides:
        skip in class java.io.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 java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • available

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

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

        public void mark​(int readAheadLimit)
        Overrides:
        mark in class java.io.InputStream
      • reset

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