|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.entityfs.util.io.RangeRandomAccess
public class RangeRandomAccess
This is a RandomAccess
object that reads data from and writes data to
a section of another RandomAccess
object. Data cannot be accessed
before the section's lower limit or after the section's upper limit.
If the client attempts to write over the upper limit, the write methods throw
an UnexpectedEofException
.
This object is not safe to use concurrently from several threads without external synchronization.
RangeInputStream
Constructor Summary | |
---|---|
RangeRandomAccess(RandomAccess adapted,
long lowerLimit,
long upperLimit)
Create a new range random access. |
Method Summary | |
---|---|
void |
addCloseObserver(RandomAccessCloseObserver raco)
Add an observer that is notified when this RandomAccess is
closed. |
protected void |
assertNotClosed()
This method throws an IllegalStateException if this random access
object has been closed. |
protected void |
assertNotReadOnly()
This method throws a ReadOnlyException if this random access is
opened read only. |
int |
available()
Returns an estimate of the number of bytes that can be read from this data source without blocking by the next invocation of a method for this data source. |
void |
close()
Close the sink and free all resources associated with it. |
protected void |
finalize()
|
void |
flush()
Flush changes made to the sink to the underlying storage. |
long |
getFilePointer()
Get the current offset in the file. |
RandomAccessMode |
getMode()
Get the mode that this RandomAccess was opened in. |
long |
length()
Get the file's current length. |
int |
read()
Read a byte of data from the source. |
int |
read(byte[] barr)
Read up to b.length bytes of data from the source into the array. |
int |
read(byte[] barr,
int off,
int len)
Read up to len bytes of data from the source into the array. |
void |
seek(long pos)
Set the file pointer offset, measured from the beginning of the file. |
void |
setLength(long l)
Set the length of the file. |
long |
skipBytes(long n)
Attempt to skip over n bytes in the source. |
void |
write(byte[] barr)
Write the contents of the array to the sink, starting at the current file pointer. |
void |
write(byte[] barr,
int off,
int len)
Write len bytes from the array, starting at the offset off to this sink. |
void |
write(int b)
Write a byte to the sink. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public RangeRandomAccess(RandomAccess adapted, long lowerLimit, long upperLimit) throws IllegalArgumentException
0
, which means that it will be at the lower limit.
The total length of the range is upperLimit - lowerLimit + 1
bytes.
The upper limit, or even the complete range, may be beyond the current
end of the supplied random access object. This object will behave as
expected when trying to access data beyond the end of the file; reading
methods will return -1
and writing methods will extend the file.
adapted
- The random access object to read data from and/or write
data to. If this object is opened read only, this object becomes read
only too.lowerLimit
- The lower limit. The byte at this position will be the
first visible byte in the range.upperLimit
- The upper limit. The byte at this position will be the
last visible byte in the range.
IllegalArgumentException
- If the lower limit is negative or if the
upper limit is less than the lower limit.Method Detail |
---|
protected void assertNotClosed() throws IllegalStateException
IllegalStateException
if this random access
object has been closed.
IllegalStateException
- If this random access object has been
closed.protected void assertNotReadOnly() throws ReadOnlyException
ReadOnlyException
if this random access is
opened read only.
ReadOnlyException
- If this random access is opened read only.public void addCloseObserver(RandomAccessCloseObserver raco)
RandomAccess
RandomAccess
is
closed. The observers are called just after the RandomAccess
has
been closed.
addCloseObserver
in interface RandomAccess
raco
- The observer.public RandomAccessMode getMode()
RandomAccess
RandomAccess
was opened in.
This method does not throw an IllegalStateException
if it is
called after the RandomAccess
has been closed.
getMode
in interface RandomAccess
RandomAccess
was opened in.public void flush() throws ReadOnlyException, IllegalStateException
DataSink
ReadOnlyException
.
flush
in interface DataSink
ReadOnlyException
- If the sink is opened read only.
IllegalStateException
- If the sink is closed.public long getFilePointer() throws IllegalStateException
RandomAccess
getFilePointer
in interface RandomAccess
IllegalStateException
- If the random access file is closed.public int available()
DataSource
available
in interface DataSource
InputStream.available()
public long length() throws IllegalStateException
RandomAccess
length
in interface RandomAccess
IllegalStateException
- If the random access file is closed.public int read() throws IllegalStateException
DataSource
0x00-0x0ff
).
read
in interface DataSource
-1
if the end of the source has
been reached.
IllegalStateException
- If the source is closed.public int read(byte[] barr) throws IllegalStateException
DataSource
b.length
bytes of data from the source into the array.
read
in interface DataSource
barr
- The byte array into which data is read.
-1
if
no data could be read because the the end of the source was reached
before the read started.
IllegalStateException
- If the source is closed.public int read(byte[] barr, int off, int len) throws IllegalStateException
DataSource
len
bytes of data from the source into the array.
read
in interface DataSource
barr
- The byte array into which data is read.off
- The start offset in the array b
at which data is
written.len
- The maximum number of bytes to read.
-1
if
no data could be read because the end of the source was reached before
the read started.
IllegalStateException
- If the source is closed.public void seek(long pos) throws FileSystemException, IllegalStateException
RandomAccess
seek
in interface RandomAccess
pos
- The new file pointer offset, measured from the beginning of
the file.
FileSystemException
- If pos < 0
.
IllegalStateException
- If the random access file is closed.DataSource.skipBytes(long)
public void setLength(long l) throws ReadOnlyException, IllegalStateException, FileSystemException
RandomAccess
If the present length of the file is greater than the l
argument,
the file will be truncated.
If the new length is bigger than the current length of the file, the file will be extended. The contents of the extended portion of the file are not defined.
The current file pointer is not changed, unless the file pointer offset is greater than the new file length. If so, it will be set to the new length.
setLength
in interface RandomAccess
l
- The new length of the file.
ReadOnlyException
- If the file is opened read only.
IllegalStateException
- If the random access file is closed.
FileSystemException
- If the new length is less than 0
.public long skipBytes(long n) throws IllegalStateException
DataSource
n
bytes in the source. If n
is
negative, no bytes are skipped.
The pointer in the source cannot be moved beyond EOF using this method
(unlike RandomAccess.seek(long)
).
skipBytes
in interface DataSource
n
- The number of bytes to increment the source pointer with.
IllegalStateException
- If the source is closed.RandomAccess.seek(long)
public void write(byte[] barr) throws ReadOnlyException, IllegalStateException, UnexpectedEofException
DataSink
write
in interface DataSink
barr
- The array to write.
UnexpectedEofException
- If the client tries to write beyond the
upper limit.
ReadOnlyException
- If the sink is opened read only.
IllegalStateException
- If the sink is closed.public void write(byte[] barr, int off, int len) throws ReadOnlyException, IllegalStateException, UnexpectedEofException
DataSink
len
bytes from the array, starting at the offset off
to this sink.
write
in interface DataSink
barr
- The byte array.off
- The starting offset in the array.len
- The number of bytes to write.
UnexpectedEofException
- If the client tries to write beyond the
upper limit.
ReadOnlyException
- If the sink is opened read only.
IllegalStateException
- If the sink file is closed.public void write(int b) throws ReadOnlyException, IllegalStateException, UnexpectedEofException
DataSink
write
in interface DataSink
b
- The byte to write.
UnexpectedEofException
- If the client tries to write beyond the
upper limit.
ReadOnlyException
- If the sink is opened read only.
IllegalStateException
- If the random access file is closed.public void close()
DataSink
close
in interface DataSink
close
in interface DataSource
protected void finalize() throws Throwable
finalize
in class Object
Throwable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |