Package org.h2gis.functions.io.utility
Class ReadBufferManager
- java.lang.Object
-
- org.h2gis.functions.io.utility.ReadBufferManager
-
public final class ReadBufferManager extends Object
-
-
Constructor Summary
Constructors Constructor Description ReadBufferManager(FileChannel channel)Instantiates a ReadBufferManager to read the specified channelReadBufferManager(FileChannel channel, int bufferSize)Instantiates a ReadBufferManager to read the specified channel.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byteget()Gets the byte value at the current positionByteBufferget(byte[] buffer)Gets the byte[] value at the current positionByteBufferget(long pos, byte[] buffer)Gets the byte[] value at the specified positionbytegetByte(long bytePos)Gets the byte value at the specified positiondoublegetDouble()Gets the double value at the specified positiondoublegetDouble(long bytePos)Gets the double value at the specified positionintgetInt()Gets the int value at the current positionintgetInt(long bytePos)Gets the int value at the specified positionlonggetLength()Gets the size of the channellonggetLong()Gets the long value at the current positionlonggetLong(long bytePos)Gets the long value at the specified positionlonggetPosition()Gets the position of this buffer in the file it's reading.booleanisEOF()If the current position is at the end of the channelvoidorder(ByteOrder order)Specifies the byte order.voidposition(long position)Moves the current position to the specified onelongremaining()Gets the number of remaining bytes in the current file, starting from the current positionvoidskip(int numBytes)skips the specified number of bytes from the current position in the channel
-
-
-
Constructor Detail
-
ReadBufferManager
public ReadBufferManager(FileChannel channel) throws IOException
Instantiates a ReadBufferManager to read the specified channel- Parameters:
channel-FileChannel- Throws:
IOException
-
ReadBufferManager
public ReadBufferManager(FileChannel channel, int bufferSize) throws IOException
Instantiates a ReadBufferManager to read the specified channel. The specified bufferSize is the size of the channel content cached in memory- Parameters:
channel-FileChannelbufferSize- buffer size- Throws:
IOException
-
-
Method Detail
-
getByte
public byte getByte(long bytePos) throws IOExceptionGets the byte value at the specified position- Parameters:
bytePos- byte position- Returns:
- byte value
- Throws:
IOException
-
getLength
public long getLength() throws IOExceptionGets the size of the channel- Returns:
- channel size
- Throws:
IOException
-
order
public void order(ByteOrder order)
Specifies the byte order. One of the constants inByteBuffer- Parameters:
order-ByteOrder
-
getInt
public int getInt(long bytePos) throws IOExceptionGets the int value at the specified position- Parameters:
bytePos- byte position- Returns:
- int value
- Throws:
IOException
-
getLong
public long getLong(long bytePos) throws IOExceptionGets the long value at the specified position- Parameters:
bytePos- byte position- Returns:
- long value
- Throws:
IOException
-
getLong
public long getLong() throws IOExceptionGets the long value at the current position- Returns:
- long value
- Throws:
IOException
-
get
public byte get() throws IOExceptionGets the byte value at the current position- Returns:
- byte value
- Throws:
IOException
-
getInt
public int getInt() throws IOExceptionGets the int value at the current position- Returns:
- int value
- Throws:
IOException
-
skip
public void skip(int numBytes) throws IOExceptionskips the specified number of bytes from the current position in the channel- Parameters:
numBytes- numBytes to move the buffer to a new position- Throws:
IOException
-
get
public ByteBuffer get(byte[] buffer) throws IOException
Gets the byte[] value at the current position- Parameters:
buffer- byte array- Returns:
- ByteBuffer
- Throws:
IOException
-
get
public ByteBuffer get(long pos, byte[] buffer) throws IOException
Gets the byte[] value at the specified position- Parameters:
pos- buffer positionbuffer- bytes- Returns:
- ByteBuffer
- Throws:
IOException
-
position
public void position(long position)
Moves the current position to the specified one- Parameters:
position- buffer position
-
getPosition
public long getPosition()
Gets the position of this buffer in the file it's reading.- Returns:
- index of the position
-
getDouble
public double getDouble() throws IOExceptionGets the double value at the specified position- Returns:
- double value
- Throws:
IOException
-
getDouble
public double getDouble(long bytePos) throws IOExceptionGets the double value at the specified position- Parameters:
bytePos- buffer position- Returns:
- double value
- Throws:
IOException
-
isEOF
public boolean isEOF() throws IOExceptionIf the current position is at the end of the channel- Returns:
- true if the current position is at the end of the channel
- Throws:
IOException
-
remaining
public long remaining() throws IOExceptionGets the number of remaining bytes in the current file, starting from the current position- Returns:
- a number of bytes >=0
- Throws:
IOException
-
-