org.apache.hadoop.hdfs
Class ByteRangeInputStream
java.lang.Object
java.io.InputStream
org.apache.hadoop.fs.FSInputStream
org.apache.hadoop.hdfs.ByteRangeInputStream
- All Implemented Interfaces:
- Closeable, 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.
Methods inherited from class org.apache.hadoop.fs.FSInputStream |
read, readFully, readFully |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
in
protected InputStream in
originalURL
protected ByteRangeInputStream.URLOpener originalURL
resolvedURL
protected ByteRangeInputStream.URLOpener resolvedURL
startPos
protected long startPos
currentPos
protected long currentPos
fileLength
protected Long fileLength
ByteRangeInputStream
public ByteRangeInputStream(ByteRangeInputStream.URLOpener o,
ByteRangeInputStream.URLOpener r)
- 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
getResolvedUrl
protected abstract URL getResolvedUrl(HttpURLConnection connection)
throws IOException
- Throws:
IOException
getInputStream
protected InputStream getInputStream()
throws IOException
- Throws:
IOException
openInputStream
protected InputStream openInputStream()
throws IOException
- Throws:
IOException
read
public int read()
throws IOException
- Specified by:
read
in class InputStream
- Throws:
IOException
read
public int read(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
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 Closeable
- Overrides:
close
in class InputStream
- Throws:
IOException
Copyright © 2012 Apache Software Foundation. All Rights Reserved.