public class NIOFileHandle extends AbstractNIOHandle
IRandomAccess,
RandomAccessFile| Modifier and Type | Field and Description |
|---|---|
protected ByteBuffer |
buffer
The buffer itself.
|
protected int |
bufferSize
The buffer size.
|
protected long |
bufferStartPosition
The absolute position of the start of the buffer.
|
protected NIOByteBufferProvider |
byteBufferProvider
Provider class for NIO byte buffers, allocated or memory mapped.
|
protected FileChannel |
channel
The file channel backed by the random access file.
|
protected static int |
defaultBufferSize
Default NIO buffer size to facilitate buffered I/O.
|
protected static int |
defaultRWBufferSize
Default NIO buffer size to facilitate buffered I/O for read/write streams.
|
protected boolean |
isReadWrite
Whether or not the file is opened read/write.
|
protected FileChannel.MapMode |
mapMode
The default map mode for the file.
|
protected ByteOrder |
order
The buffer's byte ordering.
|
protected long |
position
The absolute position within the file.
|
protected RandomAccessFile |
raf
The random access file object backing this FileHandle.
|
EOF_ERROR_MSG| Constructor and Description |
|---|
NIOFileHandle(File file,
String mode)
Creates a random access file stream to read from, and
optionally to write to, the file specified by the File argument.
|
NIOFileHandle(File file,
String mode,
int bufferSize)
Creates a random access file stream to read from, and
optionally to write to, the file specified by the File argument.
|
NIOFileHandle(String name,
String mode)
Creates a random access file stream to read from, and
optionally to write to, a file with the specified name.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this random access stream and releases
any system resources associated with the stream.
|
int |
getBufferSize() |
FileChannel |
getFileChannel() |
long |
getFilePointer()
Returns the current offset in this stream.
|
ByteOrder |
getOrder()
Returns the current order (endianness) of the stream.
|
RandomAccessFile |
getRandomAccessFile() |
long |
length()
Returns the length of this stream.
|
int |
read(byte[] b)
Reads up to b.length bytes of data
from this stream into an array of bytes.
|
int |
read(byte[] b,
int off,
int len)
Reads up to len bytes of data from this stream into an array of bytes.
|
int |
read(ByteBuffer buf)
Reads up to buffer.capacity() bytes of data
from this stream into a ByteBuffer.
|
int |
read(ByteBuffer buf,
int off,
int len)
Reads up to len bytes of data from this stream into a ByteBuffer.
|
boolean |
readBoolean() |
byte |
readByte() |
char |
readChar() |
double |
readDouble() |
float |
readFloat() |
void |
readFully(byte[] b) |
void |
readFully(byte[] b,
int off,
int len) |
int |
readInt() |
String |
readLine() |
long |
readLong() |
short |
readShort() |
int |
readUnsignedByte() |
int |
readUnsignedShort() |
String |
readUTF() |
void |
seek(long pos)
Sets the stream pointer offset, measured from the beginning
of this stream, at which the next read or write occurs.
|
static void |
setDefaultBufferSize(int size)
Set the default buffer size for read-only files.
|
static void |
setDefaultReadWriteBufferSize(int size)
Set the default buffer size for read/write files.
|
void |
setLength(long length)
Sets the new length of the handle.
|
void |
setOrder(ByteOrder order)
Sets the byte order (endianness) of the stream.
|
int |
skipBytes(int n) |
long |
skipBytes(long n)
A
long variant of DataInput.skipBytes(int). |
void |
write(byte[] b) |
void |
write(byte[] b,
int off,
int len) |
void |
write(ByteBuffer buf)
Writes up to buffer.capacity() bytes of data from the given
ByteBuffer to this stream.
|
void |
write(ByteBuffer buf,
int off,
int len)
Writes up to len bytes of data from the given ByteBuffer to this
stream.
|
void |
write(int b) |
void |
writeBoolean(boolean v) |
void |
writeByte(int v) |
void |
writeBytes(String s) |
void |
writeChar(int v) |
void |
writeChars(String s) |
void |
writeDouble(double v) |
void |
writeFloat(float v) |
void |
writeInt(int v) |
void |
writeLong(long v) |
void |
writeShort(int v) |
void |
writeUTF(String str) |
exists, validateLength, validateModeprotected static int defaultBufferSize
protected static int defaultRWBufferSize
protected RandomAccessFile raf
protected FileChannel channel
protected long position
protected long bufferStartPosition
protected int bufferSize
protected ByteBuffer buffer
protected boolean isReadWrite
protected FileChannel.MapMode mapMode
protected ByteOrder order
protected NIOByteBufferProvider byteBufferProvider
public NIOFileHandle(File file, String mode, int bufferSize) throws IOException
file - a File representing a file on diskmode - the access mode; r (read only) and
rw (read/write) are supportedbufferSize - the size of the buffer used to speed up reading
and writingIOException - if there is an error accessing the filepublic NIOFileHandle(File file, String mode) throws IOException
file - a File representing a file on diskmode - the access mode; r (read only) and
rw (read/write) are supportedIOException - if there is an error accessing the filepublic NIOFileHandle(String name, String mode) throws IOException
name - the path to a file on diskmode - the access mode; r (read only) and
rw (read/write) are supportedIOException - if there is an error accessing the filepublic static void setDefaultBufferSize(int size)
size - the new default buffer sizepublic static void setDefaultReadWriteBufferSize(int size)
size - the new default buffer sizepublic RandomAccessFile getRandomAccessFile()
public FileChannel getFileChannel()
public int getBufferSize()
public void setLength(long length)
throws IOException
AbstractNIOHandlesetLength in class AbstractNIOHandlelength - New length.IOException - If there is an error changing the handle's length.public void close()
throws IOException
IRandomAccessIOException - if the underlying stream(s) could not be closedpublic long getFilePointer()
IRandomAccesspublic long length()
throws IOException
IRandomAccessIOException - if the length cannot be retrievedpublic ByteOrder getOrder()
IRandomAccesspublic void setOrder(ByteOrder order)
IRandomAccessorder - Order to set.public int read(byte[] b)
throws IOException
IRandomAccessb - the array to fill from this streamIOException - if reading is not possiblepublic int read(byte[] b,
int off,
int len)
throws IOException
IRandomAccessb - the array to fill from this streamoff - the offset in b from which to start filling;
expected to be non-negative and no greater than
b.length - lenlen - the number of bytes to read; expected to be positive and
no greater than b.length - offsetIOException - if reading is not possiblepublic int read(ByteBuffer buf) throws IOException
IRandomAccessbuf - the ByteBuffer to fill from this streamIOException - if reading is not possiblepublic int read(ByteBuffer buf, int off, int len) throws IOException
IRandomAccessbuf - the ByteBuffer to fill from this streamoff - the offset in b from which to start filling;
expected to be non-negative and no greater than
buffer.capacity() - lenlen - the number of bytes to read; expected to be positive and
no greater than buffer.capacity() - offsetIOException - if reading is not possiblepublic void seek(long pos)
throws IOException
IRandomAccesspos - new byte offset (pointer) in the current stream.
Unless otherwise noted, may be larger or smaller than the
current pointer, but must be non-negative and less than the
value of #length()IOException - if pos is invalid or the seek failsIRandomAccess.getFilePointer()public boolean readBoolean()
throws IOException
IOExceptionpublic byte readByte()
throws IOException
IOExceptionpublic char readChar()
throws IOException
IOExceptionpublic double readDouble()
throws IOException
IOExceptionpublic float readFloat()
throws IOException
IOExceptionpublic void readFully(byte[] b)
throws IOException
IOExceptionpublic void readFully(byte[] b,
int off,
int len)
throws IOException
IOExceptionpublic int readInt()
throws IOException
IOExceptionpublic String readLine() throws IOException
IOExceptionpublic long readLong()
throws IOException
IOExceptionpublic short readShort()
throws IOException
IOExceptionpublic int readUnsignedByte()
throws IOException
IOExceptionpublic int readUnsignedShort()
throws IOException
IOExceptionpublic String readUTF() throws IOException
IOExceptionpublic int skipBytes(int n)
throws IOException
IOExceptionpublic long skipBytes(long n)
throws IOException
IRandomAccesslong variant of DataInput.skipBytes(int).n - the number of bytes to skipIOException - if the operation failedpublic void write(byte[] b)
throws IOException
IOExceptionpublic void write(byte[] b,
int off,
int len)
throws IOException
IOExceptionpublic void write(ByteBuffer buf) throws IOException
IRandomAccessbuf - the ByteBuffer containing bytes to write to this streamIOException - if writing is not possiblepublic void write(ByteBuffer buf, int off, int len) throws IOException
IRandomAccessbuf - the ByteBuffer containing bytes to write to this streamoff - the offset in b from which to start writing;
expected to be non-negative and no greater than
buf.capacity() - lenlen - the number of bytes to write; expected to be positive and
no greater than buf.capacity() - offsetIOException - if writing is not possiblepublic void write(int b)
throws IOException
IOExceptionpublic void writeBoolean(boolean v)
throws IOException
IOExceptionpublic void writeByte(int v)
throws IOException
IOExceptionpublic void writeBytes(String s) throws IOException
IOExceptionpublic void writeChar(int v)
throws IOException
IOExceptionpublic void writeChars(String s) throws IOException
IOExceptionpublic void writeDouble(double v)
throws IOException
IOExceptionpublic void writeFloat(float v)
throws IOException
IOExceptionpublic void writeInt(int v)
throws IOException
IOExceptionpublic void writeLong(long v)
throws IOException
IOExceptionpublic void writeShort(int v)
throws IOException
IOExceptionpublic void writeUTF(String str) throws IOException
IOExceptionCopyright © 2005–2024 Open Microscopy Environment. All rights reserved.