public class NIOFileHandle extends AbstractNIOHandle
IRandomAccess,
RandomAccessFile| Modifier and Type | Field and Description |
|---|---|
protected java.nio.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 java.nio.channels.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 java.nio.channels.FileChannel.MapMode |
mapMode
The default map mode for the file.
|
protected java.nio.ByteOrder |
order
The buffer's byte ordering.
|
protected long |
position
The absolute position within the file.
|
protected java.io.RandomAccessFile |
raf
The random access file object backing this FileHandle.
|
EOF_ERROR_MSG| Constructor and Description |
|---|
NIOFileHandle(java.io.File file,
java.lang.String mode)
Creates a random access file stream to read from, and
optionally to write to, the file specified by the File argument.
|
NIOFileHandle(java.io.File file,
java.lang.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(java.lang.String name,
java.lang.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()
Gets the current buffer size.
|
java.nio.channels.FileChannel |
getFileChannel()
Gets the FileChannel from this FileHandle.
|
long |
getFilePointer()
Returns the current offset in this stream.
|
java.nio.ByteOrder |
getOrder()
Returns the current order of the stream.
|
java.io.RandomAccessFile |
getRandomAccessFile()
Gets the random access file object backing this FileHandle.
|
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(java.nio.ByteBuffer buf)
Reads up to buffer.capacity() bytes of data
from this stream into a ByteBuffer.
|
int |
read(java.nio.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() |
java.lang.String |
readLine() |
long |
readLong() |
short |
readShort() |
int |
readUnsignedByte() |
int |
readUnsignedShort() |
java.lang.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(java.nio.ByteOrder order)
Sets the byte order of the stream.
|
int |
skipBytes(int n) |
void |
write(byte[] b) |
void |
write(byte[] b,
int off,
int len) |
void |
write(java.nio.ByteBuffer buf)
Writes up to buffer.capacity() bytes of data from the given
ByteBuffer to this stream.
|
void |
write(java.nio.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(java.lang.String s) |
void |
writeChar(int v) |
void |
writeChars(java.lang.String s) |
void |
writeDouble(double v) |
void |
writeFloat(float v) |
void |
writeInt(int v) |
void |
writeLong(long v) |
void |
writeShort(int v) |
void |
writeUTF(java.lang.String str) |
validateLength, validateModeprotected static int defaultBufferSize
protected static int defaultRWBufferSize
protected java.io.RandomAccessFile raf
protected java.nio.channels.FileChannel channel
protected long position
protected long bufferStartPosition
protected int bufferSize
protected java.nio.ByteBuffer buffer
protected boolean isReadWrite
protected java.nio.channels.FileChannel.MapMode mapMode
protected java.nio.ByteOrder order
protected NIOByteBufferProvider byteBufferProvider
public NIOFileHandle(java.io.File file,
java.lang.String mode,
int bufferSize)
throws java.io.IOException
java.io.IOExceptionpublic NIOFileHandle(java.io.File file,
java.lang.String mode)
throws java.io.IOException
java.io.IOExceptionpublic NIOFileHandle(java.lang.String name,
java.lang.String mode)
throws java.io.IOException
java.io.IOExceptionpublic static void setDefaultBufferSize(int size)
public static void setDefaultReadWriteBufferSize(int size)
public java.io.RandomAccessFile getRandomAccessFile()
public java.nio.channels.FileChannel getFileChannel()
public int getBufferSize()
public void setLength(long length)
throws java.io.IOException
AbstractNIOHandlesetLength in class AbstractNIOHandlelength - New length.java.io.IOException - If there is an error changing the handle's length.public void close()
throws java.io.IOException
IRandomAccessjava.io.IOExceptionpublic long getFilePointer()
IRandomAccesspublic long length()
throws java.io.IOException
IRandomAccessjava.io.IOExceptionpublic java.nio.ByteOrder getOrder()
IRandomAccesspublic void setOrder(java.nio.ByteOrder order)
IRandomAccessorder - Order to set.public int read(byte[] b)
throws java.io.IOException
IRandomAccessjava.io.IOExceptionpublic int read(byte[] b,
int off,
int len)
throws java.io.IOException
IRandomAccessjava.io.IOExceptionpublic int read(java.nio.ByteBuffer buf)
throws java.io.IOException
IRandomAccessjava.io.IOExceptionpublic int read(java.nio.ByteBuffer buf,
int off,
int len)
throws java.io.IOException
IRandomAccessjava.io.IOExceptionpublic void seek(long pos)
throws java.io.IOException
IRandomAccessjava.io.IOExceptionpublic boolean readBoolean()
throws java.io.IOException
java.io.IOExceptionpublic byte readByte()
throws java.io.IOException
java.io.IOExceptionpublic char readChar()
throws java.io.IOException
java.io.IOExceptionpublic double readDouble()
throws java.io.IOException
java.io.IOExceptionpublic float readFloat()
throws java.io.IOException
java.io.IOExceptionpublic void readFully(byte[] b)
throws java.io.IOException
java.io.IOExceptionpublic void readFully(byte[] b,
int off,
int len)
throws java.io.IOException
java.io.IOExceptionpublic int readInt()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String readLine()
throws java.io.IOException
java.io.IOExceptionpublic long readLong()
throws java.io.IOException
java.io.IOExceptionpublic short readShort()
throws java.io.IOException
java.io.IOExceptionpublic int readUnsignedByte()
throws java.io.IOException
java.io.IOExceptionpublic int readUnsignedShort()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String readUTF()
throws java.io.IOException
java.io.IOExceptionpublic int skipBytes(int n)
throws java.io.IOException
java.io.IOExceptionpublic void write(byte[] b)
throws java.io.IOException
java.io.IOExceptionpublic void write(byte[] b,
int off,
int len)
throws java.io.IOException
java.io.IOExceptionpublic void write(java.nio.ByteBuffer buf)
throws java.io.IOException
IRandomAccessjava.io.IOExceptionpublic void write(java.nio.ByteBuffer buf,
int off,
int len)
throws java.io.IOException
IRandomAccessjava.io.IOExceptionpublic void write(int b)
throws java.io.IOException
java.io.IOExceptionpublic void writeBoolean(boolean v)
throws java.io.IOException
java.io.IOExceptionpublic void writeByte(int v)
throws java.io.IOException
java.io.IOExceptionpublic void writeBytes(java.lang.String s)
throws java.io.IOException
java.io.IOExceptionpublic void writeChar(int v)
throws java.io.IOException
java.io.IOExceptionpublic void writeChars(java.lang.String s)
throws java.io.IOException
java.io.IOExceptionpublic void writeDouble(double v)
throws java.io.IOException
java.io.IOExceptionpublic void writeFloat(float v)
throws java.io.IOException
java.io.IOExceptionpublic void writeInt(int v)
throws java.io.IOException
java.io.IOExceptionpublic void writeLong(long v)
throws java.io.IOException
java.io.IOExceptionpublic void writeShort(int v)
throws java.io.IOException
java.io.IOExceptionpublic void writeUTF(java.lang.String str)
throws java.io.IOException
java.io.IOExceptionCopyright © 2014 Open Microscopy Environment