@NotThreadSafe @CleanupObligation public interface ReadOnlyFile extends Closeable
RandomAccessFile
which is required for random read-only access.
The default implementation can be found in DefaultReadOnlyFile
.Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this read-only file and releases any non-heap resources
allocated for it.
|
long |
getFilePointer()
Returns the current byte position in the file as a zero-based index.
|
long |
length()
Returns the length of the file in bytes.
|
int |
read()
Reads and returns the next byte or -1 if the end of the file has been
reached.
|
int |
read(byte[] b)
Equivalent to
read(b, 0, b.length) . |
int |
read(byte[] b,
int off,
int len)
Reads up to
len bytes of data from this read only file into
the given array. |
void |
readFully(byte[] buf)
Equivalent to
readFully(b, 0, b.length) . |
void |
readFully(byte[] buf,
int off,
int len)
Reads
len bytes into the given buffer at the given position. |
void |
seek(long pos)
Sets the current byte position in the file as a zero-based index at
which the next read occurs.
|
@DischargesObligation void close() throws IOException
close
in interface AutoCloseable
close
in interface Closeable
IOException
- On any I/O failure.long getFilePointer() throws IOException
IOException
- On any I/O failure.long length() throws IOException
IOException
- On any I/O failure.int read() throws IOException
IOException
- On any I/O failure.int read(byte[] b) throws IOException
read(b, 0, b.length)
.b
- The buffer to fill with data.-1
if there is
no more data because the end of the file has been reached.IOException
- On any I/O failure.int read(byte[] b, int off, int len) throws IOException
len
bytes of data from this read only file into
the given array.
This method blocks until at least one byte of input is available unless
len
is zero.b
- The buffer to fill with data.off
- The start offset of the data.len
- The maximum number of bytes to read.-1
if there is
no more data because the end of the file has been reached.IOException
- On any I/O failure.void readFully(byte[] buf) throws IOException
readFully(b, 0, b.length)
.buf
- the buffer to fill with data.EOFException
- If less than len
bytes are available
before the end of the file is reached.IOException
- On any I/O failure.void readFully(byte[] buf, int off, int len) throws IOException
len
bytes into the given buffer at the given position.buf
- the buffer to fill with data.off
- the start offset of the data.len
- the number of bytes to read.EOFException
- If less than len
bytes are available
before the end of the file is reached.IOException
- On any I/O failure.void seek(long pos) throws IOException
DefaultReadOnlyFile
passes "r"
as a parameter to the constructor of its super-class
RandomAccessFile
.
With Oracle's JSE implementation, on the Windows platform this
implementation allows to seek past the end of file, but on the Linux
platform it doesn't.pos
- The current byte position as a zero-based index.IOException
- If pos
is less than 0
or on any
I/O failure.Copyright © 2005–2018 Schlichtherle IT Services. All rights reserved.