Class CBORDataUtilities

java.lang.Object
com.upokecenter.cbor.CBORDataUtilities

public final class CBORDataUtilities extends Object
Contains methods useful for reading and writing data, with a focus on CBOR.
  • Method Summary

    Modifier and Type
    Method
    Description
    static CBORObject
    ParseJSONNumber(byte[] bytes)
    Parses a number from a byte sequence whose format follows the JSON specification.
    static CBORObject
    ParseJSONNumber(byte[] bytes, int offset, int count)
    Parses a number whose format follows the JSON specification (RFC 8259) from a portion of a byte sequence, and converts that number to a CBOR object.
    static CBORObject
    ParseJSONNumber(byte[] bytes, int offset, int count, JSONOptions options)
    Parses a number from a byte sequence whose format follows the JSON specification (RFC 8259) and converts that number to a CBOR object.
    static CBORObject
    ParseJSONNumber(byte[] bytes, JSONOptions options)
    Parses a number from a byte sequence whose format follows the JSON specification (RFC 8259) and converts that number to a CBOR object.
    static CBORObject
    ParseJSONNumber(char[] chars)
    Parses a number from a sequence of char s whose format follows the JSON specification.
    static CBORObject
    ParseJSONNumber(char[] chars, int offset, int count)
    Parses a number whose format follows the JSON specification (RFC 8259) from a portion of a sequence of char s, and converts that number to a CBOR object.
    static CBORObject
    ParseJSONNumber(char[] chars, int offset, int count, JSONOptions options)
    Parses a number from a sequence of char s whose format follows the JSON specification (RFC 8259) and converts that number to a CBOR object.
    static CBORObject
    ParseJSONNumber(char[] chars, JSONOptions options)
    Parses a number from a sequence of char s whose format follows the JSON specification (RFC 8259) and converts that number to a CBOR object.
    static CBORObject
    Parses a number whose format follows the JSON specification.
    static CBORObject
    ParseJSONNumber(String str, boolean integersOnly, boolean positiveOnly)
    Deprecated.
    Call the one-argument version of this method instead.
    static CBORObject
    ParseJSONNumber(String str, boolean integersOnly, boolean positiveOnly, boolean preserveNegativeZero)
    Deprecated.
    Instead, call ParseJSONNumber(str, jsonoptions) with a JSONOptions that sets preserveNegativeZero to the desired value, either true or false.
    static CBORObject
    ParseJSONNumber(String str, int offset, int count)
    Parses a number whose format follows the JSON specification (RFC 8259) from a portion of a text string, and converts that number to a CBOR object.
    static CBORObject
    ParseJSONNumber(String str, int offset, int count, JSONOptions options)
    Parses a number whose format follows the JSON specification (RFC 8259) and converts that number to a CBOR object.
    static CBORObject
    Parses a number whose format follows the JSON specification (RFC 8259) and converts that number to a CBOR object.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • ParseJSONNumber

      public static CBORObject ParseJSONNumber(String str)
      Parses a number whose format follows the JSON specification. The method uses a JSONOptions with all default properties except for a PreserveNegativeZero property of false.
      Parameters:
      str - A text string to parse as a JSON number.
      Returns:
      A CBOR object that represents the parsed number. Returns positive zero if the number is a zero that starts with a minus sign (such as "-0" or "-0.0"). Returns null if the parsing fails, including if the string is null or empty.
    • ParseJSONNumber

      @Deprecated public static CBORObject ParseJSONNumber(String str, boolean integersOnly, boolean positiveOnly)
      Deprecated.
      Call the one-argument version of this method instead. If this method call used positiveOnly = true, check that the String does not begin with '-' before calling that version. If this method call used integersOnly = true, check that the String does not contain '.', 'E', or 'e' before calling that version.

      Parses a number whose format follows the JSON specification (RFC 8259). The method uses a JSONOptions with all default properties except for a PreserveNegativeZero property of false.

      Roughly speaking, a valid JSON number consists of an optional minus sign, one or more basic digits (starting with 1 to 9 unless there is only one digit and that digit is 0), an optional decimal point (".", full stop) with one or more basic digits, and an optional letter E or e with an optional plus or minus sign and one or more basic digits (the exponent). A text string representing a valid JSON number is not allowed to contain white space characters, including spaces.

      Parameters:
      str - A text string to parse as a JSON number.
      integersOnly - If true, no decimal points or exponents are allowed in the string. The default is false.
      positiveOnly - If true, only positive numbers are allowed (the leading minus is disallowed). The default is false.
      Returns:
      A CBOR object that represents the parsed number. Returns positive zero if the number is a zero that starts with a minus sign (such as "-0" or "-0.0"). Returns null if the parsing fails, including if the string is null or empty.
    • ParseJSONNumber

      @Deprecated public static CBORObject ParseJSONNumber(String str, boolean integersOnly, boolean positiveOnly, boolean preserveNegativeZero)
      Deprecated.
      Instead, call ParseJSONNumber(str, jsonoptions) with a JSONOptions that sets preserveNegativeZero to the desired value, either true or false. If this method call used positiveOnly = true, check that the String does not begin with '-' before calling that version. If this method call used integersOnly = true, check that the String does not contain '.', 'E', or 'e' before calling that version.

      Parses a number whose format follows the JSON specification (RFC 8259).

      Roughly speaking, a valid JSON number consists of an optional minus sign, one or more basic digits (starting with 1 to 9 unless there is only one digit and that digit is 0), an optional decimal point (".", full stop) with one or more basic digits, and an optional letter E or e with an optional plus or minus sign and one or more basic digits (the exponent). A text string representing a valid JSON number is not allowed to contain white space characters, including spaces.

      Parameters:
      str - A text string to parse as a JSON number.
      integersOnly - If true, no decimal points or exponents are allowed in the string. The default is false.
      positiveOnly - If true, the leading minus is disallowed in the string. The default is false.
      preserveNegativeZero - If true, returns positive zero if the number is a zero that starts with a minus sign (such as "-0" or "-0.0"). Otherwise, returns negative zero in this case. The default is false.
      Returns:
      A CBOR object that represents the parsed number. Returns null if the parsing fails, including if the string is null or empty.
    • ParseJSONNumber

      public static CBORObject ParseJSONNumber(String str, JSONOptions options)

      Parses a number whose format follows the JSON specification (RFC 8259) and converts that number to a CBOR object.

      Roughly speaking, a valid JSON number consists of an optional minus sign, one or more basic digits (starting with 1 to 9 unless there is only one digit and that digit is 0), an optional decimal point (".", full stop) with one or more basic digits, and an optional letter E or e with an optional plus or minus sign and one or more basic digits (the exponent). A text string representing a valid JSON number is not allowed to contain white space characters, including spaces.

      Parameters:
      str - A text string to parse as a JSON number.
      options - An object containing options to control how JSON numbers are decoded to CBOR objects. Can be null, in which case a JSONOptions object with all default properties is used instead.
      Returns:
      A CBOR object that represents the parsed number. Returns null if the parsing fails, including if the string is null or empty.
    • ParseJSONNumber

      public static CBORObject ParseJSONNumber(String str, int offset, int count)

      Parses a number whose format follows the JSON specification (RFC 8259) from a portion of a text string, and converts that number to a CBOR object.

      Roughly speaking, a valid JSON number consists of an optional minus sign, one or more basic digits (starting with 1 to 9 unless there is only one digit and that digit is 0), an optional decimal point (".", full stop) with one or more basic digits, and an optional letter E or e with an optional plus or minus sign and one or more basic digits (the exponent). A text string representing a valid JSON number is not allowed to contain white space characters, including spaces.

      Parameters:
      str - A text string containing the portion to parse as a JSON number.
      offset - An index, starting at 0, showing where the desired portion of str begins.
      count - The length, in code units, of the desired portion of str (but not more than str 's length).
      Returns:
      A CBOR object that represents the parsed number. Returns null if the parsing fails, including if the string is null or empty.
      Throws:
      IllegalArgumentException - Either offset or count is less than 0 or greater than str 's length, or str 's length minus offset is less than count.
      NullPointerException - The parameter str is null.
    • ParseJSONNumber

      public static CBORObject ParseJSONNumber(String str, int offset, int count, JSONOptions options)

      Parses a number whose format follows the JSON specification (RFC 8259) and converts that number to a CBOR object.

      Roughly speaking, a valid JSON number consists of an optional minus sign, one or more basic digits (starting with 1 to 9 unless there is only one digit and that digit is 0), an optional decimal point (".", full stop) with one or more basic digits, and an optional letter E or e with an optional plus or minus sign and one or more basic digits (the exponent). A text string representing a valid JSON number is not allowed to contain white space characters, including spaces.

      Parameters:
      str - A text string to parse as a JSON number.
      offset - An index, starting at 0, showing where the desired portion of str begins.
      count - The length, in code units, of the desired portion of str (but not more than str 's length).
      options - An object containing options to control how JSON numbers are decoded to CBOR objects. Can be null, in which case a JSONOptions object with all default properties is used instead.
      Returns:
      A CBOR object that represents the parsed number. Returns null if the parsing fails, including if the string is null or empty or count is 0 or less.
      Throws:
      NullPointerException - The parameter str is null.
      IllegalArgumentException - Unsupported conversion kind.
    • ParseJSONNumber

      public static CBORObject ParseJSONNumber(byte[] bytes, int offset, int count, JSONOptions options)

      Parses a number from a byte sequence whose format follows the JSON specification (RFC 8259) and converts that number to a CBOR object.

      Roughly speaking, a valid JSON number consists of an optional minus sign, one or more basic digits (starting with 1 to 9 unless there is only one digit and that digit is 0), an optional decimal point (".", full stop) with one or more basic digits, and an optional letter E or e with an optional plus or minus sign and one or more basic digits (the exponent). A byte sequence representing a valid JSON number is not allowed to contain white space characters, including spaces.

      Parameters:
      bytes - A sequence of bytes to parse as a JSON number.
      offset - An index, starting at 0, showing where the desired portion of bytes begins.
      count - The length, in code units, of the desired portion of bytes (but not more than bytes 's length).
      options - An object containing options to control how JSON numbers are decoded to CBOR objects. Can be null, in which case a JSONOptions object with all default properties is used instead.
      Returns:
      A CBOR object that represents the parsed number. Returns null if the parsing fails, including if the byte sequence is null or empty or count is 0 or less.
      Throws:
      NullPointerException - The parameter bytes is null.
      IllegalArgumentException - Unsupported conversion kind.
    • ParseJSONNumber

      public static CBORObject ParseJSONNumber(byte[] bytes, JSONOptions options)

      Parses a number from a byte sequence whose format follows the JSON specification (RFC 8259) and converts that number to a CBOR object.

      Roughly speaking, a valid JSON number consists of an optional minus sign, one or more basic digits (starting with 1 to 9 unless there is only one digit and that digit is 0), an optional decimal point (".", full stop) with one or more basic digits, and an optional letter E or e with an optional plus or minus sign and one or more basic digits (the exponent). A byte sequence representing a valid JSON number is not allowed to contain white space characters, including spaces.

      Parameters:
      bytes - A sequence of bytes to parse as a JSON number.
      options - An object containing options to control how JSON numbers are decoded to CBOR objects. Can be null, in which case a JSONOptions object with all default properties is used instead.
      Returns:
      A CBOR object that represents the parsed number. Returns null if the parsing fails, including if the byte sequence is null or empty.
    • ParseJSONNumber

      public static CBORObject ParseJSONNumber(byte[] bytes, int offset, int count)

      Parses a number whose format follows the JSON specification (RFC 8259) from a portion of a byte sequence, and converts that number to a CBOR object.

      Roughly speaking, a valid JSON number consists of an optional minus sign, one or more basic digits (starting with 1 to 9 unless there is only one digit and that digit is 0), an optional decimal point (".", full stop) with one or more basic digits, and an optional letter E or e with an optional plus or minus sign and one or more basic digits (the exponent). A byte sequence representing a valid JSON number is not allowed to contain white space characters, including spaces.

      Parameters:
      bytes - A sequence of bytes to parse as a JSON number.
      offset - An index, starting at 0, showing where the desired portion of bytes begins.
      count - The length, in code units, of the desired portion of bytes (but not more than bytes 's length).
      Returns:
      A CBOR object that represents the parsed number. Returns null if the parsing fails, including if the byte sequence is null or empty.
      Throws:
      IllegalArgumentException - Either offset or count is less than 0 or greater than bytes 's length, or bytes 's length minus offset is less than count.
      NullPointerException - The parameter bytes is null.
    • ParseJSONNumber

      public static CBORObject ParseJSONNumber(byte[] bytes)
      Parses a number from a byte sequence whose format follows the JSON specification. The method uses a JSONOptions with all default properties except for a PreserveNegativeZero property of false.
      Parameters:
      bytes - A byte sequence to parse as a JSON number.
      Returns:
      A CBOR object that represents the parsed number. Returns positive zero if the number is a zero that starts with a minus sign (such as "-0" or "-0.0"). Returns null if the parsing fails, including if the byte sequence is null or empty.
    • ParseJSONNumber

      public static CBORObject ParseJSONNumber(char[] chars, int offset, int count, JSONOptions options)

      Parses a number from a sequence of char s whose format follows the JSON specification (RFC 8259) and converts that number to a CBOR object.

      Roughly speaking, a valid JSON number consists of an optional minus sign, one or more basic digits (starting with 1 to 9 unless there is only one digit and that digit is 0), an optional decimal point (".", full stop) with one or more basic digits, and an optional letter E or e with an optional plus or minus sign and one or more basic digits (the exponent). A sequence of char s representing a valid JSON number is not allowed to contain white space characters, including spaces.

      Parameters:
      chars - A sequence of char s to parse as a JSON number.
      offset - An index, starting at 0, showing where the desired portion of chars begins.
      count - The length, in code units, of the desired portion of chars (but not more than chars 's length).
      options - An object containing options to control how JSON numbers are decoded to CBOR objects. Can be null, in which case a JSONOptions object with all default properties is used instead.
      Returns:
      A CBOR object that represents the parsed number. Returns null if the parsing fails, including if the sequence of char s is null or empty or count is 0 or less.
      Throws:
      NullPointerException - The parameter chars is null.
      IllegalArgumentException - Unsupported conversion kind.
    • ParseJSONNumber

      public static CBORObject ParseJSONNumber(char[] chars, JSONOptions options)

      Parses a number from a sequence of char s whose format follows the JSON specification (RFC 8259) and converts that number to a CBOR object.

      Roughly speaking, a valid JSON number consists of an optional minus sign, one or more basic digits (starting with 1 to 9 unless there is only one digit and that digit is 0), an optional decimal point (".", full stop) with one or more basic digits, and an optional letter E or e with an optional plus or minus sign and one or more basic digits (the exponent). A sequence of char s representing a valid JSON number is not allowed to contain white space characters, including spaces.

      Parameters:
      chars - A sequence of char s to parse as a JSON number.
      options - An object containing options to control how JSON numbers are decoded to CBOR objects. Can be null, in which case a JSONOptions object with all default properties is used instead.
      Returns:
      A CBOR object that represents the parsed number. Returns null if the parsing fails, including if the sequence of char s is null or empty.
    • ParseJSONNumber

      public static CBORObject ParseJSONNumber(char[] chars, int offset, int count)

      Parses a number whose format follows the JSON specification (RFC 8259) from a portion of a sequence of char s, and converts that number to a CBOR object.

      Roughly speaking, a valid JSON number consists of an optional minus sign, one or more basic digits (starting with 1 to 9 unless there is only one digit and that digit is 0), an optional decimal point (".", full stop) with one or more basic digits, and an optional letter E or e with an optional plus or minus sign and one or more basic digits (the exponent). A sequence of char s representing a valid JSON number is not allowed to contain white space characters, including spaces.

      Parameters:
      chars - A sequence of char s to parse as a JSON number.
      offset - An index, starting at 0, showing where the desired portion of chars begins.
      count - The length, in code units, of the desired portion of chars (but not more than chars 's length).
      Returns:
      A CBOR object that represents the parsed number. Returns null if the parsing fails, including if the sequence of char s is null or empty.
      Throws:
      IllegalArgumentException - Either offset or count is less than 0 or greater than chars 's length, or chars 's length minus offset is less than count.
      NullPointerException - The parameter chars is null.
    • ParseJSONNumber

      public static CBORObject ParseJSONNumber(char[] chars)
      Parses a number from a sequence of char s whose format follows the JSON specification. The method uses a JSONOptions with all default properties except for a PreserveNegativeZero property of false.
      Parameters:
      chars - A sequence of char s to parse as a JSON number.
      Returns:
      A CBOR object that represents the parsed number. Returns positive zero if the number is a zero that starts with a minus sign (such as "-0" or "-0.0"). Returns null if the parsing fails, including if the sequence of char s is null or empty.