public class S_RandomAccessorImpl extends Object implements RandomAccessor
Modifier | Constructor and Description |
---|---|
protected |
S_RandomAccessorImpl(S_Document doc,
S_ContentObject co)
Constructs a non-writeable (read-only) S_RandomAccessorImpl.
|
protected |
S_RandomAccessorImpl(S_Document doc,
S_ContentObject co,
S_LibraryObjectDefinition docdef,
long expirationPeriod)
Constructs a writeable S_RandomAccessorImpl.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this RandomAccessor, saving any changes to the document.
|
void |
dispose()
Disposes this RandomAccessor, discarding any changes to the document.
|
Long |
getContentObjectId()
Gets the id of the ContentObject being accessed by this RandomAccessor.
|
Long |
getDocumentId()
Gets the id of the Document being accessed by this RandomAccessor.
|
LibrarySessionInterface |
getSession()
Gets the session associated with this RandomAccessor.
|
boolean |
isWriteable()
Gets whether this RandomAccessor 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.
|
protected void |
setContext(S_LibrarySession session,
Transaction transaction)
Called by DMRandomAccessor* methods to record the session and transaction
context.
|
void |
setSession(LibrarySessionInterface session)
Sets the session associated with this RandomAccessor.
|
String |
toString() |
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.
|
protected S_RandomAccessorImpl(S_Document doc, S_ContentObject co) throws IfsException
doc
- the documentco
- the existing ContentObjectIfsException
protected S_RandomAccessorImpl(S_Document doc, S_ContentObject co, S_LibraryObjectDefinition docdef, long expirationPeriod) throws IfsException
doc
- the documentco
- the existing ContentObjectdocdef
- the definition used to update the documentexpirationPeriod
- the expiration period of this S_RandomAccessorImpl
in millisecondsIfsException
- if the operation failspublic Long getDocumentId() throws IfsException
getDocumentId
in interface RandomAccessor
IfsException
- if the operation failspublic Long getContentObjectId() throws IfsException
getContentObjectId
in interface RandomAccessor
IfsException
- if the operation failspublic void setSession(LibrarySessionInterface session) throws IfsException
A RandomAccessor is initially bound to the session in which it was created. Call this method to safely use the RandomAccessor in the context of a different session.
setSession
in interface RandomAccessor
session
- the sessionIfsException
- if the operation failspublic LibrarySessionInterface getSession() throws IfsException
getSession
in interface RandomAccessor
IfsException
- if the operation failspublic 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
read
in interface RandomAccessor
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
- if the operation failspublic boolean isWriteable() throws IfsException
isWriteable
in interface RandomAccessor
IfsException
- if the operation failspublic void 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()
.
An exception is thrown upon any of the following conditions:
pos < 0
b == null
off < 0
len < 0
off + len > b.length
write
in interface RandomAccessor
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
- if the operation failspublic void 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
.
An exception is thrown if len < 0
or this RandomAccessor is
not writeable.
truncate
in interface RandomAccessor
len
- the desired content lengthIfsException
- if the operation failspublic long length() throws IfsException
length
in interface RandomAccessor
IfsException
- if the operation failspublic void dispose() throws IfsException
To release resources held by the RandomAccessor, an application should
call either close
(to save changes) or dispose
(to discard changes).
dispose
in interface RandomAccessor
IfsException
- if the operation failspublic void close() throws IfsException
For a writeable RandomAccessor, a new ContentObject is created for the updated content, and the document's CONTENTOBJECT attribute is set to reference this new ContentObject. Any other changes specified by the DocumentDefinition supplied in creating this RandomAccessor are also applied.
For a non-writeable RandomAccessor, close
is equivalent to
dispose
.
To release resources held by the RandomAccessor, an application should
call either close
(to save changes) or dispose
(to discard changes).
close
in interface RandomAccessor
IfsException
- if the operation failsprotected void setContext(S_LibrarySession session, Transaction transaction) throws IfsException
session
- the sessiontransaction
- the transaction in progress prior to the
DMRandomAccessor* call, or null if noneIfsException
- if the operation failsCopyright © 2023. All rights reserved.