@InterfaceAudience.Private public class DFSInputStream extends FSInputStream implements ByteBufferReadable, CanSetDropBehind, CanSetReadahead
Modifier and Type | Class and Description |
---|---|
static class |
DFSInputStream.ReadStatistics |
Modifier and Type | Method and Description |
---|---|
int |
available()
Return the size of the remaining available bytes
if the size is less than or equal to
Integer.MAX_VALUE ,
otherwise, return Integer.MAX_VALUE . |
void |
close()
Close it down!
|
List<LocatedBlock> |
getAllBlocks()
Return collection of blocks that has already been located.
|
protected BlockReader |
getBlockReader(InetSocketAddress dnAddr,
DatanodeInfo chosenNode,
String file,
ExtendedBlock block,
Token<BlockTokenIdentifier> blockToken,
long startOffset,
long len,
int bufferSize,
boolean verifyChecksum,
String clientName)
Retrieve a BlockReader suitable for reading.
|
ExtendedBlock |
getCurrentBlock()
Returns the block containing the target position.
|
DatanodeInfo |
getCurrentDatanode()
Returns the datanode from which the stream is currently reading.
|
long |
getFileLength() |
long |
getPos()
Return the current offset from the start of the file
|
DFSInputStream.ReadStatistics |
getReadStatistics()
Get statistics about the reads which this DFSInputStream has done.
|
void |
mark(int readLimit) |
boolean |
markSupported()
We definitely don't support marks
|
int |
read() |
int |
read(byte[] buf,
int off,
int len)
Read the entire buffer.
|
int |
read(ByteBuffer buf)
Reads up to buf.remaining() bytes into buf.
|
int |
read(long position,
byte[] buffer,
int offset,
int length)
Read bytes starting from the specified position.
|
void |
reset() |
void |
seek(long targetPos)
Seek to a new arbitrary location
|
boolean |
seekToNewSource(long targetPos)
Seek to given position on a node other than the current node.
|
void |
setDropBehind(Boolean dropBehind)
Configure whether the stream should drop the cache.
|
void |
setReadahead(Long readahead)
Set the readahead on this stream.
|
long |
skip(long n) |
readFully, readFully
read
public long getFileLength()
public DatanodeInfo getCurrentDatanode()
public ExtendedBlock getCurrentBlock()
public List<LocatedBlock> getAllBlocks() throws IOException
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
IOException
public int read() throws IOException
read
in class InputStream
IOException
public int read(byte[] buf, int off, int len) throws IOException
read
in class InputStream
IOException
public int read(ByteBuffer buf) throws IOException
ByteBufferReadable
UnsupportedOperationException
, so
callers that are not confident in support for this method from the
underlying filesystem should be prepared to handle that exception.
Implementations should treat 0-length requests as legitimate, and must not
signal an error upon their receipt.read
in interface ByteBufferReadable
buf
- the ByteBuffer to receive the results of the read operation. Up to
buf.limit() - buf.position() bytes may be read.IOException
- if there is some error performing the readprotected BlockReader getBlockReader(InetSocketAddress dnAddr, DatanodeInfo chosenNode, String file, ExtendedBlock block, Token<BlockTokenIdentifier> blockToken, long startOffset, long len, int bufferSize, boolean verifyChecksum, String clientName) throws IOException
dnAddr
- Address of the datanodechosenNode
- Chosen datanode informationfile
- File locationblock
- The Block objectblockToken
- The access token for securitystartOffset
- The read offset, relative to block headlen
- The number of bytes to readbufferSize
- The IO buffer size (not the client buffer size)verifyChecksum
- Whether to verify checksumclientName
- Client nameIOException
public int read(long position, byte[] buffer, int offset, int length) throws IOException
read
in interface PositionedReadable
read
in class FSInputStream
position
- start read from this positionbuffer
- read bufferoffset
- offset into bufferlength
- number of bytes to readIOException
public long skip(long n) throws IOException
skip
in class InputStream
IOException
public void seek(long targetPos) throws IOException
seek
in interface Seekable
seek
in class FSInputStream
IOException
public boolean seekToNewSource(long targetPos) throws IOException
seekToNewSource
in interface Seekable
seekToNewSource
in class FSInputStream
IOException
public long getPos() throws IOException
FSInputStream
getPos
in interface Seekable
getPos
in class FSInputStream
IOException
public int available() throws IOException
Integer.MAX_VALUE
,
otherwise, return Integer.MAX_VALUE
.available
in class InputStream
IOException
public boolean markSupported()
markSupported
in class InputStream
public void mark(int readLimit)
mark
in class InputStream
public void reset() throws IOException
reset
in class InputStream
IOException
public DFSInputStream.ReadStatistics getReadStatistics()
public void setReadahead(Long readahead) throws IOException
CanSetReadahead
setReadahead
in interface CanSetReadahead
readahead
- The readahead to use. null means to use the default.IOException
- If there was an error changing the dropBehind
setting.
UnsupportedOperationException If this stream doesn't support
setting readahead.public void setDropBehind(Boolean dropBehind) throws IOException
CanSetDropBehind
setDropBehind
in interface CanSetDropBehind
dropBehind
- Whether to drop the cache. null means to use the
default value.IOException
- If there was an error changing the dropBehind
setting.
UnsupportedOperationException If this stream doesn't support
setting the drop-behind.Copyright © 2013 Apache Software Foundation. All rights reserved.