Package org.apache.hadoop.hdfs.web
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThis class wraps a URL and provides method to open connection. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected longprotected Longprotected InputStreamprotected final ByteRangeInputStream.URLOpenerprotected final ByteRangeInputStream.URLOpenerprotected long -
Constructor Summary
ConstructorsConstructorDescriptionCreate with the specified URLOpeners. -
Method Summary
Modifier and TypeMethodDescriptionintvoidclose()protected InputStreamlonggetPos()Return the current offset from the start of the fileprotected abstract URLgetResolvedUrl(HttpURLConnection connection) protected org.apache.hadoop.hdfs.web.ByteRangeInputStream.InputStreamAndFileLengthopenInputStream(long startOffset) intread()intread(byte[] b, int off, int len) intread(long position, byte[] buffer, int offset, int length) voidreadFully(long position, byte[] buffer, int offset, int length) voidseek(long pos) Seek to the given offset from the start of the file.booleanseekToNewSource(long targetPos) Seeks a different copy of the data.Methods inherited from class org.apache.hadoop.fs.FSInputStream
readFully, toString, validatePositionedReadArgsMethods inherited from class java.io.InputStream
mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferToMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.hadoop.fs.PositionedReadable
maxReadSizeForVectorReads, minSeekForVectorReads, readVectored, readVectored
-
Field Details
-
in
-
originalURL
-
resolvedURL
-
startPos
protected long startPos -
currentPos
protected long currentPos -
fileLength
-
-
Constructor Details
-
ByteRangeInputStream
public ByteRangeInputStream(ByteRangeInputStream.URLOpener o, ByteRangeInputStream.URLOpener r) throws IOException Create with the specified URLOpeners. Original url is used to open the stream for the first time. Resolved url is used in subsequent requests.- Parameters:
o- Original urlr- Resolved url- Throws:
IOException
-
-
Method Details
-
getResolvedUrl
- Throws:
IOException
-
getInputStream
- Throws:
IOException
-
openInputStream
@VisibleForTesting protected org.apache.hadoop.hdfs.web.ByteRangeInputStream.InputStreamAndFileLength openInputStream(long startOffset) throws IOException - Throws:
IOException
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
seek
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:
seekin interfaceorg.apache.hadoop.fs.Seekable- Specified by:
seekin classorg.apache.hadoop.fs.FSInputStream- Throws:
IOException
-
read
- Specified by:
readin interfaceorg.apache.hadoop.fs.PositionedReadable- Overrides:
readin classorg.apache.hadoop.fs.FSInputStream- Throws:
IOException
-
readFully
- Specified by:
readFullyin interfaceorg.apache.hadoop.fs.PositionedReadable- Overrides:
readFullyin classorg.apache.hadoop.fs.FSInputStream- Throws:
IOException
-
getPos
Return the current offset from the start of the file- Specified by:
getPosin interfaceorg.apache.hadoop.fs.Seekable- Specified by:
getPosin classorg.apache.hadoop.fs.FSInputStream- Throws:
IOException
-
seekToNewSource
Seeks a different copy of the data. Returns true if found a new source, false otherwise.- Specified by:
seekToNewSourcein interfaceorg.apache.hadoop.fs.Seekable- Specified by:
seekToNewSourcein classorg.apache.hadoop.fs.FSInputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
available
- Overrides:
availablein classInputStream- Throws:
IOException
-