public class BinaryElement extends AbstractElement
Modifier and Type | Field and Description |
---|---|
static byte |
DEFAULT_SUB_TYPE
The sub type used when no sub type is specified.
|
static ElementType |
TYPE
The BSON type for a binary.
|
ELEMENT_TYPE
Constructor and Description |
---|
BinaryElement(String name,
byte[] value)
Constructs a new
BinaryElement . |
BinaryElement(String name,
byte subType,
BsonInputStream input,
int length)
Constructs a new
BinaryElement . |
BinaryElement(String name,
byte subType,
BsonInputStream input,
int length,
long size)
Constructs a new
BinaryElement . |
BinaryElement(String name,
byte subType,
byte[] value)
Constructs a new
BinaryElement . |
BinaryElement(String name,
byte subType,
byte[] value,
long size)
Constructs a new
BinaryElement . |
Modifier and Type | Method and Description |
---|---|
void |
accept(Visitor visitor)
Accepts the visitor and calls the
Visitor.visitBinary(java.lang.String, byte, byte[]) method. |
int |
compareTo(Element otherElement) |
boolean |
equals(Object object)
Determines if the passed object is of this same type as this object and
if so that its fields are equal.
|
byte |
get(int offset)
Returns the byte value at the specified offset.
|
byte |
getSubType()
Return the binary sub-type.
|
ElementType |
getType()
Returns the type for the BSON type.
|
byte[] |
getValue()
Returns the BSON binary value.
|
Object |
getValueAsObject()
Returns the value for BSON element as a Java
Object type. |
int |
hashCode()
Computes a reasonable hash code.
|
int |
length()
Returns the length of the contained byte array.
|
BinaryElement |
withName(String name)
Creates a new element with the same type and value as this element but
with the specified name.
|
asElement, find, find, findFirst, findFirst, getName, getValueAsString, nullSafeEquals, size, toString
public static final byte DEFAULT_SUB_TYPE
public static final ElementType TYPE
public BinaryElement(String name, byte subType, BsonInputStream input, int length) throws IOException
BinaryElement
.name
- The name for the BSON binary.subType
- The sub-type of the binary data.input
- The stream to read the data from.length
- The number of bytes of data to read.IllegalArgumentException
- If the name
is null
.IOException
- If there is an error reading from input
stream.public BinaryElement(String name, byte subType, BsonInputStream input, int length, long size) throws IOException
BinaryElement
.name
- The name for the BSON binary.subType
- The sub-type of the binary data.input
- The stream to read the data from.length
- The number of bytes of data to read.size
- The size of the element when encoded in bytes. If not known
then use the
BinaryElement(String, byte, BsonInputStream, int)
constructor instead.IllegalArgumentException
- If the name
is null
.IOException
- If there is an error reading from input
stream.public BinaryElement(String name, byte subType, byte[] value)
BinaryElement
.name
- The name for the BSON binary.subType
- The sub-type of the binary data.value
- The BSON binary value.IllegalArgumentException
- If the name
or value
is null
.public BinaryElement(String name, byte subType, byte[] value, long size)
BinaryElement
.name
- The name for the BSON binary.subType
- The sub-type of the binary data.value
- The BSON binary value.size
- The size of the element when encoded in bytes. If not known
then use the
BinaryElement(String, byte, byte[])
constructor instead.IllegalArgumentException
- If the name
or value
is null
.public BinaryElement(String name, byte[] value)
BinaryElement
. Uses the
DEFAULT_SUB_TYPE
.name
- The name for the BSON binary.value
- The BSON binary value.IllegalArgumentException
- If the name
or value
is null
.public void accept(Visitor visitor)
Visitor.visitBinary(java.lang.String, byte, byte[])
method.visitor
- The visitor for the element.Element.accept(Visitor)
public int compareTo(Element otherElement)
Overridden to compare the elements based on the tuple (name, type, value).
Overridden to compare the elements based on the tuple (name, type). Derived classes are responsible for the value portion of the full comparison.
Overridden to compare the sub-types and bytes if the base class comparison is equals.
compareTo
in interface Element
compareTo
in interface Comparable<Element>
compareTo
in class AbstractElement
public boolean equals(Object object)
equals
in class AbstractElement
object
- The object to compare to.Object.equals(java.lang.Object)
public final byte get(int offset)
offset
- The offset of the desired value.ArrayIndexOutOfBoundsException
- If the offset is not in the range [0, length()
).public byte getSubType()
public ElementType getType()
public byte[] getValue()
length()
and get(int)
methods to access each byte
value.public Object getValueAsObject()
Object
type.
Automatic conversion from the Object-ified value to an element is
provided via the DocumentBuilder.add(String, Object)
method. Not
all element types will be successfully converted to the same element
duing a Element-->Object value-->Element conversion. This cases are noted
in the appropriate sub-type's JavaDoc.
Sub-types will also overload this method with the appropriate type
returned. e.g., The
StringElement.getValueAsObject()
method signature returns a String
.
Returns a byte[].
Note: This value will not be recreated is a Object-->Element
conversion. The sub type is lost in this conversion to an Object
.
Implementation Note: The return type cannot be a byte[] here as
UuidElement
returns a UUID
.
Object
type.public int hashCode()
hashCode
in class AbstractElement
public final int length()
public BinaryElement withName(String name)
Returns a new BinaryElement
.
name
- The new name for the element.Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.