Package convex.core.data
Class Blobs
java.lang.Object
convex.core.data.Blobs
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ABlob
createFilled
(int value, long length) Create a Blob entirely filled with a given valuestatic <T extends ABlob>
TcreateRandom
(long length) static <T extends ABlob>
TcreateRandom
(Random r, long length) static Blob
empty()
static ABlob
Creates a blob from a hex stringstatic ABlob
Best effort attempt to parse a Blob.static ABlob
Best effort attempt to parse a Blob.static <T extends ABlob>
TReads a canonical Blob from a byte sourcestatic ABlob
read
(ByteBuffer bb) Reads a Blob from an Encoding in a ByteBuffer.static ABlob
toCanonical
(ABlob a) Converts any blob to a the correct canonical Blob formatstatic byte[]
Gets a zero-based array containing the contents of the given Blob.
-
Field Details
-
MAX_ENCODING_LENGTH
public static final int MAX_ENCODING_LENGTH
-
-
Constructor Details
-
Blobs
public Blobs()
-
-
Method Details
-
createRandom
-
createRandom
-
toCanonical
Converts any blob to a the correct canonical Blob format- Parameters:
a
- Any Blob- Returns:
- Canonical version s a Blob or BlobTree
-
fromHex
Creates a blob from a hex string- Parameters:
a
- Hex String- Returns:
- Blob created, or null if String not valid hex
-
parse
Best effort attempt to parse a Blob. Must parse as a Blob of correct length- Parameters:
o
- Object expected to contain a Blob value- Returns:
- ABlob value, or null if not parseable
-
parse
Best effort attempt to parse a Blob. Must parse as a Blob of correct length. Leading "0x" optional.- Parameters:
s
- String expected to contain a HasBlobh value- Returns:
- ABlob value, or null if not parseable
-
read
Reads a Blob from an Encoding in a ByteBuffer.- Parameters:
bb
- ByteBuffer starting with a blob encoding, assumes tag already read- Returns:
- Blob read from ByteBuffer
- Throws:
BadFormatException
- If format is invalid
-
read
Reads a canonical Blob from a byte source- Type Parameters:
T
- Type of Blob result- Parameters:
source
- Source blob, containing tagpos
- position to read from source, assumed to be tag- Returns:
- Canonical Blob
- Throws:
BadFormatException
- if the Blob encoding format is invalid
-
createFilled
Create a Blob entirely filled with a given value- Parameters:
value
- Byte value to fill with (low 8 bits used)length
- Length of Blob to create- Returns:
- BlobTree filled with given value
-
empty
-
zeroBasedArray
Gets a zero-based array containing the contents of the given Blob. MAY use current internal array if possible.- Parameters:
b
- Blob to get array for- Returns:
- byte array containing the blob contents starting at offset zero
-