Interface ValueAccessor
- All Superinterfaces:
AutoCloseable
,Closeable
- All Known Subinterfaces:
Cursor
Accesses database values without requiring that they be fully loaded or stored in a single
operation. This interface permits values to be larger than what can fit in main memory.
When using a cursor to access values,
autoload
should be disabled to prevent values from being fully loaded automatically
When making transactional changes through this interface, undo actions may require that copies be made of the original value. Partial truncation of a large value isn't optimized to reduce copying, but full truncation is. When possible, full truncation will reference the original value instead of creating a copy.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the accessor, but doesn't flush any OutputStream instances.newValueInputStream
(long pos) Returns a new buffered InputStream instance, which reads from the value.newValueInputStream
(long pos, int bufferSize) Returns a new buffered InputStream instance, which reads from the value.newValueOutputStream
(long pos) Returns a new buffered OutputStream instance, which writes to the value.newValueOutputStream
(long pos, int bufferSize) Returns a new buffered OutputStream instance, which writes to the value.void
valueClear
(long pos, long length) Writes over a range of the value with zeros, starting from any position.long
Returns the total length of the accessed value.void
valueLength
(long length) Extends or truncates the accessed value.int
valueRead
(long pos, byte[] buf, int off, int len) Read from the value, starting from any position.void
valueWrite
(long pos, byte[] buf, int off, int len) Write into the value, starting from any position.
-
Method Details
-
valueLength
Returns the total length of the accessed value.- Returns:
- value length or -1 if it doesn't exist
- Throws:
IllegalStateException
- if closedIOException
-
valueLength
Extends or truncates the accessed value. When extended, the new portion of the value is filled with zeros.- Parameters:
length
- new value length; a negative length deletes the value- Throws:
IllegalArgumentException
- if length is too largeIllegalStateException
- if closedIllegalUpgradeException
- if not locked for writingIOException
-
valueRead
Read from the value, starting from any position. The full requested amount of bytes are read, unless the end is reached. A return value of -1 indicates that the value doesn't exist at all, even when the requested amount is zero.- Parameters:
pos
- start position to read frombuf
- buffer to read intooff
- buffer start offsetlen
- requested amount to read- Returns:
- the actual amount read, which is less than the requested amount only if the end was reached, or -1 if the value doesn't exist
- Throws:
IllegalArgumentException
- if the position is negativeIndexOutOfBoundsException
IllegalStateException
- if closedIOException
-
valueWrite
Write into the value, starting from any position. Value is extended with zeros when writing past the end, even if the written amount is zero.- Parameters:
pos
- start position to write tobuf
- buffer to write fromoff
- buffer start offsetlen
- amount to write- Throws:
IllegalArgumentException
- if the position is negativeIndexOutOfBoundsException
IllegalStateException
- if closedIllegalUpgradeException
- if not locked for writingIOException
-
valueClear
Writes over a range of the value with zeros, starting from any position. The length of the value is never changed by this method, even when clearing past the end.- Parameters:
pos
- start position to clear fromlength
- amount to clear- Throws:
IllegalArgumentException
- if the position or length is negativeIllegalStateException
- if closedIllegalUpgradeException
- if not locked for writingIOException
-
newValueInputStream
Returns a new buffered InputStream instance, which reads from the value. When the InputStream is closed, it closes the accessor too. The InputStream is bound to the accessor, and so only one thread can access either at a time.Reading past the end of the stream returns -1 (EOF), as per the InputStream contract. Reading from a value which doesn't exist causes a
NoSuchValueException
to be thrown.- Parameters:
pos
- start position to read from- Returns:
- buffered unsynchronized InputStream
- Throws:
IllegalArgumentException
- if the position is negativeIllegalStateException
- if closedIOException
-
newValueInputStream
Returns a new buffered InputStream instance, which reads from the value. When the InputStream is closed, it closes the accessor too. The InputStream is bound to the accessor, and so only one thread can access either at a time.Reading past the end of the stream returns -1 (EOF), as per the InputStream contract. Reading from a value which doesn't exist causes a
NoSuchValueException
to be thrown.- Parameters:
pos
- start position to read frombufferSize
- requested buffer size; actual size may differ- Returns:
- buffered unsynchronized InputStream
- Throws:
IllegalArgumentException
- if the position is negativeIllegalStateException
- if closedIOException
-
newValueOutputStream
Returns a new buffered OutputStream instance, which writes to the value. When the OutputStream is closed, it closes the accessor too. The OutputStream is bound to the accessor, and so only one thread can access either at a time.- Parameters:
pos
- start position to write to- Returns:
- buffered unsynchronized OutputStream
- Throws:
IllegalArgumentException
- if the position is negativeIllegalStateException
- if closedIOException
-
newValueOutputStream
Returns a new buffered OutputStream instance, which writes to the value. When the OutputStream is closed, it closes the accessor too. The OutputStream is bound to the accessor, and so only one thread can access either at a time.- Parameters:
pos
- start position to write tobufferSize
- requested buffer size; actual size may differ- Returns:
- buffered unsynchronized OutputStream
- Throws:
IllegalArgumentException
- if the position is negativeIllegalStateException
- if closedIOException
-
close
Closes the accessor, but doesn't flush any OutputStream instances.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-