Class Zappy

java.lang.Object
com.glitchybyte.zappy.Zappy

public final class Zappy extends Object
Encoding and decoding compressed web text for transport.

It uses base64 as the message encoding, but the internal bytes are compressed.

  • Constructor Details

    • Zappy

      public Zappy(Map<Integer,String[]> source)
      Creates a Zappy object ready to encode and decode messages.
      Parameters:
      source - The contraction source used for aiding compression. These will be overlaid on the default contractions that favors json. Whole tables are replaced in the overlay process, not individual items within a table. If source is null (and it has to be explicit by design), then only the default contractions are used. It is highly recommended users of this class add their own contractions.
  • Method Details

    • base64StringEncode

      public String base64StringEncode(String str)
      Encodes a string into a base64 string.

      Encodes with "-" and "_", and no padding.

      Parameters:
      str - Original string to encode.
      Returns:
      A base64 string.
    • base64StringDecode

      public String base64StringDecode(String str) throws ZappyParseException
      Decodes a base64 string.

      Expects encoding with "-" and "_", and no padding.

      Parameters:
      str - Base64 string.
      Returns:
      The decoded string.
      Throws:
      ZappyParseException - if it's an invalid base64 string.
    • encode

      public String encode(String str)
      Turns a string into a Zappy compressed string.
      Parameters:
      str - A string.
      Returns:
      A Zappy compressed string.
    • decode

      public String decode(String str) throws ZappyParseException
      Turns a Zappy compressed string into a string.
      Parameters:
      str - A Zappy compressed string.
      Returns:
      Expanded string.
      Throws:
      ZappyParseException - if it's an invalid Zappy string.