Enum Class BinaryFormat

java.lang.Object
java.lang.Enum<BinaryFormat>
org.apache.juneau.marshall.BinaryFormat
All Implemented Interfaces:
Serializable, Comparable<BinaryFormat>, Constable

public enum BinaryFormat extends Enum<BinaryFormat>
Supported wire formats for byte[] values and stream-based serialization output.

Used by MarshallingContext.Builder.binaryFormat(BinaryFormat), Marshalled.binaryFormat(), MarshalledProp.binaryFormat(), and MarshalledConfig.binaryFormat() to control how byte[] values are written to and read from the wire on text formats, as well as the encoding used by stream-based serializers when converting their byte output to a string.

The default is NOT_SET — leaves byte[] handling to the surrounding serializer / parser (e.g. textual serializers fall back to the natural language-level array representation, and binary serializers emit native bytes). Callers wanting a textual encoding on the wire should set this to HEX, BASE64, SPACED_HEX, or BASE64_URL.

Binary serializers (BSON / CBOR / MsgPack / Prototext) emit native bytes regardless of the configured BinaryFormat; this setting only affects text-based serializers and the OutputStreamSerializerSession#writeToString(Object) stream-to-string convenience.

  • Enum Constant Details

    • NOT_SET

      public static final BinaryFormat NOT_SET
      Sentinel meaning "no value configured" — falls through to the next-higher precedence level.
    • SPACED_HEX

      public static final BinaryFormat SPACED_HEX
      Spaced-hex.
      Example:

      12 34 56 78 90 AB CD EF

    • HEX

      public static final BinaryFormat HEX
      Hex.
      Example:

      1234567890ABCDEF

    • BASE64

      public static final BinaryFormat BASE64
      Standard Base64 encoding.
    • BASE64_URL

      public static final BinaryFormat BASE64_URL
      URL-safe Base64 encoding (RFC 4648 §5).

      Uses - and _ in place of + and /. Padding (=) is omitted on the wire but accepted on input.

  • Method Details

    • values

      public static BinaryFormat[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static BinaryFormat valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • format

      public String format(byte[] value)
      Formats the specified value using this format.
      Parameters:
      value - The value to format. Can be null (returns null).
      Returns:
      The formatted string, or null if value is null.
    • parse

      public byte[] parse(String value)
      Parses the specified wire value using this format.

      The parser accepts any of the formats produced by format(byte[]) regardless of the configured constant, mirroring the format-agnostic parser convention used by other <type>Format enums in this package. The configured format is consulted only as a hint for ambiguous input.

      Parameters:
      value - The wire value. Can be null or blank (returns an empty array).
      Returns:
      The parsed bytes, or an empty array if value is null or blank.