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
- IOException
public NioFile(File file, String mode) throws IOException
file
- filemode
- file modeIOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public 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
- IOException
public void truncate(long size) throws IOException
FileChannel.truncate(long)
call.size
- IOException
public long size() throws IOException
FileChannel.size()
call.IOException
public 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 channelIOException
public int write(ByteBuffer buf, long offset) throws IOException
FileChannel.write(ByteBuffer, long)
call.buf
- bufferoffset
- non-negative offsetIOException
public int read(ByteBuffer buf, long offset) throws IOException
FileChannel.read(ByteBuffer, long)
call.buf
- buffer to readoffset
- non-negative offsetIOException
public void writeBytes(byte[] value, long offset) throws IOException
value
- byte array to writeoffset
- non-negative offsetIOException
public byte[] readBytes(long offset, int length) throws IOException
offset
- length
- IOException
public void writeByte(byte value, long offset) throws IOException
value
- value to writeoffset
- non-negative offsetIOException
public byte readByte(long offset) throws IOException
offset
- non-negative offsetIOException
public void writeLong(long value, long offset) throws IOException
value
- value to writeoffset
- non-negative offsetIOException
public long readLong(long offset) throws IOException
offset
- non-negative offsetIOException
public void writeInt(int value, long offset) throws IOException
value
- value to writeoffset
- non-negative offsetIOException
public int readInt(long offset) throws IOException
offset
- non-negative offsetIOException
Copyright © 2015-2020 Eclipse Foundation. All Rights Reserved.