public final class NioFile extends Object implements Closeable
thread
interrupts. In case the file channel that is used by this class is closed due to such an event, it will try to
reopen the channel. The thread that causes the ClosedByInterruptException is not protected, assuming the
interrupt is intended to end the thread's operation.| Constructor and Description |
|---|
NioFile(File file)
Constructor Opens a file in read/write mode, creating a new one if the file doesn't exist.
|
NioFile(File file,
String mode)
Constructor Opens a file in a specific mode, creating a new one if the file doesn't exist.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
boolean |
delete()
Close any open channels and then deletes the file.
|
void |
force(boolean metaData)
Performs a protected
FileChannel.force(boolean) call. |
File |
getFile() |
boolean |
isClosed()
Check if a file was closed explicitly.
|
int |
read(ByteBuffer buf,
long offset)
Performs a protected
FileChannel.read(ByteBuffer, long) call. |
byte |
readByte(long offset)
Read single byte from channel starting at offset.
|
byte[] |
readBytes(long offset,
int length)
Read a byte array of a specific length from channel starting at offset.
|
int |
readInt(long offset)
Read integer value from channel starting at offset.
|
long |
readLong(long offset)
Read long value from channel starting at offset.
|
long |
size()
Performs a protected
FileChannel.size() call. |
long |
transferTo(long position,
long count,
WritableByteChannel target)
Performs a protected
FileChannel.transferTo(long, long, WritableByteChannel) call. |
void |
truncate(long size)
Performs a protected
FileChannel.truncate(long) call. |
int |
write(ByteBuffer buf,
long offset)
Performs a protected
FileChannel.write(ByteBuffer, long) call. |
void |
writeByte(byte value,
long offset)
Write single byte to channel starting at offset.
|
void |
writeBytes(byte[] value,
long offset)
Write byte array to channel starting at offset.
|
void |
writeInt(int value,
long offset)
Write integer value to channel starting at offset.
|
void |
writeLong(long value,
long offset)
Write long value to channel starting at offset.
|
public NioFile(File file) throws IOException
file - IOExceptionpublic NioFile(File file, String mode) throws IOException
file - filemode - file modeIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic boolean isClosed()
public File getFile()
public boolean delete()
throws IOException
IOException - If there was a problem closing the open file channel.public void force(boolean metaData)
throws IOException
FileChannel.force(boolean) call.metaData - IOExceptionpublic void truncate(long size)
throws IOException
FileChannel.truncate(long) call.size - IOExceptionpublic long size()
throws IOException
FileChannel.size() call.IOExceptionpublic long transferTo(long position,
long count,
WritableByteChannel target)
throws IOException
FileChannel.transferTo(long, long, WritableByteChannel) call.position - position within the filecount - number of bytes to transfertarget - target channelIOExceptionpublic int write(ByteBuffer buf, long offset) throws IOException
FileChannel.write(ByteBuffer, long) call.buf - bufferoffset - non-negative offsetIOExceptionpublic int read(ByteBuffer buf, long offset) throws IOException
FileChannel.read(ByteBuffer, long) call.buf - buffer to readoffset - non-negative offsetIOExceptionpublic void writeBytes(byte[] value,
long offset)
throws IOException
value - byte array to writeoffset - non-negative offsetIOExceptionpublic byte[] readBytes(long offset,
int length)
throws IOException
offset - length - IOExceptionpublic void writeByte(byte value,
long offset)
throws IOException
value - value to writeoffset - non-negative offsetIOExceptionpublic byte readByte(long offset)
throws IOException
offset - non-negative offsetIOExceptionpublic void writeLong(long value,
long offset)
throws IOException
value - value to writeoffset - non-negative offsetIOExceptionpublic long readLong(long offset)
throws IOException
offset - non-negative offsetIOExceptionpublic void writeInt(int value,
long offset)
throws IOException
value - value to writeoffset - non-negative offsetIOExceptionpublic int readInt(long offset)
throws IOException
offset - non-negative offsetIOExceptionCopyright © 2015-2020 Eclipse Foundation. All Rights Reserved.