Interface FileIO
-
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
AbstractFileIO,AsyncFileIO,BufferedFileIO,EncryptedFileIO,FileIODecorator,RandomAccessFileIO,SegmentIO,UnzipFileIO,WriteOnlyZipFileIO
public interface FileIO extends AutoCloseable
Interface to perform file I/O operations.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidclear()Truncates current file to zero length and resets current file position to zero.voidclose()Closes current file.voidforce()Forces any updates of this file to be written to the storage device that contains it.voidforce(boolean withMetadata)Forces any updates of this file to be written to the storage device that contains it.intgetFileSystemBlockSize()longgetSparseSize()MappedByteBuffermap(int sizeBytes)Allocates memory mapped buffer for this file with given size.longposition()Returns current file position.voidposition(long newPosition)Sets new current file position.intpunchHole(long position, int len)intread(byte[] buf, int off, int len)Reads a up tolengthbytes from this file into thebuffer.intread(ByteBuffer destBuf)Reads a sequence of bytes from this file into thedestinationBuffer.intread(ByteBuffer destBuf, long position)Reads a sequence of bytes from this file into thedestinationBufferstarting from specified fileposition.intreadFully(byte[] buf, int off, int len)Reads a up tolengthbytes from this file into thebuffer.intreadFully(ByteBuffer destBuf)Reads a sequence of bytes from this file into thedestinationBuffer.intreadFully(ByteBuffer destBuf, long position)Reads a sequence of bytes from this file into thedestinationBufferstarting from specified fileposition.longsize()Returns current file size in bytes.default longtransferFrom(ReadableByteChannel src, long position, long count)default longtransferTo(long position, long count, WritableByteChannel target)This method will transfers the content of file to the specified channel.intwrite(byte[] buf, int off, int len)Writeslengthbytes from thebufferstarting at offsetoffto this file.intwrite(ByteBuffer srcBuf)Writes a sequence of bytes to this file from thesourceBuffer.intwrite(ByteBuffer srcBuf, long position)Writes a sequence of bytes to this file from thesourceBufferstarting from specified filepositionintwriteFully(byte[] buf, int off, int len)Writeslengthbytes from thebufferstarting at offsetoffto this file.intwriteFully(ByteBuffer srcBuf)Writes a sequence of bytes to this file from thesourceBuffer.intwriteFully(ByteBuffer srcBuf, long position)Writes a sequence of bytes to this file from thesourceBufferstarting from specified fileposition
-
-
-
Method Detail
-
position
long position() throws IOExceptionReturns current file position.- Returns:
- Current file position, a non-negative integer counting the number of bytes from the beginning of the file to the current position.
- Throws:
IOException- If some I/O error occurs.
-
position
void position(long newPosition) throws IOExceptionSets new current file position.- Parameters:
newPosition- The new position, a non-negative integer counting the number of bytes from the beginning of the file.- Throws:
IOException- If some I/O error occurs.
-
read
int read(ByteBuffer destBuf) throws IOException
Reads a sequence of bytes from this file into thedestinationBuffer.- Parameters:
destBuf- Destination byte buffer.- Returns:
- Number of read bytes, or -1 if the given position is greater than or equal to the file's current size
- Throws:
IOException- If some I/O error occurs.
-
readFully
int readFully(ByteBuffer destBuf) throws IOException
Reads a sequence of bytes from this file into thedestinationBuffer.- Parameters:
destBuf- Destination byte buffer.- Returns:
- Number of written bytes.
- Throws:
IOException- If some I/O error occurs.
-
read
int read(ByteBuffer destBuf, long position) throws IOException
Reads a sequence of bytes from this file into thedestinationBufferstarting from specified fileposition.- Parameters:
destBuf- Destination byte buffer.position- Starting position of file.- Returns:
- Number of read bytes, possibly zero, or -1 if the given position is greater than or equal to the file's current size
- Throws:
IOException- If some I/O error occurs.
-
readFully
int readFully(ByteBuffer destBuf, long position) throws IOException
Reads a sequence of bytes from this file into thedestinationBufferstarting from specified fileposition.- Parameters:
destBuf- Destination byte buffer.position- Starting position of file.- Returns:
- Number of written bytes.
- Throws:
IOException- If some I/O error occurs.
-
read
int read(byte[] buf, int off, int len) throws IOExceptionReads a up tolengthbytes from this file into thebuffer.- Parameters:
buf- Destination byte array.off- The start offset in arraybat which the data is written.len- Maximum number of bytes read.- Returns:
- Number of read bytes.
- Throws:
IOException- If some I/O error occurs.
-
readFully
int readFully(byte[] buf, int off, int len) throws IOExceptionReads a up tolengthbytes from this file into thebuffer.- Parameters:
buf- Destination byte array.off- The start offset in arraybat which the data is written.len- Number of bytes read.- Returns:
- Number of written bytes.
- Throws:
IOException- If some I/O error occurs.
-
write
int write(ByteBuffer srcBuf) throws IOException
Writes a sequence of bytes to this file from thesourceBuffer.- Parameters:
srcBuf- Source buffer.- Returns:
- Number of written bytes.
- Throws:
IOException- If some I/O error occurs.
-
writeFully
int writeFully(ByteBuffer srcBuf) throws IOException
Writes a sequence of bytes to this file from thesourceBuffer.- Parameters:
srcBuf- Source buffer.- Returns:
- Number of written bytes.
- Throws:
IOException- If some I/O error occurs.
-
write
int write(ByteBuffer srcBuf, long position) throws IOException
Writes a sequence of bytes to this file from thesourceBufferstarting from specified fileposition- Parameters:
srcBuf- Source buffer.position- Starting file position.- Returns:
- Number of written bytes.
- Throws:
IOException- If some I/O error occurs.
-
writeFully
int writeFully(ByteBuffer srcBuf, long position) throws IOException
Writes a sequence of bytes to this file from thesourceBufferstarting from specified fileposition- Parameters:
srcBuf- Source buffer.position- Starting file position.- Returns:
- Number of written bytes.
- Throws:
IOException- If some I/O error occurs.
-
write
int write(byte[] buf, int off, int len) throws IOExceptionWriteslengthbytes from thebufferstarting at offsetoffto this file.- Parameters:
buf- Source byte array.off- Start offset in thebuffer.len- Number of bytes to write.- Returns:
- Number of written bytes.
- Throws:
IOException- If some I/O error occurs.
-
writeFully
int writeFully(byte[] buf, int off, int len) throws IOExceptionWriteslengthbytes from thebufferstarting at offsetoffto this file.- Parameters:
buf- Source byte array.off- Start offset in thebuffer.len- Number of bytes to write.- Returns:
- Number of written bytes.
- Throws:
IOException- If some I/O error occurs.
-
map
MappedByteBuffer map(int sizeBytes) throws IOException
Allocates memory mapped buffer for this file with given size.- Parameters:
sizeBytes- Size of buffer.- Returns:
- Instance of mapped byte buffer.
- Throws:
IOException- If some I/O error occurs.
-
force
void force() throws IOExceptionForces any updates of this file to be written to the storage device that contains it.- Throws:
IOException- If some I/O error occurs.
-
force
void force(boolean withMetadata) throws IOExceptionForces any updates of this file to be written to the storage device that contains it.- Parameters:
withMetadata- Iftrueforce also file metadata.- Throws:
IOException- If some I/O error occurs.
-
size
long size() throws IOException
Returns current file size in bytes.- Returns:
- File size.
- Throws:
IOException- If some I/O error occurs.
-
clear
void clear() throws IOExceptionTruncates current file to zero length and resets current file position to zero.- Throws:
IOException- If some I/O error occurs.
-
close
void close() throws IOExceptionCloses current file.- Specified by:
closein interfaceAutoCloseable- Throws:
IOException- If some I/O error occurs.
-
getFileSystemBlockSize
int getFileSystemBlockSize()
- Returns:
- File system block size or negative value if unknown.
-
punchHole
int punchHole(long position, int len)- Parameters:
position- Starting file position.len- Number of bytes to free.- Returns:
- The actual freed size or negative value if not supported.
-
getSparseSize
long getSparseSize()
- Returns:
- Approximate system dependent size of the storage or negative value if not supported.
- See Also:
punchHole(long, int)
-
transferTo
default long transferTo(long position, long count, WritableByteChannel target) throws IOExceptionThis method will transfers the content of file to the specified channel. This is a synchronous operation, so performing it on asynchronous channels makes no sense and not provied.- Parameters:
position- The relative offset of the file where the transfer begins from.count- The number of bytes to be transferred.target- Destination channel of the transfer.- Returns:
- Count of bytes which was successfully transferred.
- Throws:
IOException- If fails.
-
transferFrom
default long transferFrom(ReadableByteChannel src, long position, long count) throws IOException
- Parameters:
src- The source channel.position- The position within the file at which the transfer is to begin.count- The maximum number of bytes to be transferred.- Returns:
- The number of bytes, possibly zero, that were actually transferred.
- Throws:
IOException- If fails.
-
-