RemoteBlockReader2
implementation.
It will be removed in the next release.@InterfaceAudience.Private @Deprecated public class RemoteBlockReader extends FSInputChecker implements BlockReader
CHECKSUM_SIZE, file, LOG
Modifier and Type | Method and Description |
---|---|
int |
available()
Deprecated.
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()
Deprecated.
Close the block reader.
|
protected long |
getChunkPosition(long pos)
Deprecated.
Return position of beginning of chunk containing pos.
|
boolean |
isLocal()
Deprecated.
|
boolean |
isShortCircuit()
Deprecated.
|
static RemoteBlockReader |
newBlockReader(String file,
ExtendedBlock block,
Token<BlockTokenIdentifier> blockToken,
long startOffset,
long len,
int bufferSize,
boolean verifyChecksum,
String clientName,
Peer peer,
DatanodeID datanodeID,
org.apache.hadoop.hdfs.PeerCache peerCache,
CachingStrategy cachingStrategy)
Deprecated.
Create a new BlockReader specifically to satisfy a read.
|
int |
read()
Deprecated.
Read one checksum-verified byte
|
int |
read(byte[] buf,
int off,
int len)
Deprecated.
Read checksum verified bytes from this byte-input stream into
the specified byte array, starting at the given offset.
|
int |
read(ByteBuffer buf)
Deprecated.
Reads up to buf.remaining() bytes into buf.
|
int |
readAll(byte[] buf,
int offset,
int len)
Deprecated.
Similar to
BlockReader.readFully(byte[], int, int) except that it will
not throw an exception on EOF. |
protected int |
readChunk(long pos,
byte[] buf,
int offset,
int len,
byte[] checksumBuf)
Deprecated.
Reads in checksum chunks into
buf at offset
and checksum into checksum . |
void |
readFully(byte[] buf,
int readOffset,
int amtToRead)
Deprecated.
Read exactly the given amount of data, throwing an exception
if EOF is reached before that amount
|
void |
seek(long pos)
Deprecated.
Seek to the given position in the stream.
|
boolean |
seekToNewSource(long targetPos)
Deprecated.
Seeks a different copy of the data.
|
long |
skip(long n)
Deprecated.
Skips over and discards
n bytes of data from the
input stream. |
checksum2long, getPos, mark, markSupported, needChecksum, readFully, reset, set
read, readFully, readFully
read
public int read(byte[] buf, int off, int len) throws IOException
FSInputChecker
This method implements the general contract of the corresponding
method of
the read
class. As an additional
convenience, it attempts to read as many bytes as possible by repeatedly
invoking the InputStream
read
method of the underlying stream. This
iterated read
continues until one of the following
conditions becomes true:
read
method of the underlying stream returns
-1
, indicating end-of-file.
read
on the underlying stream returns
-1
to indicate end-of-file then this method returns
-1
. Otherwise this method returns the number of bytes
actually read.read
in interface BlockReader
read
in class FSInputChecker
buf
- destination buffer.off
- offset at which to start storing bytes.len
- maximum number of bytes to read.-1
if the end of
the stream has been reached.IOException
- if an I/O error occurs.
ChecksumException if any checksum error occurspublic long skip(long n) throws IOException
FSInputChecker
n
bytes of data from the
input stream.
This method may skip more bytes than are remaining in the backing file. This produces no exception and the number of bytes skipped may include some number of bytes that were beyond the EOF of the backing file. Attempting to read from the stream after skipping past the end will result in -1 indicating the end of the file.
If n
is negative, no bytes are skipped.
skip
in interface BlockReader
skip
in class FSInputChecker
n
- the number of bytes to be skipped.IOException
- if an I/O error occurs.
ChecksumException if the chunk to skip to is corruptedpublic int read() throws IOException
FSInputChecker
read
in class FSInputChecker
-1
if the end of the
stream is reached.IOException
- if an I/O error occurs.public boolean seekToNewSource(long targetPos) throws IOException
FSInputStream
seekToNewSource
in interface Seekable
seekToNewSource
in class FSInputStream
IOException
public void seek(long pos) throws IOException
FSInputChecker
This method may seek past the end of the file. This produces no exception and an attempt to read from the stream will result in -1 indicating the end of the file.
seek
in interface Seekable
seek
in class FSInputChecker
pos
- the postion to seek to.IOException
- if an I/O error occurs.
ChecksumException if the chunk to seek to is corruptedprotected long getChunkPosition(long pos)
FSInputChecker
getChunkPosition
in class FSInputChecker
pos
- a postion in the fileprotected int readChunk(long pos, byte[] buf, int offset, int len, byte[] checksumBuf) throws IOException
FSInputChecker
buf
at offset
and checksum into checksum
.
Since checksums can be disabled, there are two cases implementors need
to worry about:
(a) needChecksum() will return false:
- len can be any positive value
- checksum will be null
Implementors should simply pass through to the underlying data stream.
or
(b) needChecksum() will return true:
- len >= maxChunkSize
- checksum.length is a multiple of CHECKSUM_SIZE
Implementors should read an integer number of data chunks into
buf. The amount read should be bounded by len or by
checksum.length / CHECKSUM_SIZE * maxChunkSize. Note that len may
be a value that is not a multiple of maxChunkSize, in which case
the implementation may return less than len.
The method is used for implementing read, therefore, it should be optimized
for sequential reading.readChunk
in class FSInputChecker
pos
- chunkPosbuf
- desitination bufferoffset
- offset in buf at which to store datalen
- maximum number of bytes to readchecksumBuf
- the data buffer into which to write checksumsIOException
public static RemoteBlockReader newBlockReader(String file, ExtendedBlock block, Token<BlockTokenIdentifier> blockToken, long startOffset, long len, int bufferSize, 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 normallyfile
- File locationblock
- The block objectblockToken
- The block 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 void close() throws IOException
BlockReader
close
in interface Closeable
close
in interface AutoCloseable
close
in interface BlockReader
close
in class InputStream
IOException
public void readFully(byte[] buf, int readOffset, int amtToRead) throws IOException
BlockReader
readFully
in interface BlockReader
IOException
public 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 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 int available() throws IOException
BlockReader
available
in interface BlockReader
available
in class FSInputChecker
IOException
public boolean isLocal()
isLocal
in interface BlockReader
public boolean isShortCircuit()
isShortCircuit
in interface BlockReader
Copyright © 2013 Apache Software Foundation. All rights reserved.