public final class Value extends Object
Encapsulates the serialized form of an Object or a primitive
value. To store data, the application modifies the Exchange's
Value object and then invokes the Exchange.store()
operation to write the encoded value into the database. To fetch data, the
application modifies the Exchange's Key object,
invokes the Exchange.fetch() operation and then reads the resulting
state from the Value.
A Value's state is represented internally by an array of bytes.
Methods of this class encode primitive or object values into the byte array,
and decode bytes in the array into values equivalent to their original
values. For primitive-valued values, the decoded value is identical to the
original value. That is, after:
int a = 123; value.put(a); int b = value.get();
a == b is true. For object-valued items, the
result will be an object that, subject to the accuracy of serialization code,
is equal to the original object, but generally with different identity. That
is, after: usuallyObject a = new Fricostat(); value.put(a); int b = value.get();
a == b is false, but
a.equals(b) is true.
Value uses three strategies for these conversions:
Value uses built-in logic to perform these conversions. Objects
of class java.lang.String, java.util.Date,
java.math.BigInteger, java.math.BigDecimal and all
arrays are encoded and decoded by built-in methods.Value attempt to find an associated
ValueCoder to perform custom encoding and
decoding of the object.ValueCoder then if the class implements
java.io.Serializable or java.io.Externalizable,
encoding and decoding is performed through serialization logic using extended
java.io.ObjectOutputStream and
java.io.ObjectInputStream classes implemented by
Value.Value can only encode an object if it has a
ValueCoder or implements either
java.io.Serializable or java.io.Externalizable.
Persistit JSA 1.1 introduces a faster, more compact internal storage format
for serialization. Objects encoded in 1.1 without the assistance of a
registered ValueCoder are normally stored in this new format and
cannot be decoded by earlier versions of Persistit. However, the converse is
not true: objects serialized by earlier versions of Persistit can be
deserialized properly by 1.1. Thus you may upgrade an installed application
from version 1.0 to 1.1 without running any type of database conversion
process.
In certain cases it may be preferable to store values using the default Java
serialization format defined by the Java Object Serialization Specification. You may set the
serialOverride configuration property to specify classes that
are to be serialized in standard form.
See Persistit JSA 1.1 Object Serialization for more detailed information on these these subjects.
It may be useful to build a WeakHashMap associating the serialized content of
a Value with an associated deserialized object to avoid object
deserialization overhead or to implement correct identity semantics. Since
Value is mutable it is a poor choice for use as a map key.
Instead, an immutable ValueState should be used to hold an immutable
copy of this state. Value and ValueState implement
hashCode and equals in a compatible fashion so that
code similar to the following works as expected:
...
Value value = <some value>;
if (!map.contains(value)) // uses the transient current state
{
ValueState vs = new ValueState(value);
map.put(vs, object); // uses an immutable copy as the key
}
The toString() method of this class attempts to construct a
human-readable representation of the serialized value. The Tree display panel
of the AdminUI utility uses this capability to summarize the contents of
values stored in a tree. The string representation is constructed as follows:
Value is undefined, then
return "undefined".null or a boolean, return
"null" "false", or "true".int and double are presented without prefix to
reduce clutter.java.util.Date, return a formatted
representation of the date using the format specified by Key.SDF.
This is a readable format the displays the date with full precision,
including milliseconds.Collection
implementations in the java.util package, then return a
comma-separated list of values surrounded by square brackets.Map
implementations in the java.util package, then return a
comma-separated list of key/value pairs surrounded by square brackets. Each
key/value pair is represented by a string in the form
key->value.ValueDisplayer, invoke the
displayer's display
method to format a displayable representation of the object.Collection
contain two references to the same object - then instead of creating an
additional string representing the second or subsequent instance, emit a back
reference pointer in the form @NNN where NNN is the character offset within
the displayable string where the first instance was found. (Note: does not
apply to strings and the primitive wrapper classes.)
For example, consider a Person class with fields for date of birth, first
name, last name, salary and friends, an array of other Person objects. The
result returned by toString() on a Value representing two
Person instances, each with just the other as a friend, might appear as
follows: (Note, space added for legibility.)
(Person){(Date)19490826000000.000-0400,"Mary","Jones",(long)75000,[
(Person){(Date)19550522000000.000-0400,"John","Smith",(long)68000,[@0]}]}
In this example, John Smith's friends array contains a back
reference to Mary Jones in the form "@0" because Mary's displayable reference
starts at the beginning of the string.
A Value normally contains just one object or primitive value. In
its normal mode of operation, the put operation overwrites any
previously held state, and the get operation retrieves the one
object or primitive value represented by the current state of the
Value. A subsequent invocation of get returns the
same value.
However, at certain times it is useful to store multiple items (fields)
together in one Value object. To allow this, Value
implements an alternative mode of operation called stream mode in
which each put invocation appends a new field to the state
rather than replacing the previous state. Similarly, get
operations retrieve sequentially written fields rather than rereading the
same field. Stream allows ValueCoder implementations to aggregate the multiple fields encapsulated
within an encoded value.
The low-level API allows an application to bypass the encoding and decoding operations described above and instead to operate directly on the byte array stored in the database. This might be appropriate for an existing application that has already implemented its own serialization mechanisms. Applications should use these methods only if there is a compelling design requirement to do so.
The low-level API methods are:
byte[] getEncodedBytes()
int getEncodedSize()
void setEncodedSize(int)
void putEncodedBytes(byte[], int, int)
void copyFromEncodedBytes(byte[], int, int, int)
boolean ensureFit(int)
| Modifier and Type | Class and Description |
|---|---|
static class |
Value.OldValueInputStream
An ObjectOutputStream that reads bytes from this Value using standard
Java serialization.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_MAXIMUM_SIZE
Default maximum size to which the backing buffer can grow.
|
static Value |
EMPTY_VALUE
A Value that is always EMPTY - i.e., for which
isDefined()
is always false. |
static int |
INITIAL_SIZE
Default initial size of the byte array that backs this
Value
. |
static int |
MAXIMUM_SIZE
Absolute maximum size limit.
|
| Constructor and Description |
|---|
Value(Persistit persistit)
Construct a
Value object with default initial and maximum
encoded sizes. |
Value(Persistit persistit,
int initialSize)
Construct a
Value object with specified initial encoded size
and default maximum size. |
Value(Persistit persistit,
int initialSize,
int maximumSize)
Construct a
Value object with specific initial encoded size
and specified maximum size. |
Value(Value source)
Construct a new
Value that represents the same data as the
source. |
| Modifier and Type | Method and Description |
|---|---|
Value |
clear()
Remove all content from this
Value. |
void |
copyFromEncodedBytes(byte[] dest,
int from,
int to,
int length)
Copy a subarray from the encoded byte array to a target.
|
void |
copyTo(Value target)
Copy the state of this
Value to another Value. |
void |
decodeDisplayable(boolean quoted,
StringBuilder sb)
Appends a displayable, printable String version of a value into the
supplied StringBuilder.
|
void |
decodeDisplayable(boolean quoted,
StringBuilder sb,
CoderContext context)
Appends a displayable String version of a value into the supplied
StringBuilder.
|
Object |
directGet(ValueRenderer coder,
Class<?> clazz,
CoderContext context)
Optimized get method to be used in specialized circumstances where an
applications can supply a
ValueCoder directly. |
Object |
directGet(ValueRenderer coder,
Object target,
Class<?> clazz,
CoderContext context)
Optimized get method to be used in specialized circumstances where an
applications can supply a
ValueCoder directly. |
void |
directPut(ValueCoder coder,
Object object,
CoderContext context)
Optimized put method to be used in specialized circumstances where an
applications can supply a
ValueCoder directly. |
boolean |
ensureFit(int length)
Ensures that the specified number of bytes can be appended to the backing
byte array.
|
boolean |
equals(Object obj)
Implements the
equals method such that Value
and ValueState objects may be used interchangeably as map keys. |
Object |
get()
Decodes the object value represented by the current state of this
Value. |
Object |
get(Object target)
Decodes the object value represented by the current state of this
Value. |
Object |
get(Object target,
CoderContext context)
Decodes the object value represented by the current state of this
Value. |
Object |
getArray()
Decodes the array value represented by the current state of this
Value. |
int |
getArrayLength()
Returns the element count for the array represented by the current state
of this
Value. |
BigDecimal |
getBigDecimal()
Decodes the
java.math.BigDecimal value represented by the
current state of this Value. |
BigInteger |
getBigInteger()
Decodes the
java.math.BigInteger value represented by the
current state of this Value. |
boolean |
getBoolean()
Decodes the boolean value represented by the current state of this
Value. |
boolean[] |
getBooleanArray()
Returns a
boolean array representing the state of this
Value. |
int |
getBooleanArray(boolean[] array,
int fromOffset,
int toOffset,
int length)
Copies a subarray of the
boolean array represented by the
state of this Value into the supplied target array. |
byte |
getByte()
Decodes the byte value represented by the current state of this
Value. |
byte[] |
getByteArray()
Returns a
byte array representing the state of this
Value. |
int |
getByteArray(byte[] array,
int fromOffset,
int toOffset,
int length)
Copies a subarray of the
byte array represented by the state
of this Value into the supplied target array. |
char |
getChar()
Decodes the char value represented by the current state of this
Value. |
char[] |
getCharArray()
Returns a
char array representing the state of this
Value. |
int |
getCharArray(char[] array,
int fromOffset,
int toOffset,
int length)
Copies a subarray of the
char array represented by the state
of this Value into the supplied target array. |
int |
getCursor() |
Date |
getDate()
Decodes the
java.util.Date value represented by the current
state of this Value. |
double |
getDouble()
Decodes the double value represented by the current state of this
Value. |
double[] |
getDoubleArray()
Returns a
double array representing the state of this
Value. |
int |
getDoubleArray(double[] array,
int fromOffset,
int toOffset,
int length)
Copies a subarray of the
double array represented by the
state of this Value into the supplied target array. |
byte[] |
getEncodedBytes()
Returns the backing byte array used to hold the state of this
Value. |
int |
getEncodedSize()
Returns the number of bytes used to encode the current value.
|
float |
getFloat()
Decodes the float value represented by the current state of this
Value. |
float[] |
getFloatArray()
Returns a
float array representing the state of this
Value. |
int |
getFloatArray(float[] array,
int fromOffset,
int toOffset,
int length)
Copies a subarray of the
float array represented by the
state of this Value into the supplied target array. |
int |
getInt()
Decodes the int value represented by the current state of this
Value. |
int[] |
getIntArray()
Returns a
int array representing the state of this
Value. |
int |
getIntArray(int[] array,
int fromOffset,
int toOffset,
int length)
Copies a subarray of the
int array represented by the state
of this Value into the supplied target array. |
long |
getLong()
Decodes the long value represented by the current state of this
Value. |
long[] |
getLongArray()
Returns a
long array representing the state of this
Value. |
int |
getLongArray(long[] array,
int fromOffset,
int toOffset,
int length)
Copies a subarray of the
long array represented by the state
of this Value into the supplied target array. |
int |
getMaximumSize()
Returns the maximum size to which the backing buffer can grow.
|
Object |
getNull()
Decodes the object value represented by the current state of this
Value and verifies that it is null. |
Object[] |
getObjectArray()
Returns a
Object array representing the state of this
Value. |
ObjectInputStream |
getObjectInputStream()
Return a
java.io.ObjectInputStream that reads bytes from
this Value. |
ObjectOutputStream |
getObjectOutputStream()
Return a
java.io.ObjectOutputStream that writes bytes
directly into this Value. |
short |
getShort()
Decodes the short value represented by the current state of this
Value. |
short[] |
getShortArray()
Returns a
short array representing the state of this
Value. |
int |
getShortArray(short[] array,
int fromOffset,
int toOffset,
int length)
Copies a subarray of the
short array represented by the
state of this Value into the supplied target array. |
String |
getString()
Decodes the
java.lang.String value represented by the
current state of this Value. |
<T extends Appendable> |
getString(T sb)
Decodes the
java.lang.String value represented by the
current state of this Value into a supplied
java.lang.Appendable. |
String[] |
getStringArray()
Returns a
Object array representing the state of this
Value. |
Class<?> |
getType()
Returns the type of the object represented by the current state of this
Value. |
int |
hashCode()
Hash code for the current state of this
Value. |
boolean |
hasMoreItems()
Indicates whether there is at least one more item in this
Value. |
boolean |
isDefined()
Indicates whether there is data associated with this
Value. |
boolean |
isNull()
Tests whether the data held by this
Value is null. |
boolean |
isNull(boolean skipNull)
Determine whether the data held by this
Value is null. |
boolean |
isStreamMode()
Indicates whether stream mode is enabled.
|
boolean |
isType(Class<?> clazz) |
Value.OldValueInputStream |
oldValueInputStream(ObjectStreamClass classDescriptor) |
com.persistit.Value.OldValueOutputStream |
oldValueOutputStream(ObjectStreamClass classDescriptor) |
Object |
peek()
Decodes the object value represented by the current state of this
Value. |
Object |
peek(Object target)
Decodes the object value represented by the current state of this
Value. |
Object |
peek(Object target,
CoderContext context)
Decodes the object value represented by the current state of this
Value. |
void |
put(boolean booleanValue)
Replaces the current state with the supplied
boolean value
(or in stream mode, appends a new field
containing this value to the state). |
void |
put(byte byteValue)
Replaces the current state with the supplied
byte value (or
in stream mode, appends a new field containing
this value to the state). |
void |
put(char charValue)
Replaces the current state with the supplied
char value (or
in stream mode, appends a new field
containing this value to the state). |
void |
put(double doubleValue)
Replaces the current state with the supplied
double value
(or in stream mode, appends a new field
containing this value to the state). |
void |
put(float floatValue)
Replaces the current state with the supplied
float value (or
in stream mode, appends a new field
containing this value to the state). |
void |
put(int intValue)
Replaces the current state with the supplied
int value (or
in stream mode, appends a new field
containing this value to the state). |
void |
put(long longValue)
Replaces the current state with the supplied
long value (or
in stream mode, appends a new field
containing this value to the state). |
void |
put(Object object)
Replaces the current state with the supplied
Object (or in
stream mode, appends a new field
containing this value to the state). |
void |
put(Object object,
CoderContext context)
Replaces the current state with the supplied
Object (or in
stream mode, appends a new field
containing this value to the state). |
void |
put(short shortValue)
Replaces the current state with the supplied
short value (or
in stream mode, appends a new field
containing this value to the state). |
void |
putBigDecimal(BigDecimal bigDecimalValue)
Replaces the current state with the supplied
java.math.BigDecimal (or in stream
mode, appends a new field containing this value to the state). |
void |
putBigInteger(BigInteger bigIntValue)
Replaces the current state with the supplied
java.math.BigInteger (or in stream
mode, appends a new field containing this value to the state). |
void |
putBooleanArray(boolean[] array)
Replaces the current state with the supplied
boolean (or in
stream mode, appends a new field
containing this array to the state). |
void |
putBooleanArray(boolean[] array,
int offset,
int length)
Replaces the current state with a subarray of the supplied array of
boolean-valued elements (or in stream mode, appends a new field containing
this subarray to the state). |
void |
putByteArray(byte[] array)
Replaces the current state with the supplied
byte array, (or
in stream mode, appends a new field
containing this array to the state). |
void |
putByteArray(byte[] array,
int offset,
int length)
Replaces the current state with a subarray of the supplied array of
byte-valued elements (or in stream
mode, appends a new field containing this subarray to the state). |
void |
putCharArray(char[] array)
Replaces the current state with the supplied
char array (or
in stream mode, appends a new field
containing this array to the state). |
void |
putCharArray(char[] array,
int offset,
int length)
Replaces the current state with a subarray of the supplied array of
char-valued elements (or in stream
mode, appends a new field containing this subarray to the state). |
void |
putDate(Date dateValue)
Replaces the current state with the supplied
java.util.Date
(or in stream mode, appends a new field
containing this value to the state). |
void |
putDoubleArray(double[] array)
Replaces the current state with the supplied
double array
(or in stream mode, appends a new field
containing this array to the state). |
void |
putDoubleArray(double[] array,
int offset,
int length)
Replaces the current state with a subarray of the supplied array of
double-valued elements (or in stream mode, appends a new field containing
this subarray to the state). |
void |
putEncodedBytes(byte[] from,
int offset,
int length)
Replace the encoded value with bytes from a supplied array.
|
void |
putFloatArray(float[] array)
Replaces the current state with the supplied
float array (or
in stream mode, appends a new field
containing this array to the state). |
void |
putFloatArray(float[] array,
int offset,
int length)
Replaces the current state with a subarray of the supplied array of
float-valued elements (or in stream mode, appends a new field containing
this subarray to the state). |
void |
putIntArray(int[] array)
Replaces the current state with the supplied
int array (or
in stream mode, appends a new field
containing this array to the state). |
void |
putIntArray(int[] array,
int offset,
int length)
Replaces the current state with a subarray of the supplied array of
int-valued elements (or in stream
mode, appends a new field containing this subarray to the state). |
void |
putLongArray(long[] array)
Replaces the current state with the supplied
long array (or
in stream mode, appends a new field
containing this array to the state). |
void |
putLongArray(long[] array,
int offset,
int length)
Replaces the current state with a subarray of the supplied array of
long-valued elements (or in stream
mode, appends a new field containing this subarray to the state). |
void |
putNull()
Replaces the current state with null (or in stream mode, appends a null to the state).
|
void |
putObjectArray(Object[] array)
Replaces the current state with the supplied
Object array
(or in stream mode, appends a new field
containing this array to the state). |
void |
putObjectArray(Object[] array,
int offset,
int length)
Replaces the current state with a subarray of the supplied array of
Object-valued elements (or in stream mode, appends a new field containing
this subarray to the state). |
void |
putShortArray(short[] array)
Replaces the current state with the supplied
short array (or
in stream mode, appends a new field
containing this array to the state). |
void |
putShortArray(short[] array,
int offset,
int length)
Replaces the current state with a subarray of the supplied array of
short-valued elements (or in stream mode, appends a new field containing
this subarray to the state). |
void |
putString(CharSequence sb)
Replaces the current state with the String represented by the supplied
CharSequence (or in stream mode,
appends a new field containing this value to the state).
|
void |
putString(String string)
Replaces the current state with the supplied
java.lang.String (or in stream
mode, appends a new field containing this value to the state). |
void |
putStringArray(String[] array)
Replaces the current state with the supplied
String array
(or in stream mode, appends a new field
containing this array to the state). |
void |
putStringArray(String[] array,
int offset,
int length)
Replaces the current state with a subarray of the supplied array of
String-valued elements (or in stream mode, appends a new field containing
this subarray to the state). |
void |
putUTF(String string)
Replaces the current state with the supplied
java.lang.String (or in stream
mode, appends a new field containing this value to the state). |
void |
registerEncodedObject(Object object)
Registers an object with an internal handle used to represent back
references.
|
void |
setCursor(int cursor) |
void |
setEncodedSize(int size)
Sets the length of the encoded data in the backing byte array.
|
void |
setMaximumSize(int size)
Deprecated.
use
Exchange.setMaximumValueSize(int). This method should not be public. |
void |
setStreamMode(boolean b)
Enables or disables stream mode.
|
void |
skip()
Does nothing except when this
Value is in stream
mode. |
String |
toString()
Provides a String representation of the state of this
Value. |
boolean |
trim()
Reduce the backing byte buffer to the minimal length needed to represent
the current state.
|
boolean |
trim(int newSize)
Reduce the backing byte buffer to the greater of the minimal length
needed to represent the current state and the specified lower bound.
|
public static final Value EMPTY_VALUE
isDefined()
is always false.public static final int INITIAL_SIZE
Value
.public static final int DEFAULT_MAXIMUM_SIZE
public static final int MAXIMUM_SIZE
public Value(Persistit persistit)
Value object with default initial and maximum
encoded sizes.public Value(Persistit persistit, int initialSize)
Value object with specified initial encoded size
and default maximum size.initialSize - Initial size of the encoded value buffer.public Value(Persistit persistit, int initialSize, int maximumSize)
Value object with specific initial encoded size
and specified maximum size.initialSize - Initial size of the encoded value buffer.maximumSize - Maximum size of the encoded value buffer.public Value(Value source)
Value that represents the same data as the
source.source - A Value whose state should be copied as the
initial state of this Value.public Value clear()
Value. This method also
disables stream mode.public void copyTo(Value target)
Value to another Value.target - The Value to which state should be copied.public int hashCode()
Value. Note that if
the underlying state changes, hashCode will produce a
different result. Construct a ValueState instance to hold an
immutable copy of the current state of a Value.public boolean equals(Object obj)
equals method such that Value
and ValueState objects may be used interchangeably as map keys.public boolean trim()
true if the size was actually reduced.public boolean trim(int newSize)
newSize - the minimum size of the backing buffer.true if the size was actually reduced.public boolean ensureFit(int length)
Ensures that the specified number of bytes can be appended to the backing
byte array. If the available space is too small, this method replaces the
array with a new one having at least length available bytes.
Applications using the low-level API must call getEncodedBytes()
to get a reference to the new array after this replacement has occurred.
This method is part of the Low-Level API.
length - true if the backing byte array was replaced by a
larger array.public void copyFromEncodedBytes(byte[] dest,
int from,
int to,
int length)
dest - The target byte arrayfrom - Offset from which to start the copyto - Offset into the target at which the subarray should be copiedlength - Number of bytes to copyArrayIndexOutOfBoundsExceptionpublic int getEncodedSize()
public void putEncodedBytes(byte[] from,
int offset,
int length)
from - Byte array from which to copy the encoded valueoffset - Offset to first byte in the supplied array from which to copylength - Number of bytes to copyArrayIndexOutOfBoundsException - if the supplied offset or size exceed the bounds of the
supplied arrayConversionException - if the resulting value size exceeds the maximum sizepublic byte[] getEncodedBytes()
Value. This method is part of the Low-Level API.public void setEncodedSize(int size)
store operation.
This method is part of the Low-Level API.public int getMaximumSize()
@Deprecated public void setMaximumSize(int size)
Exchange.setMaximumValueSize(int). This method should not be public.size - The maximum sizeIllegalArgumentException - If the backing buffer is already larger than
size, this methodpublic int getCursor()
public void setCursor(int cursor)
public void setStreamMode(boolean b)
b - true to enable stream mode, false to
disable it.public boolean isStreamMode()
true if stream mode is enabled.public boolean isDefined()
Value.
The result of fetching a Key that has no associated record
in the database leaves the corresponding Value in an
undefined state. Note that a Value containing null is
defined. Persistit distinguishes between null and undefined states.true if there is data represented by this
Value .public boolean isNull()
Value is null.true if the current state of this Value
represents null.public boolean isNull(boolean skipNull)
Value is null. As a
side effect, if skipNull is true and Stream Mode is enabled this method also advances
the cursor to the next field if the current field is null.skipNull - if true, the Value is in stream mode
and the current field is null, then advance the cursor to next
fieldtrue if the current state of this Value
represents null.public String toString()
Value.toString in class ObjecttoString on a Value whose
state represents the string "undefined". Invoke the
isDefined() method to determine reliably whether the
Value is defined.decodeDisplayable(boolean, StringBuilder)public void decodeDisplayable(boolean quoted,
StringBuilder sb)
quoted is true, then
the all String values in the result will be enclosed and converted to a
printable format.quoted - true to quote and convert all strings to
printable form.sb - A StringBuilder to which the displayable value
will be appended.decodeDisplayable(boolean, StringBuilder, CoderContext)public void decodeDisplayable(boolean quoted,
StringBuilder sb,
CoderContext context)
quoted is true, then the all
String values in the result will be enclosed and converted to a printable
format.quoted - true to quote and convert all strings to
printable form.sb - A StringBuilder to which the displayable value
will be appended.context - A CoderContext to be passed to any underlying
ValueDisplayer.public Class<?> getType()
Value.public boolean isType(Class<?> clazz)
public Object getNull()
Value and verifies that it is null.nullConversionException - if this Value does not currently represent
null.public boolean getBoolean()
Value.ConversionException - if this Value does not currently represent data
of this type.public byte getByte()
Value.ConversionException - if this Value does not currently represent data
of this type.public short getShort()
Value.ConversionException - if this Value does not currently represent data
of this type.public char getChar()
Value.ConversionException - if this Value does not currently represent data
of this type.public int getInt()
Value.ConversionException - if this Value does not currently represent data
of this type.public long getLong()
Value.ConversionException - if this Value does not currently represent data
of this type.public float getFloat()
Value.ConversionException - if this Value does not currently represent data
of this type.public double getDouble()
Value.ConversionException - if this Value does not currently represent data
of this type.public Object peek()
Value. This method is identical to get() except
that in Stream Mode the pointer to the next
retrieved value is not advanced.ConversionException - if this Value does not currently represent data
of a recognizable class.MalformedValueException - if this Value is structurally corrupt.public Object peek(Object target)
Decodes the object value represented by the current state of this
Value. This method is identical to get(Object)
except that in Stream Mode the pointer to the
next retrieved value is not advanced.
This variant of get may modify and return the target
object supplied as a parameter, rather than creating a new object. This
behavior will occur only if the encoded value has a registered
ValueRenderer. See the documentation for
ValueRenderer for more information.
target - A mutable object into which a ValueRenderer may
decode this Value.ConversionException - if this Value does not currently represent data
of a recognizable class.MalformedValueException - if this Value is structurally corrupt.public Object peek(Object target, CoderContext context)
Decodes the object value represented by the current state of this
Value. This method is identical to
get(Object, CoderContext) except that in Stream Mode the pointer to the next retrieved
value is not advanced.
target - A mutable object into which a ValueRenderer may
decode this Value.ConversionException - if this Value does not currently represent data
of a recognizable class.MalformedValueException - if this Value is structurally corrupt.public Object get()
Value. If the represented value is primitive, this method
returns the wrapped object of the corresponding class. For example, if
the value represents an int, this method returns a
java.lang.Integer.ConversionException - if this Value does not currently represent data
of a recognizable class.MalformedValueException - if this Value is structurally corrupt.public Object get(Object target)
Decodes the object value represented by the current state of this
Value. If the represented value is primitive, this method
returns the wrapped object of the corresponding class. For example, if
the value represents an int, this method returns a
java.lang.Integer.
This variant of get may modify and return the target
object supplied as a parameter, rather than creating a new object. This
behavior will occur only if the encoded value has a registered
ValueRenderer. See the documentation for
ValueRenderer for more information.
target - A mutable object into which a ValueRenderer may
decode this Value.ConversionException - if this Value does not currently represent data
of a recognizable class.MalformedValueException - if this Value is structurally corrupt.public Object get(Object target, CoderContext context)
Decodes the object value represented by the current state of this
Value. If the represented value is primitive, this method
returns the wrapped object of the corresponding class. For example, if
the value represents an int, this method returns a
java.lang.Integer.
This variant of get may modify and return the target
object supplied as a parameter, rather than creating a new object. This
behavior will occur only if the encoded value has an associated
ValueRenderer registered by CoderManager. See the
documentation for those classes for a detailed explanation of value
rendering.
target - A mutable object into which a ValueRenderer may
decode this Value.context - An application-specified value that may assist a
ValueCoder. The context is passed to the
ValueCoder.get(com.persistit.Value, java.lang.Class<?>, com.persistit.encoding.CoderContext) method.ConversionException - if this Value does not currently represent data
of a recognizable class.MalformedValueException - if this Value is structurally corrupt.public void registerEncodedObject(Object object)
ValueCoder.get(Value, Class, CoderContext) method of custom
ValueCoders. See Parameters:
object - A newly created objected whose fields are about to be
deserializedpublic String getString()
java.lang.String value represented by the
current state of this Value.ConversionException - if this Value does not currently represent a
String.public <T extends Appendable> Appendable getString(T sb)
java.lang.String value represented by the
current state of this Value into a supplied
java.lang.Appendable.ConversionException - if this Value does not currently represent a
String.public Date getDate()
java.util.Date value represented by the current
state of this Value.ConversionException - if this Value does not currently represent a
Date.public BigInteger getBigInteger()
java.math.BigInteger value represented by the
current state of this Value.ConversionException - if this Value does not currently represent a
BigInteger.public BigDecimal getBigDecimal()
java.math.BigDecimal value represented by the
current state of this Value.ConversionException - if this Value does not currently represent a
BigDecimal.public int getArrayLength()
Value.null rather than an array.ConversionException - if this Value does not currently represent an
array.public Object getArray()
Value.ConversionException - if this Value does not currently represent an
array.public boolean[] getBooleanArray()
boolean array representing the state of this
Value. Equivalent to (boolean)[])get().public int getBooleanArray(boolean[] array,
int fromOffset,
int toOffset,
int length)
boolean array represented by the
state of this Value into the supplied target array. The
subarray is bounded by fromOffset and length,
and truncated to fit within the target array.array - The target arrayfromOffset - Offset of the first element within the source array to copy
fromtoOffset - Offset of the first element within the target array to copy tolength - The maximum number of elements to copy.Value object represents null.public byte[] getByteArray()
byte array representing the state of this
Value. Equivalent to (byte[])get().public int getByteArray(byte[] array,
int fromOffset,
int toOffset,
int length)
byte array represented by the state
of this Value into the supplied target array. The subarray
is bounded by fromOffset and length, and
truncated to fit within the target array.array - The target arrayfromOffset - Offset of the first element within the source array to copy
fromtoOffset - Offset of the first element within the target array to copy tolength - The maximum number of elements to copy.Value object represents null.public short[] getShortArray()
short array representing the state of this
Value. Equivalent to (short[])get().public int getShortArray(short[] array,
int fromOffset,
int toOffset,
int length)
short array represented by the
state of this Value into the supplied target array. The
subarray is bounded by fromOffset and length,
and truncated to fit within the target array.array - The target arrayfromOffset - Offset of the first element within the source array to copy
fromtoOffset - Offset of the first element within the target array to copy tolength - The maximum number of elements to copy.Value object represents null.public char[] getCharArray()
char array representing the state of this
Value. Equivalent to (char[])get().public int getCharArray(char[] array,
int fromOffset,
int toOffset,
int length)
char array represented by the state
of this Value into the supplied target array. The subarray
is bounded by fromOffset and length, and
truncated to fit within the target array.array - The target arrayfromOffset - Offset of the first element within the source array to copy
fromtoOffset - Offset of the first element within the target array to copy tolength - The maximum number of elements to copy.Value object represents null.public int[] getIntArray()
int array representing the state of this
Value. Equivalent to (int[])get().public int getIntArray(int[] array,
int fromOffset,
int toOffset,
int length)
int array represented by the state
of this Value into the supplied target array. The subarray
is bounded by fromOffset and length, and
truncated to fit within the target array.array - The target arrayfromOffset - Offset of the first element within the source array to copy
fromtoOffset - Offset of the first element within the target array to copy tolength - The maximum number of elements to copy.Value object represents null.public long[] getLongArray()
long array representing the state of this
Value. Equivalent to (long[])get().public int getLongArray(long[] array,
int fromOffset,
int toOffset,
int length)
long array represented by the state
of this Value into the supplied target array. The subarray
is bounded by fromOffset and length, and
truncated to fit within the target array.array - The target arrayfromOffset - Offset of the first element within the source array to copy
fromtoOffset - Offset of the first element within the target array to copy tolength - The maximum number of elements to copy.Value object represents null.public float[] getFloatArray()
float array representing the state of this
Value. Equivalent to (float[])get().public int getFloatArray(float[] array,
int fromOffset,
int toOffset,
int length)
float array represented by the
state of this Value into the supplied target array. The
subarray is bounded by fromOffset and length,
and truncated to fit within the target array.array - The target arrayfromOffset - Offset of the first element within the source array to copy
fromtoOffset - Offset of the first element within the target array to copy tolength - The maximum number of elements to copy.Value object represents null.public double[] getDoubleArray()
double array representing the state of this
Value. Equivalent to (double[])get().public int getDoubleArray(double[] array,
int fromOffset,
int toOffset,
int length)
double array represented by the
state of this Value into the supplied target array. The
subarray is bounded by fromOffset and length,
and truncated to fit within the target array.array - The target arrayfromOffset - Offset of the first element within the source array to copy
fromtoOffset - Offset of the first element within the target array to copy tolength - The maximum number of elements to copy.Value object represents null.public Object[] getObjectArray()
Object array representing the state of this
Value. This is equivalent to
(Object[])getArray().public String[] getStringArray()
Object array representing the state of this
Value. This is equivalent to
(Object[])getArray().public boolean hasMoreItems()
Value. This method is valid only if the Value is in Stream Mode. (See isStreamMode().)true if another item can be decoded from this
Value.public void put(boolean booleanValue)
boolean value
(or in stream mode, appends a new field
containing this value to the state).booleanValue - The new valuepublic void put(byte byteValue)
byte value (or
in stream mode, appends a new field containing
this value to the state).byteValue - The new valuepublic void put(short shortValue)
short value (or
in stream mode, appends a new field
containing this value to the state).shortValue - The new valuepublic void put(char charValue)
char value (or
in stream mode, appends a new field
containing this value to the state).charValue - The new valuepublic void put(int intValue)
int value (or
in stream mode, appends a new field
containing this value to the state).intValue - The new valuepublic void put(long longValue)
long value (or
in stream mode, appends a new field
containing this value to the state).longValue - The new valuepublic void put(float floatValue)
float value (or
in stream mode, appends a new field
containing this value to the state).floatValue - The new valuepublic void put(double doubleValue)
double value
(or in stream mode, appends a new field
containing this value to the state).doubleValue - The new valuepublic void put(Object object)
Object (or in
stream mode, appends a new field
containing this value to the state).object - The new value. The supplied Object must be null, or it
must implement java.io.Serializable or
java.io.Externalizable, or it must be handled by
a registered ValueCoder.ConversionException - if the Object cannot be encoded as a sequence of bytes.public void put(Object object, CoderContext context)
Object (or in
stream mode, appends a new field
containing this value to the state).object - The new value. The supplied Object must be null, or it
must implement java.io.Serializable or
java.io.Externalizable, or it must be handled by
a registered ValueCoder.context - An application-specified value that may assist a
ValueCoder. The context is passed to the
ValueCoder.put(com.persistit.Value, java.lang.Object, com.persistit.encoding.CoderContext) method.ConversionException - if the Object cannot be encoded as a sequence of bytes.public void putNull()
public void putString(String string)
java.lang.String (or in stream
mode, appends a new field containing this value to the state).string - The new valuepublic void putUTF(String string)
java.lang.String (or in stream
mode, appends a new field containing this value to the state).
Unlike putString, this method always writes a new copy of
the String rather than a reference to a previously written value. Thus on
deserialization, two copies of the same string written by this method
will result in two unique String objects.string - The new valuepublic void putString(CharSequence sb)
sb - The String value as a CharSequencepublic void putDate(Date dateValue)
java.util.Date
(or in stream mode, appends a new field
containing this value to the state).dateValue - The new valuepublic void putBigInteger(BigInteger bigIntValue)
java.math.BigInteger (or in stream
mode, appends a new field containing this value to the state).bigIntValue - The new valuepublic void putBigDecimal(BigDecimal bigDecimalValue)
java.math.BigDecimal (or in stream
mode, appends a new field containing this value to the state).bigDecimalValue - The new valuepublic void putBooleanArray(boolean[] array)
boolean (or in
stream mode, appends a new field
containing this array to the state).array - The new array valuepublic void putBooleanArray(boolean[] array,
int offset,
int length)
boolean-valued elements (or in stream mode, appends a new field containing
this subarray to the state).array - The arrayoffset - Offset of the subarray in arraylength - Length of the subarraypublic void putByteArray(byte[] array)
byte array, (or
in stream mode, appends a new field
containing this array to the state).array - The new array valuepublic void putByteArray(byte[] array,
int offset,
int length)
byte-valued elements (or in stream
mode, appends a new field containing this subarray to the state).array - The arrayoffset - Offset of the subarray in arraylength - Length of the subarraypublic void putShortArray(short[] array)
short array (or
in stream mode, appends a new field
containing this array to the state).array - The new array valuepublic void putShortArray(short[] array,
int offset,
int length)
short-valued elements (or in stream mode, appends a new field containing
this subarray to the state).array - The arrayoffset - Offset of the subarray in arraylength - Length of the subarraypublic void putCharArray(char[] array)
char array (or
in stream mode, appends a new field
containing this array to the state).array - The new array valuepublic void putCharArray(char[] array,
int offset,
int length)
char-valued elements (or in stream
mode, appends a new field containing this subarray to the state).array - The arrayoffset - Offset of the subarray in arraylength - Length of the subarraypublic void putIntArray(int[] array)
int array (or
in stream mode, appends a new field
containing this array to the state).array - The new array valuepublic void putIntArray(int[] array,
int offset,
int length)
int-valued elements (or in stream
mode, appends a new field containing this subarray to the state).array - The arrayoffset - Offset of the subarray in arraylength - Length of the subarraypublic void putLongArray(long[] array)
long array (or
in stream mode, appends a new field
containing this array to the state).array - The new array valuepublic void putLongArray(long[] array,
int offset,
int length)
long-valued elements (or in stream
mode, appends a new field containing this subarray to the state).array - The arrayoffset - Offset of the subarray in arraylength - Length of the subarraypublic void putFloatArray(float[] array)
float array (or
in stream mode, appends a new field
containing this array to the state).array - The new array valuepublic void putFloatArray(float[] array,
int offset,
int length)
float-valued elements (or in stream mode, appends a new field containing
this subarray to the state).array - The arrayoffset - Offset of the subarray in arraylength - Length of the subarraypublic void putDoubleArray(double[] array)
double array
(or in stream mode, appends a new field
containing this array to the state).array - The new array valuepublic void putDoubleArray(double[] array,
int offset,
int length)
double-valued elements (or in stream mode, appends a new field containing
this subarray to the state).array - The arrayoffset - Offset of the subarray in arraylength - Length of the subarraypublic void putStringArray(String[] array)
String array
(or in stream mode, appends a new field
containing this array to the state).array - The new array valuepublic void putStringArray(String[] array, int offset, int length)
String-valued elements (or in stream mode, appends a new field containing
this subarray to the state).array - The arrayoffset - Offset of the subarray in arraylength - Length of the subarraypublic void putObjectArray(Object[] array)
Object array
(or in stream mode, appends a new field
containing this array to the state).array - The new array valuepublic void putObjectArray(Object[] array, int offset, int length)
Object-valued elements (or in stream mode, appends a new field containing
this subarray to the state).array - The arrayoffset - Offset of the subarray in arraylength - Length of the subarraypublic void skip()
Value is in stream
mode. In stream mode, this method skips a field. It is generally
faster to skip a field rather than to get and
discard it because the value and its interior state do not actually need
to be decoded and constructed.public void directPut(ValueCoder coder, Object object, CoderContext context)
ValueCoder directly. This method
receives the ValueCoder to be used from the application and
therefore avoids the cost of looking it up from the class of the supplied
Object. For example, suppose the application has registered
a ValueCoder named myCoder to handle
serialization and deserialization for a class called MyClass
. The following
value.directPut(myCoder, myClassValue, context);
is equivalent to but somewhat faster than
value.put(myClassValue, context);
coder - The ValueCoder registered for the class of
objectobject - The object value to storecontext - The CoderContext or nullpublic Object directGet(ValueRenderer coder, Class<?> clazz, CoderContext context)
ValueCoder directly. This method
receives the ValueCoder to be used from the application and
therefore avoids the cost of looking it up from the class of the supplied
Object. For example, suppose the application has registered
a ValueCoder named myCoder to handle
serialization and deserialization for a class called MyClass
. The following
MyClass myClassValue = (MyClass)value.directGet(myCoder, context);
is equivalent to but somewhat faster than
MyClass myClassValue = (MyClass)value.get(null, context);
coder - The ValueCoder registered for the class of
objectclazz - The class of the object value to getcontext - The CoderContext or nullclazz, or nullpublic Object directGet(ValueRenderer coder, Object target, Class<?> clazz, CoderContext context)
ValueCoder directly. This method
receives the ValueCoder to be used from the application and
therefore avoids the cost of looking it up from the class of the supplied
Object. For example, suppose the application has registered
a ValueCoder named myCoder to handle
serialization and deserialization for a class called MyClass
. The following
MyClass myClassValue = new MyClass();
value.directGet(myCoder, myClassValue, context);
is equivalent to but somewhat faster than
MyClass myClassValue = new MyClass();
(MyClass)value.get(myClassValue, context);
coder - The ValueCoder registered for the class of
objecttarget - A mutable object of type clazz into which a
ValueRenderer may decode this
Value.clazz - The class of the object value to getcontext - The CoderContext or nullpublic ObjectOutputStream getObjectOutputStream() throws ConversionException
java.io.ObjectOutputStream that writes bytes
directly into this Value. The implementation returned by this method
overrides the standard implementation to work correctly within the
Persistit context. See Notes on Object
Serialization for details.ObjectOutputStreamConversionExceptionpublic ObjectInputStream getObjectInputStream() throws ConversionException
java.io.ObjectInputStream that reads bytes from
this Value. The implementation returned by this method overrides the
standard implementation to work correctly within the Persistit context.
See Notes on Object
Serialization for details.ObjectInputStreamConversionExceptionpublic Value.OldValueInputStream oldValueInputStream(ObjectStreamClass classDescriptor) throws IOException
IOExceptionpublic com.persistit.Value.OldValueOutputStream oldValueOutputStream(ObjectStreamClass classDescriptor) throws IOException
IOExceptionCopyright © 2025 Open Identity Platform Community. All rights reserved.