Class MultiRangeObjectInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    @NotThreadSafe
    public abstract class MultiRangeObjectInputStream
    extends java.io.InputStream
    A stream for reading data using range queries.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean mClosed
      Has the stream been closed.
      protected long mEndPos
      Position the current stream was open till (exclusive).
      protected long mPos
      The current position of the stream.
      protected java.io.InputStream mStream
      The backing input stream.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected MultiRangeObjectInputStream​(long multiRangeChunkSize)
      Creates the input stream that will perform reads with a specified chunk size.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      protected abstract java.io.InputStream createStream​(long startPos, long endPos)
      Opens a new stream reading a range.
      int read()  
      int read​(byte[] b)  
      int read​(byte[] b, int offset, int length)  
      long skip​(long n)  
      • Methods inherited from class java.io.InputStream

        available, mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • mClosed

        protected boolean mClosed
        Has the stream been closed.
      • mStream

        protected java.io.InputStream mStream
        The backing input stream.
      • mPos

        protected long mPos
        The current position of the stream.
      • mEndPos

        protected long mEndPos
        Position the current stream was open till (exclusive).
    • Constructor Detail

      • MultiRangeObjectInputStream

        protected MultiRangeObjectInputStream​(long multiRangeChunkSize)
        Creates the input stream that will perform reads with a specified chunk size. Reading in chunks allows us to read in smaller portions so that we don't need to read all the way to the end of a block.
        Parameters:
        multiRangeChunkSize - the chunk size in bytes to read with
    • Method Detail

      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b,
                        int offset,
                        int length)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • skip

        public long skip​(long n)
                  throws java.io.IOException
        Overrides:
        skip in class java.io.InputStream
        Throws:
        java.io.IOException
      • createStream

        protected abstract java.io.InputStream createStream​(long startPos,
                                                            long endPos)
                                                     throws java.io.IOException
        Opens a new stream reading a range. When endPos > content length, the returned stream should read till the last valid byte of the input. The behaviour is undefined when (startPos < 0), (startPos >= content length), or (endPos <= 0).
        Parameters:
        startPos - start position in bytes (inclusive)
        endPos - end position in bytes (exclusive)
        Returns:
        a new InputStream
        Throws:
        java.io.IOException