public abstract class BufferedBlockInStream extends BlockInStream
TachyonBlockStore.getInStream(long)
. The buffer size of the stream can be
set through configuration. Multiple BufferedBlockInStreams can be opened for a block. This class
is not thread safe and should only be used by one thread.
This class provides the same methods as a Java InputStream
with additional methods from
Tachyon Stream interfaces.Modifier and Type | Field and Description |
---|---|
protected long |
mBlockId
The id of the block to which this instream provides access.
|
protected boolean |
mBlockIsRead
Flag indicating if the stream is read
|
protected long |
mBlockSize
The size in bytes of the block.
|
protected ByteBuffer |
mBuffer
Internal buffer to improve small read performance.
|
protected boolean |
mClosed
Flag indicating if the stream is closed, can only go from false to true.
|
protected InetSocketAddress |
mLocation
The address of the worker to read the data from.
|
Constructor and Description |
---|
BufferedBlockInStream(long blockId,
long blockSize,
InetSocketAddress location)
Basic constructor for a BufferedBlockInStream.
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
bufferedRead(int len)
Reads from the data source into the buffer.
|
void |
close() |
protected abstract int |
directRead(byte[] b,
int off,
int len)
Directly reads data to the given byte array.
|
protected long |
getPosition() |
protected abstract void |
incrementBytesReadMetric(int bytes)
Increments the number of bytes read metric.
|
int |
read() |
int |
read(byte[] b) |
int |
read(byte[] b,
int off,
int len) |
long |
remaining()
Gets the remaining number of bytes left in the stream, starting at the current position.
|
void |
seek(long pos)
Moves the starting read position of the stream to the specified position which is relative to
the start of the stream.
|
long |
skip(long n) |
available, mark, markSupported, reset
protected final long mBlockId
protected final long mBlockSize
protected final InetSocketAddress mLocation
protected ByteBuffer mBuffer
protected boolean mClosed
protected boolean mBlockIsRead
public BufferedBlockInStream(long blockId, long blockSize, InetSocketAddress location)
blockId
- block id for this streamblockSize
- size of the block in byteslocation
- worker address to read the block frompublic 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[] b) throws IOException
read
in class InputStream
IOException
public int read(byte[] b, int off, int len) throws IOException
read
in class InputStream
IOException
public long remaining()
BoundedStream
public void seek(long pos) throws IOException
Seekable
pos
- The position to seek to, it must be between 0 and the end of the stream - 1.IOException
- if the seek fails due to an error accessing the stream at the positionpublic long skip(long n) throws IOException
skip
in class InputStream
IOException
protected long getPosition()
protected abstract void bufferedRead(int len) throws IOException
len
- length of data to fill in the buffer, must always be <= buffer sizeIOException
- if the read failed to buffer the requested number of bytesprotected abstract int directRead(byte[] b, int off, int len) throws IOException
b
- the byte array to write the data tooff
- the offset in the array to write tolen
- the length of data to write into the array must always be valid within the blockIOException
- if an error occurs reading the dataprotected abstract void incrementBytesReadMetric(int bytes)
bytes
- number of bytes to record as readCopyright © 2015. All Rights Reserved.