@InterfaceAudience.Private public class RemoteBlockReader2 extends Object implements BlockReader
Modifier | Constructor and Description |
---|---|
protected |
RemoteBlockReader2(String file,
String bpid,
long blockId,
DataChecksum checksum,
boolean verifyChecksum,
long startOffset,
long firstChunkOffset,
long bytesToRead,
Peer peer,
DatanodeID datanodeID,
org.apache.hadoop.hdfs.PeerCache peerCache) |
Modifier and Type | Method and Description |
---|---|
int |
available()
Returns an estimate of the number of bytes that can be read
(or skipped over) from this input stream without performing
network I/O.
|
void |
close()
Close the block reader.
|
static String |
getFileName(InetSocketAddress s,
String poolId,
long blockId)
File name to print when accessing a block directly (from servlets)
|
Peer |
getPeer() |
boolean |
isLocal() |
boolean |
isShortCircuit() |
static BlockReader |
newBlockReader(String file,
ExtendedBlock block,
Token<BlockTokenIdentifier> blockToken,
long startOffset,
long len,
boolean verifyChecksum,
String clientName,
Peer peer,
DatanodeID datanodeID,
org.apache.hadoop.hdfs.PeerCache peerCache,
CachingStrategy cachingStrategy)
Create a new BlockReader specifically to satisfy a read.
|
int |
read(byte[] buf,
int off,
int len) |
int |
read(ByteBuffer buf)
Reads up to buf.remaining() bytes into buf.
|
int |
readAll(byte[] buf,
int offset,
int len)
Similar to
BlockReader.readFully(byte[], int, int) except that it will
not throw an exception on EOF. |
void |
readFully(byte[] buf,
int off,
int len)
Read exactly the given amount of data, throwing an exception
if EOF is reached before that amount
|
long |
skip(long n)
Skip the given number of bytes
|
protected RemoteBlockReader2(String file, String bpid, long blockId, DataChecksum checksum, boolean verifyChecksum, long startOffset, long firstChunkOffset, long bytesToRead, Peer peer, DatanodeID datanodeID, org.apache.hadoop.hdfs.PeerCache peerCache)
public Peer getPeer()
public int read(byte[] buf, int off, int len) throws IOException
read
in interface BlockReader
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 readpublic long skip(long n) throws IOException
BlockReader
skip
in interface BlockReader
IOException
public void close() throws IOException
BlockReader
close
in interface BlockReader
IOException
public static String getFileName(InetSocketAddress s, String poolId, long blockId)
s
- Address of the block locationpoolId
- Block pool ID of the blockblockId
- Block ID of the blockpublic int readAll(byte[] buf, int offset, int len) throws IOException
BlockReader
BlockReader.readFully(byte[], int, int)
except that it will
not throw an exception on EOF. However, it differs from the simple
BlockReader.read(byte[], int, int)
call in that it is guaranteed to
read the data if it is available. In other words, if this call
does not throw an exception, then either the buffer has been
filled or the next call will return EOF.readAll
in interface BlockReader
IOException
public void readFully(byte[] buf, int off, int len) throws IOException
BlockReader
readFully
in interface BlockReader
IOException
public static BlockReader newBlockReader(String file, ExtendedBlock block, Token<BlockTokenIdentifier> blockToken, long startOffset, long len, boolean verifyChecksum, String clientName, Peer peer, DatanodeID datanodeID, org.apache.hadoop.hdfs.PeerCache peerCache, CachingStrategy cachingStrategy) throws IOException
sock
- An established Socket to the DN. The BlockReader will not close it normally.
This socket must have an associated Channel.file
- File locationblock
- The block objectblockToken
- The block token for securitystartOffset
- The read offset, relative to block headlen
- The number of bytes to readverifyChecksum
- Whether to verify checksumclientName
- Client namepeer
- The Peer to usedatanodeID
- The DatanodeID this peer is connected toIOException
public int available() throws IOException
BlockReader
available
in interface BlockReader
IOException
public boolean isLocal()
isLocal
in interface BlockReader
public boolean isShortCircuit()
isShortCircuit
in interface BlockReader
Copyright © 2013 Apache Software Foundation. All rights reserved.