Class Base64ArrayEncoding<T,E>

Type Parameters:
T - array type
E - array element type
All Implemented Interfaces:
Encoding<T>, NaturalSortAware, Serializable, Comparator<T>
Direct Known Subclasses:
DoubleArrayEncoding, FloatArrayEncoding, IntegralArrayEncoding

public abstract class Base64ArrayEncoding<T,E> extends ArrayEncoding<T,E>
Adds support for an alternate Base-64 String encoding for primitive array types. Does not support null arrays.
See Also:
  • Constructor Details

  • Method Details

    • fromString

      public T fromString(String string)
      Description copied from interface: Encoding
      Parse a non-null value previously encoded by toString(T).
      Specified by:
      fromString in interface Encoding<T>
      Overrides:
      fromString in class ArrayEncoding<T,E>
      Parameters:
      string - non-null value previously encoded as a String by toString(T)
      Returns:
      actual value
    • toString

      public String toString(T array)
      Description copied from interface: Encoding
      Encode a non-null value as a String for later decoding by fromString().

      Each of the characters in the returned String must be one of the valid XML characters (tab, newline, carriage return, \u0020 - \ud7ff, and \ue000 - \ufffd).

      Specified by:
      toString in interface Encoding<T>
      Overrides:
      toString in class ArrayEncoding<T,E>
      Parameters:
      array - actual value, never null
      Returns:
      string encoding of value acceptable to fromString()
      See Also:
    • toString

      public String toString(T array, boolean base64)
      Encode a non-null value as a String for later decoding by fromString().
      Parameters:
      array - array to encode
      base64 - true for base 64 synax, false for standard syntax
      Returns:
      string encoding of value acceptable to fromString()
      Throws:
      IllegalArgumentException - if value is null
    • useBase64Encoding

      protected boolean useBase64Encoding(T array)
      Invoked by toString(T) to determine whether to encode using base 64 or not.

      The implementation in Base64ArrayEncoding rerturns true for arrays longer than 16 elements.

      Parameters:
      array - array to be encoded, never null
      Returns:
      true for base 64 encoding, otherwise false
    • encode

      protected abstract void encode(T array, DataOutputStream output) throws IOException
      Throws:
      IOException
    • decode

      protected abstract T decode(DataInputStream input, int numBytes) throws IOException
      Throws:
      IOException
    • checkDecodeLength

      protected T checkDecodeLength(int numBytes)