java.lang.Object
net.metanotion.io.data.StringBytes
All Implemented Interfaces:
Serializer<String>

public class StringBytesextends Object implements Serializer<String>
String serializer using US-ASCII encoding.

Converts between String objects and US-ASCII byte arrays. Only supports 7-bit ASCII characters.

Note: Use only when data is guaranteed to contain only US-ASCII. For Unicode text, use UTF8StringBytes instead.

If string contains characters outside US-ASCII range, an Error is thrown.

  • Constructor Details

    • StringBytes

      public StringBytes()
      The codec holds no state - the US-ASCII charset is named on every call - so a bare instance is ready to serialise.
  • Method Details

    • getBytes

      public byte[] getBytes(String o)
      Description copied from interface: Serializer
      o).
      Specified by:
      getBytes in interface Serializer<String>
      Parameters:
      o - the object to serialize
      Returns:
      the given object's serialized form as a byte array
    • construct

      public String construct(byte[] b)
      Description copied from interface: Serializer
      b).
      Specified by:
      construct in interface Serializer<String>
      Parameters:
      b - the serialized bytes to read back
      Returns:
      the deserialized object