Class Blobs

java.lang.Object
convex.core.data.Blobs

public class Blobs extends Object
  • Field Details

    • MAX_ENCODING_LENGTH

      public static final int MAX_ENCODING_LENGTH
  • Constructor Details

    • Blobs

      public Blobs()
  • Method Details

    • createRandom

      public static <T extends ABlob> T createRandom(long length)
    • createRandom

      public static <T extends ABlob> T createRandom(Random r, long length)
    • toCanonical

      public static ABlob toCanonical(ABlob a)
      Converts any blob to a the correct canonical Blob format
      Parameters:
      a - Any Blob
      Returns:
      Canonical version s a Blob or BlobTree
    • fromHex

      public static ABlob fromHex(String a)
      Creates a blob from a hex string
      Parameters:
      a - Hex String
      Returns:
      Blob created, or null if String not valid hex
    • parse

      public static ABlob parse(Object o)
      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

      public static ABlob parse(String s)
      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

      public static ABlob read(ByteBuffer bb) throws BadFormatException
      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

      public static <T extends ABlob> T read(Blob source, int pos) throws BadFormatException
      Reads a canonical Blob from a byte source
      Type Parameters:
      T - Type of Blob result
      Parameters:
      source - Source blob, containing tag
      pos - position to read from source, assumed to be tag
      Returns:
      Canonical Blob
      Throws:
      BadFormatException - if the Blob encoding format is invalid
    • createFilled

      public static ABlob createFilled(int value, long length)
      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

      public static Blob empty()
    • zeroBasedArray

      public static byte[] zeroBasedArray(AArrayBlob b)
      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