|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.basex.build.fs.parser.BufferedFileChannel
public final class BufferedFileChannel
Buffered FileChannel implementation.
This implementation is optimized for sequential reading of a file or a fragment of a file.
| Constructor Summary | |
|---|---|
BufferedFileChannel(java.io.File file)
Standard constructor for creating a BufferedFileChannel from a
complete file. |
|
BufferedFileChannel(java.io.File file,
java.nio.ByteBuffer buffer)
Creates a BufferedFileChannel from a complete file and uses the
given buffer for caching the data. |
|
BufferedFileChannel(java.io.File file,
int bufferSize)
Creates a BufferedFileChannel from a complete file with the given
buffer size. |
|
| Method Summary | |
|---|---|
long |
absolutePosition()
Returns this channel's absolute position. |
boolean |
buffer(int n)
Buffers n bytes, if the underlying buffer is large enough. |
void |
close()
Closes the underlying FileChannel. |
void |
finish()
Finishes reading from a channel created by subChannel(int). |
int |
get()
Relative get method. |
byte[] |
get(byte[] dst)
Reads dst.length bytes from the BufferedFileChannel. |
void |
get(byte[] dst,
int start,
int length)
Reads length bytes from the BufferedFileChannel. |
int |
getBufferSize()
Returns the size of the buffer. |
java.lang.String |
getFileName()
Returns the absolute file name of current file. |
int |
getInt()
Relative get method. |
int |
getShort()
Relative get method. |
boolean |
isSubChannel()
Checks if the current BufferedFileChannel instance is a
sub-channel. |
long |
position()
Returns this channel's position. |
void |
position(long newPosition)
Sets this channel's position. |
long |
remaining()
Returns the number of remaining bytes in this BufferedFileChannel. |
void |
reset()
Resets the channel to its initial position. |
void |
setByteOrder(java.nio.ByteOrder order)
Modifies this channel's byte order. |
long |
size()
Returns the size of the channel. |
void |
skip(long n)
Skips n bytes in the ByteBuffer. |
BufferedFileChannel |
subChannel(int bytesToRead)
Creates a "subChannel" view for this BufferedFileChannel instance
that shares the underlying FileChannel and buffer. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public BufferedFileChannel(java.io.File file)
throws java.io.IOException
BufferedFileChannel from a
complete file.
file - the file to read from.
java.io.IOException - if any error occurs while creating the
BufferedFileChannel.
public BufferedFileChannel(java.io.File file,
int bufferSize)
throws java.io.IOException
BufferedFileChannel from a complete file with the given
buffer size.
file - the file to read from.bufferSize - the size of the buffer.
java.io.IOException - if any error occurs while creating the
BufferedFileChannel.
public BufferedFileChannel(java.io.File file,
java.nio.ByteBuffer buffer)
throws java.io.IOException
BufferedFileChannel from a complete file and uses the
given buffer for caching the data. This constructor can be used for
creating many BufferedFileChannel instances (consecutively) with
the same direct byte buffer to avoid the allocation- and
garbage-collection-overhead for multiple direct byte buffers.
file - the file to read from.buffer - the ByteBuffer to use for caching the data.
java.io.IOException - if any error occurs while creating the
BufferedFileChannel.| Method Detail |
|---|
public BufferedFileChannel subChannel(int bytesToRead)
throws java.io.IOException
Creates a "subChannel" view for this BufferedFileChannel instance
that shares the underlying FileChannel and buffer.
The content of the new channel will start at this channel's current
position and it's size depends on the given parameter
bytesToRead.
The original channel must not be used before finish() has been
called on the BufferedFileChannel created by this method. After
finishing the subChannel, the original channel's position is incremented by
bytesToRead.
bytesToRead - the maximum number of bytes to read.
java.io.IOException - if any error occurs while creating the channel.public int getBufferSize()
public void skip(long n)
throws java.io.IOException
n bytes in the ByteBuffer.
n - number of bytes to skip. May be negative.
java.io.IOException - if any error occurs while reading the file.
public long position()
throws java.io.IOException
java.io.IOException - if any error occurs while reading from the channel.
public long absolutePosition()
throws java.io.IOException
java.io.IOException - if any error occurs while reading from the channel.
public void position(long newPosition)
throws java.io.IOException
newPosition - the new position, a non-negative integer counting the
number of bytes from the beginning of the channel.
java.io.IOException - if any error occurs while reading from the channel.public long remaining()
BufferedFileChannel.
public long size()
throws java.io.IOException
java.io.IOException - if any error occurs while calculating the size.
public boolean isSubChannel()
throws java.io.IOException
BufferedFileChannel instance is a
sub-channel.
java.io.IOException - if any i/o error occurs.
public void reset()
throws java.io.IOException
java.io.IOException - if any error occurs while reading from the channel.
public byte[] get(byte[] dst)
throws java.io.IOException
dst.length bytes from the BufferedFileChannel.
dst - the arrray to write the data to.
java.io.IOException - if there are less than dst.length bytes
available or any error occurs while reading from the channel.
public void get(byte[] dst,
int start,
int length)
Reads length bytes from the BufferedFileChannel.
Assure that that the buffer is large enough and that enough bytes are
buffered (via buffer(int)). Otherwise, a
BufferUnderflowException may be thrown.
dst - the arrray to write the data to.start - the first position to write the data to.length - the number of bytes to read.public int get()
Relative get method. Reads the byte at this channel's current position, and then increments the position.
Assure that enough at least one byte is buffered via
#buffer(1). Otherwise, a
BufferUnderflowException may be thrown.
public int getShort()
Relative get method. Reads two bytes at this channel's current position, and then increments the position by two.
Assure that enough at least two bytes are buffered via
#buffer(2). Otherwise, a
BufferUnderflowException may be thrown.
public int getInt()
Relative get method. Reads four bytes at this channel's current position, and then increments the position by four.
Assure that enough at least four bytes are buffered via
#buffer(4). Otherwise, a
BufferUnderflowException may be thrown.
public void finish()
throws java.io.IOException
Finishes reading from a channel created by subChannel(int). Any
subsequent read from this BufferedFileChannel will fail.
This method must be called for every BufferedFileChannel that
was created by subChannel(int) instead of calling close()
.
java.io.IOException - if any error occurs while finishing the channel.close()
public void close()
throws java.io.IOException
Closes the underlying FileChannel.
This method must not be called for BufferedFileChannel instances
that were created by subChannel(int).
java.io.IOException - if any error occurs while closing the
FileChannel.finish()
public boolean buffer(int n)
throws java.io.IOException
Buffers n bytes, if the underlying buffer is large enough.
Does nothing, if the buffer is too small.
n - the number of bytes to buffer.
n bytes, false if it is too small.
java.io.IOException - if any error occurs while reading the file.public java.lang.String getFileName()
public void setByteOrder(java.nio.ByteOrder order)
order - The new byte order, either BIG_ENDIAN or LITTLE_ENDIAN
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||