Package alluxio.worker.block.io
Class LocalFileBlockReader
- java.lang.Object
-
- alluxio.worker.block.io.BlockClient
-
- alluxio.worker.block.io.BlockReader
-
- alluxio.worker.block.io.LocalFileBlockReader
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
@NotThreadSafe public class LocalFileBlockReader extends BlockReader
This class provides read access to a block data file locally stored in managed storage.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class alluxio.worker.block.io.BlockClient
BlockClient.Type
-
-
Constructor Summary
Constructors Constructor Description LocalFileBlockReader(java.lang.String path)
Constructs a Block reader given the file path of the block.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
decreaseUsageCount()
decrease the file reader usage count.java.nio.channels.ReadableByteChannel
getChannel()
Returns a readable byte channel of the block.java.lang.String
getFilePath()
long
getLength()
Gets the length of the block in bytes.java.lang.String
getLocation()
int
getUsageCount()
void
increaseUsageCount()
increase the file reader usage count.boolean
isClosed()
java.nio.ByteBuffer
read(long offset, long length)
Reads data from the block.int
transferTo(io.netty.buffer.ByteBuf buf)
Transfers data (up to buf.writableBytes()) from this reader to the buffer.-
Methods inherited from class alluxio.worker.block.io.BlockClient
toString
-
-
-
-
Method Detail
-
getChannel
public java.nio.channels.ReadableByteChannel getChannel()
Description copied from class:BlockReader
Returns a readable byte channel of the block.- Specified by:
getChannel
in classBlockReader
- Returns:
- channel
-
getLength
public long getLength()
Description copied from class:BlockReader
Gets the length of the block in bytes.- Specified by:
getLength
in classBlockReader
- Returns:
- the length of the block in bytes
-
increaseUsageCount
public void increaseUsageCount()
increase the file reader usage count.
-
decreaseUsageCount
public void decreaseUsageCount()
decrease the file reader usage count.
-
getUsageCount
public int getUsageCount()
- Returns:
- the file reader usage count
-
getFilePath
public java.lang.String getFilePath()
- Returns:
- the file path
-
read
public java.nio.ByteBuffer read(long offset, long length) throws java.io.IOException
Description copied from class:BlockReader
Reads data from the block.Implementation Note
Since this method needs to allocate a buffer inside its implementation, it must not choose a ByteBuffer that needs any kind of explicit de-allocation, e.g. a pooled buffer, because the caller has no means of knowing how and when to properly deallocate the returned buffer.
If explicit de-allocation is desired, use an externally allocatedByteBuf
and callBlockReader.transferTo(ByteBuf)
instead. It is then the caller's responsibility to de-allocate the buffer.- Specified by:
read
in classBlockReader
- Parameters:
offset
- the offset from starting of the block file in byteslength
- the length of data to read in bytes. If offset + length exceeds the block size, the part of data from offset to the end of block is returned.- Returns:
ByteBuffer
the data that was read, empty buffer ifoffset
is at the end of block- Throws:
java.io.IOException
-
transferTo
public int transferTo(io.netty.buffer.ByteBuf buf) throws java.io.IOException
Description copied from class:BlockReader
Transfers data (up to buf.writableBytes()) from this reader to the buffer.- Specified by:
transferTo
in classBlockReader
- Parameters:
buf
- the byte buffer- Returns:
- the number of bytes transferred, -1 if the end of the block is reached
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classBlockClient
- Throws:
java.io.IOException
-
isClosed
public boolean isClosed()
- Specified by:
isClosed
in classBlockReader
- Returns:
- true if this reader is closed
-
getLocation
public java.lang.String getLocation()
- Specified by:
getLocation
in classBlockReader
- Returns:
- an informational string of the location the reader is reading from
-
-