Class ByteRangeInputStream

java.lang.Object
java.io.InputStream
org.apache.hadoop.fs.FSInputStream
org.apache.hadoop.hdfs.web.ByteRangeInputStream
All Implemented Interfaces:
Closeable, AutoCloseable, org.apache.hadoop.fs.PositionedReadable, org.apache.hadoop.fs.Seekable

public abstract class ByteRangeInputStream extends org.apache.hadoop.fs.FSInputStream
To support HTTP byte streams, a new connection to an HTTP server needs to be created each time. This class hides the complexity of those multiple connections from the client. Whenever seek() is called, a new connection is made on the successive read(). The normal input stream functions are connected to the currently active input stream.
  • Field Details

  • Constructor Details

  • Method Details

    • getResolvedUrl

      protected abstract URL getResolvedUrl(HttpURLConnection connection) throws IOException
      Throws:
      IOException
    • getInputStream

      @VisibleForTesting protected InputStream getInputStream() throws IOException
      Throws:
      IOException
    • openInputStream

      @VisibleForTesting protected org.apache.hadoop.hdfs.web.ByteRangeInputStream.InputStreamAndFileLength openInputStream(long startOffset) throws IOException
      Throws:
      IOException
    • read

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

      public int read(@Nonnull byte[] b, int off, int len) throws IOException
      Overrides:
      read in class InputStream
      Throws:
      IOException
    • seek

      public void seek(long pos) throws IOException
      Seek to the given offset from the start of the file. The next read() will be from that location. Can't seek past the end of the file.
      Specified by:
      seek in interface org.apache.hadoop.fs.Seekable
      Specified by:
      seek in class org.apache.hadoop.fs.FSInputStream
      Throws:
      IOException
    • read

      public int read(long position, byte[] buffer, int offset, int length) throws IOException
      Specified by:
      read in interface org.apache.hadoop.fs.PositionedReadable
      Overrides:
      read in class org.apache.hadoop.fs.FSInputStream
      Throws:
      IOException
    • readFully

      public void readFully(long position, byte[] buffer, int offset, int length) throws IOException
      Specified by:
      readFully in interface org.apache.hadoop.fs.PositionedReadable
      Overrides:
      readFully in class org.apache.hadoop.fs.FSInputStream
      Throws:
      IOException
    • getPos

      public long getPos() throws IOException
      Return the current offset from the start of the file
      Specified by:
      getPos in interface org.apache.hadoop.fs.Seekable
      Specified by:
      getPos in class org.apache.hadoop.fs.FSInputStream
      Throws:
      IOException
    • seekToNewSource

      public boolean seekToNewSource(long targetPos) throws IOException
      Seeks a different copy of the data. Returns true if found a new source, false otherwise.
      Specified by:
      seekToNewSource in interface org.apache.hadoop.fs.Seekable
      Specified by:
      seekToNewSource in class org.apache.hadoop.fs.FSInputStream
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InputStream
      Throws:
      IOException
    • available

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