- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
ByteBuffers, and strings at both the current
file position and at explicit (random-access) file positions.
The buffer is used for both reading and writing. Sequential read and write operations advance the file position; random-access operations (those accepting an explicit position parameter) do not. The default byte order is configurable and may be changed during the lifetime of the file; explicit little-endian and big-endian method variants are also provided.
Thread safety
This class uses a lightweight compare-and-swap lock to detect illegal concurrent access. If two threads attempt to use the same instance concurrently, the second thread will receive anIllegalStateException. Re-entrant calls from the same thread are permitted
(the lock is recursive within a single thread).
Stream and channel views
TheinputStream() and outputStream() methods return cached views that
extend FileInputStream and FileOutputStream respectively and also implement
DataInput and DataOutput (with the big-endian semantics mandated by those
interfaces, independent of this file's configured byte order). The channel() method
returns a cached FileChannel view.
The input and output stream views share a single file position with this
BufferedFile, so mixing their usage may produce unexpected results unless the
shared position is explicitly considered.
Calling close() on any view is a no-op; closing the
BufferedFile itself closes all views.
Append mode
Append mode is not supported by this API.File descriptor and buffering caveats
The file descriptor is exposed for advanced use, but directly accessing or modifying the file position through the file descriptor will result in inconsistent behavior. Furthermore, the backing file may not reflect buffered data that has not yet been flushed.Byte order
The byte order used by methods on this class is the configurable default (or the explicit LE/BE variant). This differs from theDataInput/DataOutput methods on the
stream views, which always use big-endian per their contract. The
writeFloat(float)/writeDouble(double) methods use raw bit patterns
(Float.floatToRawIntBits(float), Double.doubleToRawLongBits(double)), preserving NaN
payloads.
Buffer boundary behavior
Random-access operations that partially overlap the buffer boundary are decomposed into smaller sub-operations; this is a rare edge case and not a performance concern in practice.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal classAFileChannelview that delegates to the enclosingBufferedFile, maintaining buffer consistency for all read/write/position operations.final classAnInputStreamview that extendsFileInputStreamand implementsDataInputwith big-endian semantics.final classAnOutputStreamview that extendsFileOutputStreamand implementsDataOutputwith big-endian semantics. -
Method Summary
Modifier and TypeMethodDescriptionReturns the current default byte order.voidSet the default byte order.channel()Returns a cachedFileChannelview of this file.voidclose()Flush any buffered data and close this file.Returns the file descriptor for this file.longReturns the current file position.intfill(int bytes) Attempt to fill the buffer with at leastbytesbytes of data.voidflush()Flush any buffered data to the file.Returns a cachedFileInputStreamview of this file.longlength()Returns the current file length, including any buffered but unflushed data.Create a nested view of this file starting at the current file position.openNested(Closeable closeAction) Create a nested view of this file starting at the current file position.Returns a cachedFileOutputStreamview of this file.intpeek()Read a single byte at the current position without advancing.bytepeekByte()Read a single byte at the current position without advancing.intpeekInt()Read a 32-bit value at the current position using the default byte order without advancing.intRead a 32-bit value at the current position using big-endian byte order without advancing.intRead a 32-bit value at the current position using little-endian byte order without advancing.longpeekLong()Read a 64-bit value at the current position using the default byte order without advancing.longRead a 64-bit value at the current position using big-endian byte order without advancing.longRead a 64-bit value at the current position using little-endian byte order without advancing.shortRead a 16-bit value at the current position using the default byte order without advancing.shortRead a 16-bit value at the current position using big-endian byte order without advancing.shortRead a 16-bit value at the current position using little-endian byte order without advancing.intRead a single unsigned byte at the current position without advancing.longRead a 32-bit unsigned value at the current position using the default byte order without advancing.longRead a 32-bit unsigned value at the current position using big-endian byte order without advancing.longRead a 32-bit unsigned value at the current position using little-endian byte order without advancing.intRead an unsigned 16-bit value at the current position using the default byte order without advancing.intRead an unsigned 16-bit value at the current position using big-endian byte order without advancing.intRead an unsigned 16-bit value at the current position using little-endian byte order without advancing.intread()Read a single byte at the current position and advance.intread(byte[] dest) Read bytes into the given array at the current position and advance.intread(byte[] dest, int offset, int length) Read bytes into the given array at the current position and advance.intread(long pos, byte[] dest) Read bytes at the given file position without changing the current position.intread(long pos, byte[] dest, int offset, int length) Read bytes at the given file position without changing the current position.intread(long pos, ByteBuffer dest) Read into the given ByteBuffer at the given file position without changing the current position.intread(ByteBuffer dest) Read into the given ByteBuffer at the current position and advance.booleanRead a boolean value (1 byte: 0 for false, non-zero for true) and advance.booleanreadBoolean(long pos) Read a boolean value at the given file position without advancing the current position.bytereadByte()Read a single byte at the current position and advance.bytereadByte(long pos) Read a single byte at the given file position without changing the current position.charreadChar()Read a 16-bit char at the current position using the default byte order and advance.charreadChar(long pos) Read a 16-bit character value at the given file position using the default byte order without advancing the current position.charRead a 16-bit character value at the current position using big-endian byte order and advance.charreadCharBE(long pos) Read a 16-bit character value at the given file position using big-endian byte order without advancing the current position.charRead a 16-bit character value at the current position using little-endian byte order and advance.charreadCharLE(long pos) Read a 16-bit character value at the given file position using little-endian byte order without advancing the current position.doubleRead a 64-bit floating-point value using raw bit patterns at the current position using the default byte order and advance.doublereadDouble(long pos) Read a 64-bit floating-point value using raw bit patterns at the given file position using the default byte order without advancing the current position.doubleRead a 64-bit floating-point value using raw bit patterns at the current position using big-endian byte order and advance.doublereadDoubleBE(long pos) Read a 64-bit floating-point value using raw bit patterns at the given file position using big-endian byte order without advancing the current position.doubleRead a 64-bit floating-point value using raw bit patterns at the current position using little-endian byte order and advance.doublereadDoubleLE(long pos) Read a 64-bit floating-point value using raw bit patterns at the given file position using little-endian byte order without advancing the current position.floatRead a 32-bit floating-point value using raw bit patterns at the current position using the default byte order and advance.floatreadFloat(long pos) Read a 32-bit floating-point value using raw bit patterns at the given file position using the default byte order without advancing the current position.floatRead a 32-bit floating-point value using raw bit patterns at the current position using big-endian byte order and advance.floatreadFloatBE(long pos) Read a 32-bit floating-point value using raw bit patterns at the given file position using big-endian byte order without advancing the current position.floatRead a 32-bit floating-point value using raw bit patterns at the current position using little-endian byte order and advance.floatreadFloatLE(long pos) Read a 32-bit floating-point value using raw bit patterns at the given file position using little-endian byte order without advancing the current position.voidreadFully(byte[] dest) Read exactlydest.lengthbytes from the current position into the given array and advance.voidreadFully(byte[] dest, int offset, int length) Read exactlylengthbytes at the current position and advance.intreadInt()Read a 32-bit value at the current position using the default byte order and advance.intreadInt(long pos) Read a 32-bit value at the given file position using the default byte order without advancing the current position.intRead a 32-bit value at the current position using big-endian byte order and advance.intreadIntBE(long pos) Read a 32-bit value at the given file position using big-endian byte order without advancing the current position.intRead a 32-bit value at the current position using little-endian byte order and advance.intreadIntLE(long pos) Read a 32-bit value at the given file position using little-endian byte order without advancing the current position.longreadLong()Read a 64-bit value at the current position using the default byte order and advance.longreadLong(long pos) Read a 64-bit value at the given file position using the default byte order without advancing the current position.longRead a 64-bit value at the current position using big-endian byte order and advance.longreadLongBE(long pos) Read a 64-bit value at the given file position using big-endian byte order without advancing the current position.longRead a 64-bit value at the current position using little-endian byte order and advance.longreadLongLE(long pos) Read a 64-bit value at the given file position using little-endian byte order without advancing the current position.shortRead a 16-bit value at the current position using the default byte order and advance.shortreadShort(long pos) Read a 16-bit value at the given file position using the default byte order without changing the current position.shortRead a 16-bit value at the current position using big-endian byte order and advance.shortreadShortBE(long pos) Read a 16-bit value at the given file position using big-endian byte order without advancing the current position.shortRead a 16-bit value at the current position using little-endian byte order and advance.shortreadShortLE(long pos) Read a 16-bit value at the given file position using little-endian byte order without advancing the current position.readString(int byteLength) Read a fixed number of bytes and decode as a UTF-8 string.readString(int byteLength, Charset charset) Read a fixed number of bytes and decode as a string using the given charset.intRead a single unsigned byte at the current position and advance.intreadUnsignedByte(long pos) Read a single unsigned byte at the given file position without changing the current position.longRead a 32-bit unsigned value at the current position using the default byte order and advance.longreadUnsignedInt(long pos) Read an unsigned 32-bit value at the given file position using the default byte order without changing the current position.longRead a 32-bit unsigned value at the current position using big-endian byte order and advance.longreadUnsignedIntBE(long pos) Read an unsigned 32-bit value at the given file position using big-endian byte order without advancing the current position.longRead a 32-bit unsigned value at the current position using little-endian byte order and advance.longreadUnsignedIntLE(long pos) Read an unsigned 32-bit value at the given file position using little-endian byte order without advancing the current position.intRead an unsigned 16-bit value at the current position using the default byte order and advance.intreadUnsignedShort(long pos) Read an unsigned 16-bit value at the given file position using the default byte order without changing the current position.intRead an unsigned 16-bit value at the current position using big-endian byte order and advance.intreadUnsignedShortBE(long pos) Read an unsigned 16-bit value at the given file position using big-endian byte order without advancing the current position.intRead an unsigned 16-bit value at the current position using little-endian byte order and advance.intreadUnsignedShortLE(long pos) Read an unsigned 16-bit value at the given file position using little-endian byte order without advancing the current position.Read a zero-terminated UTF-8 string and advance past the terminator.readZeroTerminatedString(Charset charset) Read a zero-terminated string using the given charset and advance past the terminator.longReturns the number of bytes between the current position and the end of the file.voidseek(long position) Set the file position.voidsetLength(long newLength) Set the length of the file.longskip(long count) Skip forward by the given number of bytes.longtransferFrom(long pos, InputStream in, long length) Transfer bytes from the given input stream to the given file position without changing the current position.longTransfer all bytes from the given input stream to the current position.longtransferFrom(InputStream in, long length) Transfer up tolengthbytes from the given input stream to the current position.longtransferTo(long pos, OutputStream out, long length) Transfer bytes from the given file position to the output stream without changing the current position.longtransferTo(OutputStream out) Transfer all remaining bytes from the current position to the given output stream.longtransferTo(OutputStream out, long length) Transfer up tolengthbytes from the current position to the given output stream.voidwrite(byte[] src) Write all bytes from the given array to the current position and advance.voidwrite(byte[] src, int offset, int length) Write bytes from the given array at the current position and advance.voidwrite(long pos, byte[] src, int offset, int length) Write bytes at the given file position without changing the current position.intwrite(long pos, ByteBuffer src) Write from the given ByteBuffer at the given file position without changing the current position.voidwrite(ByteBuffer src) Write from the given ByteBuffer at the current position and advance.voidwriteBoolean(boolean value) Write a boolean value (1 byte: 0 for false, 1 for true) and advance.voidwriteBoolean(long pos, boolean value) Write a boolean value at the given file position without advancing the current position.voidwriteByte(int value) Write a single byte at the current position and advance.voidwriteByte(long pos, int value) Write a single byte at the given file position without changing the current position.voidwriteChar(int value) Write a 16-bit char at the current position using the default byte order and advance.voidwriteChar(long pos, int value) Write a 16-bit character value at the given file position using the default byte order without advancing the current position.voidwriteCharBE(int value) Write a 16-bit character value at the current position using big-endian byte order and advance.voidwriteCharBE(long pos, int value) Write a 16-bit character value at the given file position using big-endian byte order without advancing the current position.voidwriteCharLE(int value) Write a 16-bit character value at the current position using little-endian byte order and advance.voidwriteCharLE(long pos, int value) Write a 16-bit character value at the given file position using little-endian byte order without advancing the current position.voidwriteDouble(double value) Write a 64-bit floating-point value using raw bit patterns at the current position using the default byte order and advance.voidwriteDouble(long pos, double value) Write a 64-bit floating-point value using raw bit patterns at the given file position using the default byte order without advancing the current position.voidwriteDoubleBE(double value) Write a 64-bit floating-point value using raw bit patterns at the current position using big-endian byte order and advance.voidwriteDoubleBE(long pos, double value) Write a 64-bit floating-point value using raw bit patterns at the given file position using big-endian byte order without advancing the current position.voidwriteDoubleLE(double value) Write a 64-bit floating-point value using raw bit patterns at the current position using little-endian byte order and advance.voidwriteDoubleLE(long pos, double value) Write a 64-bit floating-point value using raw bit patterns at the given file position using little-endian byte order without advancing the current position.voidwriteFloat(float value) Write a 32-bit floating-point value using raw bit patterns at the current position using the default byte order and advance.voidwriteFloat(long pos, float value) Write a 32-bit floating-point value using raw bit patterns at the given file position using the default byte order without advancing the current position.voidwriteFloatBE(float value) Write a 32-bit floating-point value using raw bit patterns at the current position using big-endian byte order and advance.voidwriteFloatBE(long pos, float value) Write a 32-bit floating-point value using raw bit patterns at the given file position using big-endian byte order without advancing the current position.voidwriteFloatLE(float value) Write a 32-bit floating-point value using raw bit patterns at the current position using little-endian byte order and advance.voidwriteFloatLE(long pos, float value) Write a 32-bit floating-point value using raw bit patterns at the given file position using little-endian byte order without advancing the current position.voidwriteInt(int value) Write a 32-bit value at the current position using the default byte order and advance.voidwriteInt(long pos, int value) Write a 32-bit value at the given file position using the default byte order without advancing the current position.voidwriteIntBE(int value) Write a 32-bit value at the current position using big-endian byte order and advance.voidwriteIntBE(long pos, int value) Write a 32-bit value at the given file position using big-endian byte order without advancing the current position.voidwriteIntLE(int value) Write a 32-bit value at the current position using little-endian byte order and advance.voidwriteIntLE(long pos, int value) Write a 32-bit value at the given file position using little-endian byte order without advancing the current position.voidwriteLong(long value) Write a 64-bit value at the current position using the default byte order and advance.voidwriteLong(long pos, long value) Write a 64-bit value at the given file position using the default byte order without advancing the current position.voidwriteLongBE(long value) Write a 64-bit value at the current position using big-endian byte order and advance.voidwriteLongBE(long pos, long value) Write a 64-bit value at the given file position using big-endian byte order without advancing the current position.voidwriteLongLE(long value) Write a 64-bit value at the current position using little-endian byte order and advance.voidwriteLongLE(long pos, long value) Write a 64-bit value at the given file position using little-endian byte order without advancing the current position.voidwriteShort(int value) Write a 16-bit value at the current position using the default byte order and advance.voidwriteShort(long pos, int value) Write a 16-bit value at the given file position using the default byte order without changing the current position.voidwriteShortBE(int value) Write a 16-bit value at the current position using big-endian byte order and advance.voidwriteShortBE(long pos, int value) Write a 16-bit value at the given file position using big-endian byte order without advancing the current position.voidwriteShortLE(int value) Write a 16-bit value at the current position using little-endian byte order and advance.voidwriteShortLE(long pos, int value) Write a 16-bit value at the given file position using little-endian byte order without advancing the current position.voidWrite a UTF-8-encoded string (no terminator) and advance.voidwriteString(String s, Charset charset) Write a string encoded with the given charset (no terminator) and advance.voidwriteZeros(long count) Write the given number of zero bytes at the current position and advance.voidwriteZeros(long pos, long count) Write zero bytes at the given file position without changing the current position.voidWrite a UTF-8-encoded string followed by a zero byte and advance.voidwriteZeroTerminatedString(String s, Charset charset) Write a string encoded with the given charset, followed by a zero byte, and advance.
-
Method Details
-
openNested
Create a nested view of this file starting at the current file position. The returned view has its own buffer and position tracking; all positions are relative to the current position at the time of this call. The parent is unusable until the nested view is closed.- Returns:
- the nested view (not
null) - Throws:
IOException- if an I/O error occursIllegalStateException- if a nested view is already active
-
openNested
Create a nested view of this file starting at the current file position. The returned view has its own buffer and position tracking; all positions are relative to the current position at the time of this call. The parent is unusable until the nested view is closed.The optional
closeActionis invoked during the nested view'sclose()after the data is flushed and the parent is unlocked. This allows callers to perform post-processing (such as computing checksums and patching headers) by reading and writing the parent file.- Parameters:
closeAction- an action to invoke when the nested view is closed, ornull- Returns:
- the nested view (not
null) - Throws:
IOException- if an I/O error occursIllegalStateException- if a nested view is already active
-
fill
Attempt to fill the buffer with at leastbytesbytes of data. If a value less thanbytesis returned, then that is the number of bytes that can be read before reaching EOF (at the time of the call).If the buffer has remaining capacity, data is read into the buffer at the current end of valid data, extending the valid region without affecting the dirty state. If the buffer does not have enough remaining space, it is flushed (if dirty) and compacted before reading.
- Parameters:
bytes- the minimum number of bytes to attempt to read (must not be negative, and must be less than the buffer size)- Returns:
- the actual number of bytes currently available in the buffer, or -1 if end-of-file was reached and no bytes could be read
- Throws:
IOException- if an I/O error occurs
-
filePosition
Returns the current file position.- Returns:
- the current file position
- Throws:
IOException- if an I/O error occurs
-
seek
Set the file position.This method does not flush or invalidate the buffer. If the file has been truncated to a length smaller than the given position, subsequent sequential reads will see EOF and subsequent sequential writes will extend the file (with a zero-filled gap, per
RandomAccessFilesemantics).- Parameters:
position- the new file position- Throws:
IOException- if the file is in append mode, or if an I/O error occurs
-
length
Returns the current file length, including any buffered but unflushed data.- Returns:
- the current file length, including any buffered but unflushed data
- Throws:
IOException- if an I/O error occurs
-
remaining
Returns the number of bytes between the current position and the end of the file.- Returns:
- the number of bytes between the current position and the end of the file
- Throws:
IOException- if an I/O error occurs
-
setLength
Set the length of the file.If
newLengthis less than the current length, the file is truncated. The current file position is not automatically adjusted; if it exceeds the new length, subsequent sequential reads will see EOF and sequential writes will extend the file with a zero-filled gap. Callseek(long)to reposition if needed.If the buffer window extends beyond the new length, the valid portion of the buffer is trimmed. If the entire buffer lies beyond the new length, it is invalidated.
If
newLengthis greater than the current length, the file is extended with zero bytes (perRandomAccessFilesemantics).- Parameters:
newLength- the desired file length- Throws:
IOException- if an I/O error occurs
-
skip
Skip forward by the given number of bytes.- Parameters:
count- the number of bytes to skip- Returns:
- the number of bytes actually skipped
- Throws:
IOException- if an I/O error occurs
-
fileDescriptor
Returns the file descriptor for this file.Warning: directly accessing or modifying the file position through this descriptor will result in inconsistent behavior. The backing file may not reflect buffered data that has not yet been flushed, among other potential issues.
- Returns:
- the file descriptor for this file
- Throws:
IOException- if an I/O error occurs
-
byteOrder
Returns the current default byte order.- Returns:
- the current default byte order
-
byteOrder
Set the default byte order.- Parameters:
byteOrder- the new byte order (must not benull)
-
writeByte
Write a single byte at the current position and advance.- Parameters:
value- the byte value (only the low 8 bits are used)- Throws:
IOException- if an I/O error occurs
-
read
Read a single byte at the current position and advance.- Returns:
- the byte value (sign-extended to
int), or -1 at end-of-file - Throws:
IOException- if an I/O error occurs
-
peek
Read a single byte at the current position without advancing.- Returns:
- the byte value (sign-extended to
int), or -1 at end-of-file - Throws:
IOException- if an I/O error occurs
-
readByte
Read a single byte at the current position and advance.- Returns:
- the byte value
- Throws:
EOFException- if end-of-file is reachedIOException- if an I/O error occurs
-
peekByte
Read a single byte at the current position without advancing.- Returns:
- the byte value
- Throws:
EOFException- if end-of-file is reachedIOException- if an I/O error occurs
-
readUnsignedByte
Read a single unsigned byte at the current position and advance.- Returns:
- the byte value as an unsigned
int(in the range 0-255) - Throws:
EOFException- if end-of-file is reachedIOException- if an I/O error occurs
-
peekUnsignedByte
Read a single unsigned byte at the current position without advancing.- Returns:
- the byte value as an unsigned
int(in the range 0-255) - Throws:
EOFException- if end-of-file is reachedIOException- if an I/O error occurs
-
writeShort
Write a 16-bit value at the current position using the default byte order and advance.- Parameters:
value- the value (only the low 16 bits are used)- Throws:
IOException- if an I/O error occurs
-
writeShortLE
Write a 16-bit value at the current position using little-endian byte order and advance.- Parameters:
value- the value (only the low 16 bits are used)- Throws:
IOException- if an I/O error occurs
-
writeShortBE
Write a 16-bit value at the current position using big-endian byte order and advance.- Parameters:
value- the value (only the low 16 bits are used)- Throws:
IOException- if an I/O error occurs
-
readShort
Read a 16-bit value at the current position using the default byte order and advance.- Returns:
- the value (sign-extended)
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
peekShort
Read a 16-bit value at the current position using the default byte order without advancing.- Returns:
- the value (sign-extended)
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readShortLE
Read a 16-bit value at the current position using little-endian byte order and advance.- Returns:
- the value (sign-extended)
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
peekShortLE
Read a 16-bit value at the current position using little-endian byte order without advancing.- Returns:
- the value (sign-extended)
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readShortBE
Read a 16-bit value at the current position using big-endian byte order and advance.- Returns:
- the value (sign-extended)
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
peekShortBE
Read a 16-bit value at the current position using big-endian byte order without advancing.- Returns:
- the value (sign-extended)
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readUnsignedShort
Read an unsigned 16-bit value at the current position using the default byte order and advance.- Returns:
- the value (zero-extended)
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
peekUnsignedShort
Read an unsigned 16-bit value at the current position using the default byte order without advancing.- Returns:
- the value (zero-extended)
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readUnsignedShortLE
Read an unsigned 16-bit value at the current position using little-endian byte order and advance.- Returns:
- the value (zero-extended)
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
peekUnsignedShortLE
Read an unsigned 16-bit value at the current position using little-endian byte order without advancing.- Returns:
- the value (zero-extended)
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readUnsignedShortBE
Read an unsigned 16-bit value at the current position using big-endian byte order and advance.- Returns:
- the value (zero-extended)
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
peekUnsignedShortBE
Read an unsigned 16-bit value at the current position using big-endian byte order without advancing.- Returns:
- the value (zero-extended)
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
writeInt
Write a 32-bit value at the current position using the default byte order and advance.- Parameters:
value- the value- Throws:
IOException- if an I/O error occurs
-
writeIntLE
Write a 32-bit value at the current position using little-endian byte order and advance.- Parameters:
value- the value to write- Throws:
IOException- if an I/O error occurs
-
writeIntBE
Write a 32-bit value at the current position using big-endian byte order and advance.- Parameters:
value- the value to write- Throws:
IOException- if an I/O error occurs
-
readInt
Read a 32-bit value at the current position using the default byte order and advance.- Returns:
- the value
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
peekInt
Read a 32-bit value at the current position using the default byte order without advancing.- Returns:
- the value
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readIntLE
Read a 32-bit value at the current position using little-endian byte order and advance.- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
peekIntLE
Read a 32-bit value at the current position using little-endian byte order without advancing.- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readIntBE
Read a 32-bit value at the current position using big-endian byte order and advance.- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
peekIntBE
Read a 32-bit value at the current position using big-endian byte order without advancing.- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readUnsignedInt
Read a 32-bit unsigned value at the current position using the default byte order and advance.- Returns:
- the unsigned value
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
peekUnsignedInt
Read a 32-bit unsigned value at the current position using the default byte order without advancing.- Returns:
- the unsigned value
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readUnsignedIntLE
Read a 32-bit unsigned value at the current position using little-endian byte order and advance.- Returns:
- the unsigned value
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
peekUnsignedIntLE
Read a 32-bit unsigned value at the current position using little-endian byte order without advancing.- Returns:
- the unsigned value
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readUnsignedIntBE
Read a 32-bit unsigned value at the current position using big-endian byte order and advance.- Returns:
- the unsigned value
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
peekUnsignedIntBE
Read a 32-bit unsigned value at the current position using big-endian byte order without advancing.- Returns:
- the unsigned value
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
writeLong
Write a 64-bit value at the current position using the default byte order and advance.- Parameters:
value- the value- Throws:
IOException- if an I/O error occurs
-
writeLongLE
Write a 64-bit value at the current position using little-endian byte order and advance.- Parameters:
value- the value to write- Throws:
IOException- if an I/O error occurs
-
writeLongBE
Write a 64-bit value at the current position using big-endian byte order and advance.- Parameters:
value- the value to write- Throws:
IOException- if an I/O error occurs
-
readLong
Read a 64-bit value at the current position using the default byte order and advance.- Returns:
- the value
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
peekLong
Read a 64-bit value at the current position using the default byte order without advancing.- Returns:
- the value
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readLongLE
Read a 64-bit value at the current position using little-endian byte order and advance.- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
peekLongLE
Read a 64-bit value at the current position using little-endian byte order without advancing.- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readLongBE
Read a 64-bit value at the current position using big-endian byte order and advance.- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
peekLongBE
Read a 64-bit value at the current position using big-endian byte order without advancing.- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
writeFloat
Write a 32-bit floating-point value using raw bit patterns at the current position using the default byte order and advance.- Parameters:
value- the value to write- Throws:
IOException- if an I/O error occurs
-
writeFloatLE
Write a 32-bit floating-point value using raw bit patterns at the current position using little-endian byte order and advance.- Parameters:
value- the value to write- Throws:
IOException- if an I/O error occurs
-
writeFloatBE
Write a 32-bit floating-point value using raw bit patterns at the current position using big-endian byte order and advance.- Parameters:
value- the value to write- Throws:
IOException- if an I/O error occurs
-
readFloat
Read a 32-bit floating-point value using raw bit patterns at the current position using the default byte order and advance.- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readFloatLE
Read a 32-bit floating-point value using raw bit patterns at the current position using little-endian byte order and advance.- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readFloatBE
Read a 32-bit floating-point value using raw bit patterns at the current position using big-endian byte order and advance.- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
writeDouble
Write a 64-bit floating-point value using raw bit patterns at the current position using the default byte order and advance.- Parameters:
value- the value to write- Throws:
IOException- if an I/O error occurs
-
writeDoubleLE
Write a 64-bit floating-point value using raw bit patterns at the current position using little-endian byte order and advance.- Parameters:
value- the value to write- Throws:
IOException- if an I/O error occurs
-
writeDoubleBE
Write a 64-bit floating-point value using raw bit patterns at the current position using big-endian byte order and advance.- Parameters:
value- the value to write- Throws:
IOException- if an I/O error occurs
-
readDouble
Read a 64-bit floating-point value using raw bit patterns at the current position using the default byte order and advance.- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readDoubleLE
Read a 64-bit floating-point value using raw bit patterns at the current position using little-endian byte order and advance.- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readDoubleBE
Read a 64-bit floating-point value using raw bit patterns at the current position using big-endian byte order and advance.- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
writeBoolean
Write a boolean value (1 byte: 0 for false, 1 for true) and advance.- Parameters:
value- the boolean value- Throws:
IOException- if an I/O error occurs
-
readBoolean
Read a boolean value (1 byte: 0 for false, non-zero for true) and advance.- Returns:
- the boolean value
- Throws:
EOFException- if end-of-file is reachedIOException- if an I/O error occurs
-
writeChar
Write a 16-bit char at the current position using the default byte order and advance.- Parameters:
value- the char value (only the low 16 bits of theintare used)- Throws:
IOException- if an I/O error occurs
-
writeCharLE
Write a 16-bit character value at the current position using little-endian byte order and advance.- Parameters:
value- the value (only the low 16 bits are used)- Throws:
IOException- if an I/O error occurs
-
writeCharBE
Write a 16-bit character value at the current position using big-endian byte order and advance.- Parameters:
value- the value (only the low 16 bits are used)- Throws:
IOException- if an I/O error occurs
-
readChar
Read a 16-bit char at the current position using the default byte order and advance.- Returns:
- the char value
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readCharLE
Read a 16-bit character value at the current position using little-endian byte order and advance.- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readCharBE
Read a 16-bit character value at the current position using big-endian byte order and advance.- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
writeByte
Write a single byte at the given file position without changing the current position.- Parameters:
pos- the file positionvalue- the byte value (only the low 8 bits are used)- Throws:
IOException- if an I/O error occurs
-
readByte
Read a single byte at the given file position without changing the current position.- Parameters:
pos- the file position- Returns:
- the byte value
- Throws:
EOFException- if end-of-file is reachedIOException- if an I/O error occurs
-
readUnsignedByte
Read a single unsigned byte at the given file position without changing the current position.- Parameters:
pos- the file position- Returns:
- the unsigned byte value
- Throws:
EOFException- if end-of-file is reachedIOException- if an I/O error occurs
-
writeShort
Write a 16-bit value at the given file position using the default byte order without changing the current position.- Parameters:
pos- the file positionvalue- the value (only the low 16 bits are used)- Throws:
IOException- if an I/O error occurs
-
writeShortLE
Write a 16-bit value at the given file position using little-endian byte order without advancing the current position.- Parameters:
pos- the file positionvalue- the value (only the low 16 bits are used)- Throws:
IOException- if an I/O error occurs
-
writeShortBE
Write a 16-bit value at the given file position using big-endian byte order without advancing the current position.- Parameters:
pos- the file positionvalue- the value (only the low 16 bits are used)- Throws:
IOException- if an I/O error occurs
-
readShort
Read a 16-bit value at the given file position using the default byte order without changing the current position.- Parameters:
pos- the file position- Returns:
- the value (sign-extended)
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readShortLE
Read a 16-bit value at the given file position using little-endian byte order without advancing the current position.- Parameters:
pos- the file position- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readShortBE
Read a 16-bit value at the given file position using big-endian byte order without advancing the current position.- Parameters:
pos- the file position- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readUnsignedShort
Read an unsigned 16-bit value at the given file position using the default byte order without changing the current position.- Parameters:
pos- the file position- Returns:
- the value (zero-extended)
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readUnsignedShortLE
Read an unsigned 16-bit value at the given file position using little-endian byte order without advancing the current position.- Parameters:
pos- the file position- Returns:
- the value (zero-extended)
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readUnsignedShortBE
Read an unsigned 16-bit value at the given file position using big-endian byte order without advancing the current position.- Parameters:
pos- the file position- Returns:
- the value (zero-extended)
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
writeInt
Write a 32-bit value at the given file position using the default byte order without advancing the current position.- Parameters:
pos- the file positionvalue- the value to write- Throws:
IOException- if an I/O error occurs
-
writeIntLE
Write a 32-bit value at the given file position using little-endian byte order without advancing the current position.- Parameters:
pos- the file positionvalue- the value to write- Throws:
IOException- if an I/O error occurs
-
writeIntBE
Write a 32-bit value at the given file position using big-endian byte order without advancing the current position.- Parameters:
pos- the file positionvalue- the value to write- Throws:
IOException- if an I/O error occurs
-
readInt
Read a 32-bit value at the given file position using the default byte order without advancing the current position.- Parameters:
pos- the file position- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readIntLE
Read a 32-bit value at the given file position using little-endian byte order without advancing the current position.- Parameters:
pos- the file position- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readIntBE
Read a 32-bit value at the given file position using big-endian byte order without advancing the current position.- Parameters:
pos- the file position- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readUnsignedInt
Read an unsigned 32-bit value at the given file position using the default byte order without changing the current position.- Parameters:
pos- the file position- Returns:
- the value (zero-extended)
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readUnsignedIntLE
Read an unsigned 32-bit value at the given file position using little-endian byte order without advancing the current position.- Parameters:
pos- the file position- Returns:
- the value (zero-extended)
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readUnsignedIntBE
Read an unsigned 32-bit value at the given file position using big-endian byte order without advancing the current position.- Parameters:
pos- the file position- Returns:
- the value (zero-extended)
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
writeLong
Write a 64-bit value at the given file position using the default byte order without advancing the current position.- Parameters:
pos- the file positionvalue- the value to write- Throws:
IOException- if an I/O error occurs
-
writeLongLE
Write a 64-bit value at the given file position using little-endian byte order without advancing the current position.- Parameters:
pos- the file positionvalue- the value to write- Throws:
IOException- if an I/O error occurs
-
writeLongBE
Write a 64-bit value at the given file position using big-endian byte order without advancing the current position.- Parameters:
pos- the file positionvalue- the value to write- Throws:
IOException- if an I/O error occurs
-
readLong
Read a 64-bit value at the given file position using the default byte order without advancing the current position.- Parameters:
pos- the file position- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readLongLE
Read a 64-bit value at the given file position using little-endian byte order without advancing the current position.- Parameters:
pos- the file position- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readLongBE
Read a 64-bit value at the given file position using big-endian byte order without advancing the current position.- Parameters:
pos- the file position- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
writeFloat
Write a 32-bit floating-point value using raw bit patterns at the given file position using the default byte order without advancing the current position.- Parameters:
pos- the file positionvalue- the value to write- Throws:
IOException- if an I/O error occurs
-
writeFloatLE
Write a 32-bit floating-point value using raw bit patterns at the given file position using little-endian byte order without advancing the current position.- Parameters:
pos- the file positionvalue- the value to write- Throws:
IOException- if an I/O error occurs
-
writeFloatBE
Write a 32-bit floating-point value using raw bit patterns at the given file position using big-endian byte order without advancing the current position.- Parameters:
pos- the file positionvalue- the value to write- Throws:
IOException- if an I/O error occurs
-
readFloat
Read a 32-bit floating-point value using raw bit patterns at the given file position using the default byte order without advancing the current position.- Parameters:
pos- the file position- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readFloatLE
Read a 32-bit floating-point value using raw bit patterns at the given file position using little-endian byte order without advancing the current position.- Parameters:
pos- the file position- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readFloatBE
Read a 32-bit floating-point value using raw bit patterns at the given file position using big-endian byte order without advancing the current position.- Parameters:
pos- the file position- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
writeDouble
Write a 64-bit floating-point value using raw bit patterns at the given file position using the default byte order without advancing the current position.- Parameters:
pos- the file positionvalue- the value to write- Throws:
IOException- if an I/O error occurs
-
writeDoubleLE
Write a 64-bit floating-point value using raw bit patterns at the given file position using little-endian byte order without advancing the current position.- Parameters:
pos- the file positionvalue- the value to write- Throws:
IOException- if an I/O error occurs
-
writeDoubleBE
Write a 64-bit floating-point value using raw bit patterns at the given file position using big-endian byte order without advancing the current position.- Parameters:
pos- the file positionvalue- the value to write- Throws:
IOException- if an I/O error occurs
-
readDouble
Read a 64-bit floating-point value using raw bit patterns at the given file position using the default byte order without advancing the current position.- Parameters:
pos- the file position- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readDoubleLE
Read a 64-bit floating-point value using raw bit patterns at the given file position using little-endian byte order without advancing the current position.- Parameters:
pos- the file position- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readDoubleBE
Read a 64-bit floating-point value using raw bit patterns at the given file position using big-endian byte order without advancing the current position.- Parameters:
pos- the file position- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
writeBoolean
Write a boolean value at the given file position without advancing the current position.- Parameters:
pos- the file positionvalue- the value to write- Throws:
IOException- if an I/O error occurs
-
readBoolean
Read a boolean value at the given file position without advancing the current position.- Parameters:
pos- the file position- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
writeChar
Write a 16-bit character value at the given file position using the default byte order without advancing the current position.- Parameters:
pos- the file positionvalue- the value (only the low 16 bits are used)- Throws:
IOException- if an I/O error occurs
-
writeCharLE
Write a 16-bit character value at the given file position using little-endian byte order without advancing the current position.- Parameters:
pos- the file positionvalue- the value (only the low 16 bits are used)- Throws:
IOException- if an I/O error occurs
-
writeCharBE
Write a 16-bit character value at the given file position using big-endian byte order without advancing the current position.- Parameters:
pos- the file positionvalue- the value (only the low 16 bits are used)- Throws:
IOException- if an I/O error occurs
-
readChar
Read a 16-bit character value at the given file position using the default byte order without advancing the current position.- Parameters:
pos- the file position- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readCharLE
Read a 16-bit character value at the given file position using little-endian byte order without advancing the current position.- Parameters:
pos- the file position- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readCharBE
Read a 16-bit character value at the given file position using big-endian byte order without advancing the current position.- Parameters:
pos- the file position- Returns:
- the value read
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
read
Read bytes into the given array at the current position and advance.- Parameters:
dest- the destination arrayoffset- the start offset in the arraylength- the maximum number of bytes to read- Returns:
- the number of bytes actually read, or -1 at end-of-file
- Throws:
IOException- if an I/O error occurs
-
read
Read bytes into the given array at the current position and advance.- Parameters:
dest- the destination array- Returns:
- the number of bytes actually read, or -1 at end-of-file
- Throws:
IOException- if an I/O error occurs
-
readFully
Read exactlylengthbytes at the current position and advance. IfEOFExceptionis thrown, the buffer may have been partially populated.- Parameters:
dest- the destination arrayoffset- the start offset in the arraylength- the number of bytes to read- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readFully
Read exactlydest.lengthbytes from the current position into the given array and advance.- Parameters:
dest- the destination array- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
write
Write bytes from the given array at the current position and advance.- Parameters:
src- the source arrayoffset- the start offset in the arraylength- the number of bytes to write- Throws:
IOException- if an I/O error occurs
-
write
Write all bytes from the given array to the current position and advance.- Parameters:
src- the source byte array- Throws:
IOException- if an I/O error occurs
-
read
Read bytes at the given file position without changing the current position.- Parameters:
pos- the file positiondest- the destination array- Returns:
- the number of bytes actually read, or -1 at end-of-file
- Throws:
IOException- if an I/O error occurs
-
read
Read bytes at the given file position without changing the current position.- Parameters:
pos- the file positiondest- the destination arrayoffset- the start offset in the arraylength- the maximum number of bytes to read- Returns:
- the number of bytes actually read, or -1 at end-of-file
- Throws:
IOException- if an I/O error occurs
-
write
Write bytes at the given file position without changing the current position.- Parameters:
pos- the file positionsrc- the source arrayoffset- the start offset in the arraylength- the number of bytes to write- Throws:
IOException- if an I/O error occurs
-
read
Read into the given ByteBuffer at the current position and advance.- Parameters:
dest- the destination buffer- Returns:
- the number of bytes read, or -1 at end-of-file
- Throws:
IOException- if an I/O error occurs
-
write
Write from the given ByteBuffer at the current position and advance.- Parameters:
src- the source buffer- Throws:
IOException- if an I/O error occurs
-
read
Read into the given ByteBuffer at the given file position without changing the current position.- Parameters:
pos- the file positiondest- the destination buffer- Returns:
- the number of bytes read, or -1 at end-of-file
- Throws:
IOException- if an I/O error occurs
-
write
Write from the given ByteBuffer at the given file position without changing the current position.- Parameters:
pos- the file positionsrc- the source buffer- Returns:
- the number of bytes written
- Throws:
IOException- if an I/O error occurs
-
writeZeroTerminatedString
Write a string encoded with the given charset, followed by a zero byte, and advance.- Parameters:
s- the string to writecharset- the charset to use for encoding- Throws:
IOException- if an I/O error occurs
-
writeZeroTerminatedString
Write a UTF-8-encoded string followed by a zero byte and advance.- Parameters:
s- the string to write- Throws:
IOException- if an I/O error occurs
-
writeString
Write a string encoded with the given charset (no terminator) and advance.- Parameters:
s- the string to writecharset- the charset to use for encoding- Throws:
IOException- if an I/O error occurs
-
writeString
Write a UTF-8-encoded string (no terminator) and advance.- Parameters:
s- the string to write- Throws:
IOException- if an I/O error occurs
-
readZeroTerminatedString
Read a zero-terminated string using the given charset and advance past the terminator.- Parameters:
charset- the charset to use for decoding- Returns:
- the string (not including the zero terminator)
- Throws:
EOFException- if end-of-file is reached before a zero byte is foundIOException- if an I/O error occurs
-
readZeroTerminatedString
Read a zero-terminated UTF-8 string and advance past the terminator.- Returns:
- the string
- Throws:
EOFException- if end-of-file is reached before a zero byte is foundIOException- if an I/O error occurs
-
readString
Read a fixed number of bytes and decode as a string using the given charset.- Parameters:
byteLength- the number of bytes to readcharset- the charset to use for decoding- Returns:
- the decoded string
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
readString
Read a fixed number of bytes and decode as a UTF-8 string.- Parameters:
byteLength- the number of bytes to read- Returns:
- the decoded string
- Throws:
EOFException- if end-of-file is reached before all bytes are readIOException- if an I/O error occurs
-
writeZeros
Write the given number of zero bytes at the current position and advance.- Parameters:
count- the number of zero bytes to write- Throws:
IOException- if an I/O error occurs
-
writeZeros
Write zero bytes at the given file position without changing the current position.- Parameters:
pos- the file positioncount- the number of zero bytes to write- Throws:
IOException- if an I/O error occurs
-
transferTo
Transfer all remaining bytes from the current position to the given output stream.- Parameters:
out- the output stream- Returns:
- the number of bytes transferred
- Throws:
IOException- if an I/O error occurs
-
transferTo
Transfer up tolengthbytes from the current position to the given output stream.- Parameters:
out- the output streamlength- the maximum number of bytes to transfer- Returns:
- the number of bytes transferred
- Throws:
IOException- if an I/O error occurs
-
transferTo
Transfer bytes from the given file position to the output stream without changing the current position.- Parameters:
pos- the file position to read fromout- the output streamlength- the number of bytes to transfer- Returns:
- the number of bytes transferred
- Throws:
IOException- if an I/O error occurs
-
transferFrom
Transfer all bytes from the given input stream to the current position.- Parameters:
in- the input stream- Returns:
- the number of bytes transferred
- Throws:
IOException- if an I/O error occurs
-
transferFrom
Transfer up tolengthbytes from the given input stream to the current position.- Parameters:
in- the input streamlength- the maximum number of bytes to transfer- Returns:
- the number of bytes transferred
- Throws:
IOException- if an I/O error occurs
-
transferFrom
Transfer bytes from the given input stream to the given file position without changing the current position.- Parameters:
pos- the file position to write toin- the input streamlength- the maximum number of bytes to transfer- Returns:
- the number of bytes transferred
- Throws:
IOException- if an I/O error occurs
-
flush
Flush any buffered data to the file.- Specified by:
flushin interfaceFlushable- Throws:
IOException- if an I/O error occurs
-
close
Flush any buffered data and close this file. Subsequent operations (except further calls toclose()) will throwIOException.For nested views, this method flushes buffered data, advances the parent's position past the nested data, unlocks the parent for further use, and then invokes the close action (if any). The close action runs after the parent is unlocked, so it may read and write the parent freely. The underlying file is not closed; the root instance owns the file handle.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- if an I/O error occursIllegalStateException- if a nested child view is still active
-
inputStream
Returns a cachedFileInputStreamview of this file.The returned stream also implements
DataInput(with big-endian semantics). Callingclose()on the returned stream is a no-op.- Returns:
- a cached
FileInputStreamview of this file - Throws:
IllegalStateException- if this file was not opened for reading
-
outputStream
Returns a cachedFileOutputStreamview of this file.The returned stream also implements
DataOutput(with big-endian semantics). Callingclose()on the returned stream is a no-op.- Returns:
- a cached
FileOutputStreamview of this file - Throws:
IllegalStateException- if this file was not opened for writing
-
channel
Returns a cachedFileChannelview of this file.All read/write/position operations on the returned channel delegate to this
BufferedFile, maintaining buffer consistency. Callingclose()on the returned channel is a no-op.- Returns:
- a cached
FileChannelview of this file
-