Package squidpony

Class DataCompressor

java.lang.Object
com.badlogic.gdx.utils.Json
squidpony.store.json.JsonCompressor
squidpony.DataCompressor

public class DataCompressor
extends JsonCompressor
A variant of DataConverter (and an extension of libGDX's Json class) that compresses its JSON output and reads compressed input. Due to limits on the String compression library this uses (namely, it only compresses Strings, so input must be able to be interpreted as a String), this only allows String and FileHandle input formats, and throws exceptions if you try to deserialize a char array, InputStream, or Reader with fromJson() . Otherwise, it acts like DataConverter, so the same docs apply:
Augmented version of LibGDX's Json class that knows how to handle various data types common in SquidLib. This includes OrderedMap, which notably allows non-String keys (LibGDX's default Map serializer requires keys to be Strings), but does not currently allow the IHasher to be set (which only should affect OrderedMaps with array keys). It also makes significantly shorter serialized output for 2D char arrays, GreasedRegion and FakeLanguageGen objects, and various collections (IntDoubleOrderedMap, IntVLA, Arrangement, K2, and K2V1 at least). Created by Tommy Ettinger on 1/9/2017.
  • Nested Class Summary

    Nested classes/interfaces inherited from class com.badlogic.gdx.utils.Json

    com.badlogic.gdx.utils.Json.ReadOnlySerializer<T extends Object>, com.badlogic.gdx.utils.Json.Serializable, com.badlogic.gdx.utils.Json.Serializer<T extends Object>
  • Constructor Summary

    Constructors 
    Constructor Description
    DataCompressor()  
    DataCompressor​(com.badlogic.gdx.utils.JsonWriter.OutputType outputType)  
  • Method Summary

    Modifier and Type Method Description
    <T> T fromJson​(Class<T> type, char[] data, int offset, int length)  
    <T> T fromJson​(Class<T> type, com.badlogic.gdx.files.FileHandle file)  
    <T> T fromJson​(Class<T> type, InputStream input)  
    <T> T fromJson​(Class<T> type, Reader reader)  
    <T> T fromJson​(Class<T> type, Class elementType, char[] data, int offset, int length)  
    <T> T fromJson​(Class<T> type, Class elementType, com.badlogic.gdx.files.FileHandle file)  
    <T> T fromJson​(Class<T> type, Class elementType, InputStream input)  
    <T> T fromJson​(Class<T> type, Class elementType, Reader reader)  
    <T> T fromJson​(Class<T> type, Class elementType, String json)  
    <T> T fromJson​(Class<T> type, String json)  
    String toJson​(Object object, Class knownType, Class elementType)  
    void toJson​(Object object, Class knownType, Class elementType, com.badlogic.gdx.files.FileHandle file)  
    void toJson​(Object object, Class knownType, Class elementType, Writer writer)
    Deprecated.

    Methods inherited from class com.badlogic.gdx.utils.Json

    addClassTag, copyFields, getClass, getIgnoreUnknownFields, getSerializer, getTag, getWriter, ignoreUnknownField, newInstance, prettyPrint, prettyPrint, prettyPrint, prettyPrint, prettyPrint, prettyPrint, readField, readField, readField, readField, readField, readFields, readValue, readValue, readValue, readValue, readValue, readValue, readValue, setDefaultSerializer, setDeprecated, setElementType, setEnumNames, setIgnoreDeprecated, setIgnoreUnknownFields, setOutputType, setQuoteLongValues, setReadDeprecated, setSerializer, setSortFields, setTypeName, setUsePrototypes, setWriter, toJson, toJson, toJson, toJson, toJson, toJson, writeArrayEnd, writeArrayStart, writeArrayStart, writeField, writeField, writeField, writeField, writeFields, writeObjectEnd, writeObjectStart, writeObjectStart, writeObjectStart, writeObjectStart, writeType, writeValue, writeValue, writeValue, writeValue, writeValue, writeValue

    Methods inherited from class java.lang.Object

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

  • Method Details

    • toJson

      public String toJson​(Object object, Class knownType, Class elementType)
      Overrides:
      toJson in class JsonCompressor
      Parameters:
      object - The object to serialize
      knownType - May be null if the type is unknown.
      elementType - May be null if the type is unknown.
    • toJson

      public void toJson​(Object object, Class knownType, Class elementType, com.badlogic.gdx.files.FileHandle file)
      Overrides:
      toJson in class JsonCompressor
      Parameters:
      object - The object to serialize
      knownType - May be null if the type is unknown.
      elementType - May be null if the type is unknown.
      file - A LibGDX FileHandle that can be written to; overwrites, does not append
    • toJson

      @Deprecated public void toJson​(Object object, Class knownType, Class elementType, Writer writer)
      Deprecated.
      Don't use this, please! This method doesn't compress its output.
      Overrides:
      toJson in class JsonCompressor
      Parameters:
      object - The object to serialize
      knownType - May be null if the type is unknown.
      elementType - May be null if the type is unknown.
      writer - A Writer that will be the recipient of this class' JSON output
    • fromJson

      public <T> T fromJson​(Class<T> type, Reader reader)
      Overrides:
      fromJson in class JsonCompressor
      Parameters:
      type - May be null if the type is unknown.
      reader -
      Returns:
      May be null.
    • fromJson

      public <T> T fromJson​(Class<T> type, Class elementType, Reader reader)
      Overrides:
      fromJson in class JsonCompressor
      Parameters:
      type - May be null if the type is unknown.
      elementType - May be null if the type is unknown.
      reader -
      Returns:
      May be null.
    • fromJson

      public <T> T fromJson​(Class<T> type, InputStream input)
      Overrides:
      fromJson in class JsonCompressor
      Parameters:
      type - May be null if the type is unknown.
      input -
      Returns:
      May be null.
    • fromJson

      public <T> T fromJson​(Class<T> type, Class elementType, InputStream input)
      Overrides:
      fromJson in class JsonCompressor
      Parameters:
      type - May be null if the type is unknown.
      elementType - May be null if the type is unknown.
      input -
      Returns:
      May be null.
    • fromJson

      public <T> T fromJson​(Class<T> type, com.badlogic.gdx.files.FileHandle file)
      Overrides:
      fromJson in class JsonCompressor
      Parameters:
      type - May be null if the type is unknown.
      file -
      Returns:
      May be null.
    • fromJson

      public <T> T fromJson​(Class<T> type, Class elementType, com.badlogic.gdx.files.FileHandle file)
      Overrides:
      fromJson in class JsonCompressor
      Parameters:
      type - May be null if the type is unknown.
      elementType - May be null if the type is unknown.
      file -
      Returns:
      May be null.
    • fromJson

      public <T> T fromJson​(Class<T> type, char[] data, int offset, int length)
      Overrides:
      fromJson in class JsonCompressor
      Parameters:
      type - May be null if the type is unknown.
      data -
      offset -
      length -
      Returns:
      May be null.
    • fromJson

      public <T> T fromJson​(Class<T> type, Class elementType, char[] data, int offset, int length)
      Overrides:
      fromJson in class JsonCompressor
      Parameters:
      type - May be null if the type is unknown.
      elementType - May be null if the type is unknown.
      data -
      offset -
      length -
      Returns:
      May be null.
    • fromJson

      public <T> T fromJson​(Class<T> type, String json)
      Overrides:
      fromJson in class JsonCompressor
      Parameters:
      type - May be null if the type is unknown.
      json -
      Returns:
      May be null.
    • fromJson

      public <T> T fromJson​(Class<T> type, Class elementType, String json)
      Overrides:
      fromJson in class JsonCompressor
      Parameters:
      type - May be null if the type is unknown.
      elementType -
      json -
      Returns:
      May be null.