public interface RandomAccessDriver
A RandomAccessDriver instance is associated with a particular content id,
in a particular session, and within the context of a specific writeable
transaction. Changes to content made by write(long, byte[], int, int)
and truncate(long)
should be transactional. However, the effect of
aborting a transaction in which write
or truncate
was called is unspecified, since some medias are non-transactional.
dispose()
will be called to close the RandomAccessDriver. However
this is not guaranteed to occur until the session is disconnected.
Modifier and Type | Method and Description |
---|---|
void |
dispose()
Disposes this RandomAccessDriver.
|
boolean |
isWriteable()
Gets whether this RandomAccessDriver is writeable.
|
long |
length()
Gets the content length.
|
int |
read(long pos,
byte[] b,
int off,
int len)
Reads bytes from content into a byte array.
|
void |
truncate(long len)
Truncates the content to exactly
len bytes in length. |
void |
write(long pos,
byte[] b,
int off,
int len)
Writes bytes from a byte array.
|
int read(long pos, byte[] b, int off, int len) throws IfsException
Reads from position pos
in content, where 0 is the first byte
in content, 1 is the second byte, and so forth.
Attempts to read as many as len
bytes, but a smaller number
of bytes may actually be read. Returns 0 if len
is 0.
Otherwise, blocks until at least one byte is read, the end of file is
detected, or an error occurs. Returns the number of bytes actually read.
The bytes are read into b
starting at index off
.
If r
is the number of bytes actually read (as returned by the
method), the bytes are read into elements b[off]
through
b[off+r-1]
. Elements b[off+r]
through
b[off+len-1]
are not changed. Additionally, elements
b[0]
through b[off-1]
are never changed.
Similarly, b[off+len]
through b[b.length-1]
are never changed.
An exception is thrown upon any of the following conditions:
pos < 0
pos >= length()
b == null
off < 0
len < 0
off + len > b.length
pos
- the position in content from which to readb
- the buffer into which to readoff
- the offset in the bufferlen
- the maximum number of bytes to readIfsException
- 13600: if the operation failsboolean isWriteable() throws IfsException
IfsException
- 13601: if the operation failsvoid write(long pos, byte[] b, int off, int len) throws IfsException
If len
is 0, the content is unchanged. Otherwise, the
content is changed as specified in the following two paragraphs.
The bytes b[off]
through b[off+len-1]
are
written to positions pos
through pos + len - 1
in the content, where 0 is the position of the first byte in content, 1
is the second byte, and so forth.
If, prior to the call, pos + len > length()
, the method will
extend the content so that pos + len == length()
.
When the method returns, the change must be visible within the session's transaction. Therefore, the method must not buffer unwritten changes beyond call duration.
An exception is thrown upon any of the following conditions:
pos < 0
b == null
off < 0
len < 0
off + len > b.length
pos
- the position in content from which to writeb
- the buffer from which to writeoff
- the offset in the bufferlen
- the number of bytes to writeIfsException
- 13602: if the operation failsvoid truncate(long len) throws IfsException
len
bytes in length.
If len > length()
, the content at byte positions
len
through length() - 1
are dropped,
where 0 is the position of the first byte in content, 1 the second
byte, and so forth.
If len < length()
, the content is resized by zero-filling
positions length()
through len - 1
.
If len == length()
, the method has no effect.
In all three cases, after the method returns, length()
will
return len
.
When the method returns, the change must be visible within the session's transaction. Therefore, the method must not buffer unwritten changes beyond call duration.
An exception is thrown if len < 0
or this RandomAccessDriver
is not writeable.
len
- the desired content lengthIfsException
- 13603: if the operation failslong length() throws IfsException
IfsException
- 13604: if the operation failsvoid dispose() throws IfsException
This method will be called at some point before the session is
disconnected. When dispose
is called, the session may be
in a different transaction and bound to a different database connection.
Consequently, this method must not make database changes.
IfsException
- 13605: if the operation failsCopyright © 2023. All rights reserved.