Package convex.core.data
Class AArrayBlob
- All Implemented Interfaces:
IValidated
,IWriteable
,Comparable<ABlob>
- Direct Known Subclasses:
AccountKey
,ANumericBlob
,Blob
,Hash
Abstract base class for binary data stored in Java arrays.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
protected int
protected byte[]
Fields inherited from class convex.core.data.ABlob
contentHash
Fields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAppend an additional data object to this, creating a new data object.byte
byteAt(long i)
Gets the byte at the specified position in this bloblong
Computes the length of the longest common hex prefix between two blobsint
compareTo(AArrayBlob b)
int
Compares this blob to another blob, in lexographic order sorting by first bytes.long
count()
Gets the length of this Blobint
encodeRaw(byte[] bs, int pos)
Writes this Cell's encoding to a byte array, excluding the tag byteboolean
equalsBytes(byte[] bytes, int byteOffset)
Tests if this Blob is equal to a subset of a byte arrayboolean
equalsBytes(ABlob k)
Tests if this Blob has exactly the same bytes as another BlobGets a byte buffer containing this Blob's data.void
getBytes(byte[] dest, int destOffset)
Copies the bytes from this blob to a given destinationint
getHexDigit(long digitPos)
Gets the specified hex digit from this data object.byte[]
Gets the internal array backing this Blob.int
Gets this offset into the internal array backing this Blob.int
Gets the number of Refs contained within this Cell.byte
getUnchecked(long i)
Gets the byte at the specified position in this data object, without bounds checking.boolean
hexMatches(ABlob key, int start, int end)
Tests if a specific range of hex digits are exactly equal.long
hexMatchLength(ABlob b, long start, long length)
Returns the number of matching hex digits in the given hex range of another blob.long
Gets the long value of this Blob if the length is exactly 8 bytes, otherwise throws an Exceptionboolean
rangeMatches(AArrayBlob b, int start, int end)
Tests if a specific range of bytes are exactly equal from this Blob with another Blobboolean
rangeMatches(ABlob b, int start, int end)
Tests if a specific range of bytes are exactly equal.slice(long start)
Gets a slice of this blob, as a new blob, starting from the given offset and extending to the end of the blob.slice(long start, long length)
Gets a contiguous slice of this blob, as a new Blob.toBlob()
Converts this object to a Blob instanceConverts this data object to a lowercase hex string representationvoid
toHexString(StringBuilder sb)
long
toLong()
Converts this Blob to the corresponding long value.void
updateDigest(MessageDigest digest)
void
validate()
Validates the complete structure of this object.void
Validates the local structure and invariants of this cell.int
writeToBuffer(byte[] bs, int pos)
Writes the raw byte contents of this blob to a byte arraywriteToBuffer(ByteBuffer bb)
Writes the raw byte contents of this blob to a ByteBuffer.Methods inherited from class convex.core.data.ABlob
computeHash, empty, equals, equals, get, getBytes, getChunk, getContentHash, getElementRef, getType, hashCode, hexEquals, hexEquals, hexLength, isRegularBlob, print, toByteBuffer, toCanonical, toHexString
Methods inherited from class convex.core.data.ACountable
isEmpty, size
Methods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, encode, equals, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getRef, getTag, isCanonical, isCVMValue, isEmbedded, mark, mark, toString, updateRefs, write
Methods inherited from class convex.core.data.AObject
attachEncoding, print
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface convex.core.data.IWriteable
estimatedEncodingSize
-
Field Details
-
store
protected final byte[] store -
offset
protected final int offset -
length
protected final int length
-
-
Constructor Details
-
AArrayBlob
protected AArrayBlob(byte[] bytes, int offset, int length)
-
-
Method Details
-
updateDigest
- Specified by:
updateDigest
in classABlob
-
slice
Description copied from class:ABlob
Gets a contiguous slice of this blob, as a new Blob. Shares underlying backing data where possible -
append
Description copied from class:ABlob
Append an additional data object to this, creating a new data object. -
slice
Description copied from class:ABlob
Gets a slice of this blob, as a new blob, starting from the given offset and extending to the end of the blob. Shares underlying backing data where possible. Returned Blob may not be the same type as the original Blob -
toBlob
Description copied from class:ABlob
Converts this object to a Blob instance -
compareTo
Description copied from class:ABlob
Compares this blob to another blob, in lexographic order sorting by first bytes. Note: This means that compareTo does not precisely match equality, because different blob types may be lexicographically equal but represent different values.- Specified by:
compareTo
in interfaceComparable<ABlob>
- Overrides:
compareTo
in classABlob
-
compareTo
-
getBytes
public final void getBytes(byte[] dest, int destOffset)Description copied from class:ABlob
Copies the bytes from this blob to a given destination -
writeToBuffer
Description copied from class:ABlob
Writes the raw byte contents of this blob to a ByteBuffer.- Specified by:
writeToBuffer
in classABlob
- Parameters:
bb
- ByteBuffer to write to- Returns:
- The passed ByteBuffer, after writing byte content
-
writeToBuffer
public int writeToBuffer(byte[] bs, int pos)Description copied from class:ABlob
Writes the raw byte contents of this blob to a byte array- Specified by:
writeToBuffer
in classABlob
- Parameters:
bs
- Byte array to write topos
- Starting position in byte array to write to- Returns:
- The position in the array after writing
-
encodeRaw
public int encodeRaw(byte[] bs, int pos)Description copied from class:ACell
Writes this Cell's encoding to a byte array, excluding the tag byte -
toHexString
Description copied from class:ABlob
Converts this data object to a lowercase hex string representation- Specified by:
toHexString
in classABlob
- Returns:
- Hex String representation
-
toHexString
- Specified by:
toHexString
in classABlob
-
count
public final long count()Description copied from class:ABlob
Gets the length of this Blob -
byteAt
public final byte byteAt(long i)Description copied from class:ABlob
Gets the byte at the specified position in this blob -
getUnchecked
public final byte getUnchecked(long i)Description copied from class:ABlob
Gets the byte at the specified position in this data object, without bounds checking. Only safe if index is known to be in bounds, otherwise result is undefined.- Specified by:
getUnchecked
in classABlob
- Parameters:
i
- Index of the byte to get- Returns:
- The byte at the specified position
-
getHexDigit
public int getHexDigit(long digitPos)Description copied from class:ABlob
Gets the specified hex digit from this data object. Result is undefined if index is out of bounds.- Overrides:
getHexDigit
in classABlob
- Parameters:
digitPos
- The position of the hex digit- Returns:
- The value of the hex digit, in the range 0-15 inclusive
-
getInternalArray
public byte[] getInternalArray()Gets the internal array backing this Blob. Use with caution!- Returns:
- Byte array backing this blob
-
getInternalOffset
public int getInternalOffset()Gets this offset into the internal array backing this Blob.- Returns:
- Offset into backing array
-
getByteBuffer
Description copied from class:ABlob
Gets a byte buffer containing this Blob's data. Will have remaining bytes equal to this Blob's size.- Specified by:
getByteBuffer
in classABlob
- Returns:
- A ByteBuffer containing the Blob's data.
-
equalsBytes
public boolean equalsBytes(byte[] bytes, int byteOffset)Description copied from class:ABlob
Tests if this Blob is equal to a subset of a byte array- Specified by:
equalsBytes
in classABlob
- Parameters:
bytes
- Byte array to compare withbyteOffset
- Offset into byte array- Returns:
- true if exactly equal, false otherwise
-
equalsBytes
Description copied from class:ABlob
Tests if this Blob has exactly the same bytes as another Blob- Specified by:
equalsBytes
in classABlob
- Parameters:
k
- Blob to compare with- Returns:
- True if byte content is exactly equal, false otherwise
-
rangeMatches
Tests if a specific range of bytes are exactly equal.- Parameters:
b
- Blob to compare withstart
- Start index of range (inclusive)end
- End index of range (exclusive)- Returns:
- true if digits are equal, false otherwise
-
rangeMatches
Tests if a specific range of bytes are exactly equal from this Blob with another Blob- Parameters:
b
- Blob with which to comparestart
- Start index in both Blobsend
- End index in both Blobs- Returns:
- true if digits are equal, false otherwise
-
hexMatchLength
Description copied from class:ABlob
Returns the number of matching hex digits in the given hex range of another blob. Assumes range is valid for both blobs. Returns length if this Blob is exactly equal to the specified hex range.- Specified by:
hexMatchLength
in classABlob
- Parameters:
b
- Blob to compare withstart
- Start position (in hex digits)length
- Length to compare (in hex digits)- Returns:
- The number of matching hex characters
-
hexMatches
Tests if a specific range of hex digits are exactly equal.- Parameters:
key
- Blob to compare withstart
- Start hex digit index (inclusive)end
- End hex digit index (Exclusive)- Returns:
- true if digits are equal, false otherwise
-
commonHexPrefixLength
Description copied from class:ABlob
Computes the length of the longest common hex prefix between two blobs- Specified by:
commonHexPrefixLength
in classABlob
- Parameters:
b
- Blob to compare with- Returns:
- The length of the longest common prefix in hex digits
-
validate
Description copied from interface:IValidated
Validates the complete structure of this object. It is necessary to ensure all child Refs are validated, so the general contract for validate is:- Call super.validate() - which will indirectly call validateCell()
- Call validate() on any contained cells in this class
- Specified by:
validate
in interfaceIValidated
- Overrides:
validate
in classABlob
- Throws:
InvalidDataException
- If the data Valie is invalid in any way
-
validateCell
Description copied from class:ACell
Validates the local structure and invariants of this cell. Called by validate() super implementation. Should validate directly contained data, but should not validate all other structure of this cell. In particular, should not traverse potentially missing child Refs.- Overrides:
validateCell
in classABlob
- Throws:
InvalidDataException
- If the Cell is invalid
-
longValue
public long longValue()Description copied from class:ABlob
Gets the long value of this Blob if the length is exactly 8 bytes, otherwise throws an Exception -
toLong
public long toLong()Description copied from class:ABlob
Converts this Blob to the corresponding long value. Assumes big-endian format, as if the entire blob is interpreted as a signed big integer. Higher bytes outside the Long range will be ignored. -
getRefCount
public int getRefCount()Description copied from class:ACell
Gets the number of Refs contained within this Cell. This number is final / immutable for any given instance and is defined by the Cell encoding rules. Contained Refs may be either external or embedded.- Specified by:
getRefCount
in classACell
- Returns:
- The number of Refs in this Cell
-