@NotThreadSafe public class IntervalReadOnlyFile extends DecoratingReadOnlyFile
Note that this class implements a virtual file pointer. Thus, if you would like to use the decorated read only file again after you have finished using this decorating read only file, then you should not assume a particular position of the file pointer in the decorated read only file.
delegate
Constructor and Description |
---|
IntervalReadOnlyFile(ReadOnlyFile rof,
long length)
Constructs a new interval read only file starting at the current
position of the file pointer in the decorated read only file.
|
IntervalReadOnlyFile(ReadOnlyFile rof,
long offset,
long length)
Constructs a new interval read only file starting at the given position
of the file pointer in the given decorated read only file.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the decorated read only file if and only if it is exclusively
accessed by this decorating read only file.
|
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[] buf,
int off,
int len)
Reads up to
len bytes of data from this read only file into
the given array. |
void |
seek(long fp)
Sets the current byte position in the file as a zero-based index at
which the next read occurs.
|
toString
read, readFully, readFully
@CreatesObligation public IntervalReadOnlyFile(@WillCloseWhenClosed ReadOnlyFile rof, long length) throws IOException
Note that this constructor assumes that it has exclusive access to the decorated read only file. Concurrent modification of the file pointer in the decorated read only file may corrupt the input of this decorating read only file!
rof
- the read only file to decorate.length
- the length of the interval.IOException
- On any I/O failure.@CreatesObligation public IntervalReadOnlyFile(@Nullable @WillNotClose ReadOnlyFile rof, long offset, long length) throws IOException
Note that this constructor assumes that it does not have exclusive access to the decorated read only file and positions the file pointer in the decorated read only file before each read operation!
rof
- the read only file to decorate.offset
- the start of the interval.length
- the length of the interval.IOException
- On any I/O failure.public void close() throws IOException
close
in interface ReadOnlyFile
close
in interface Closeable
close
in interface AutoCloseable
close
in class DecoratingReadOnlyFile
IOException
- On any I/O error.public long getFilePointer() throws IOException
ReadOnlyFile
getFilePointer
in interface ReadOnlyFile
getFilePointer
in class DecoratingReadOnlyFile
IOException
- On any I/O failure.public long length() throws IOException
ReadOnlyFile
length
in interface ReadOnlyFile
length
in class DecoratingReadOnlyFile
IOException
- On any I/O failure.public int read() throws IOException
ReadOnlyFile
read
in interface ReadOnlyFile
read
in class DecoratingReadOnlyFile
IOException
- On any I/O failure.public int read(byte[] buf, int off, int len) throws IOException
ReadOnlyFile
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.read
in interface ReadOnlyFile
read
in class DecoratingReadOnlyFile
buf
- 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.public void seek(long fp) throws IOException
ReadOnlyFile
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.seek
in interface ReadOnlyFile
seek
in class DecoratingReadOnlyFile
fp
- 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.