Class GCSInputStream

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

    @NotThreadSafe
    public final class GCSInputStream
    extends java.io.InputStream
    A stream for reading a file from GCS. The main purpose is to provide a faster skip method, as the underlying implementation will read and discard bytes until the number to skip has been reached. This input stream returns 0 when calling read with an empty buffer.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      int read()  
      int read​(byte[] b)  
      int read​(byte[] b, int off, int len)  
      long skip​(long n)
      This method leverages the ability to open a stream from GCS from a given offset.
      • 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
    • 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 off,
                        int len)
                 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
        This method leverages the ability to open a stream from GCS from a given offset. When the underlying stream has fewer bytes buffered than the skip request, the stream is closed, and a new stream is opened starting at the requested offset.
        Overrides:
        skip in class java.io.InputStream
        Parameters:
        n - number of bytes to skip
        Returns:
        the number of bytes skipped
        Throws:
        java.io.IOException