org.duelengine.duel
Class DataEncoder

java.lang.Object
  extended by org.duelengine.duel.DataEncoder

public class DataEncoder
extends Object

Utility for writing data as ECMAScript literals or JSON Inherently thread-safe as contains no mutable instance data.


Nested Class Summary
static class DataEncoder.Snippet
           
 
Constructor Summary
DataEncoder()
           
DataEncoder(String newline, String indent)
           
 
Method Summary
static DataEncoder.Snippet asSnippet(String text)
           
 String encode(Object data)
          Serializes the data as ECMAScript literals
 String encodeJSON(Object data)
          Serializes the data as JSON
 void indent(Appendable output, int depth)
           
 boolean isPrettyPrint()
           
 void write(Appendable output, Object data)
          Serializes the data as ECMAScript literals
 void write(Appendable output, Object data, int depth)
          Serializes the data as ECMAScript literals
 void writeJSON(Appendable output, Object data)
          Serializes the data as JSON
 void writeln(Appendable output, int depth)
           
 boolean writeNamespace(Appendable output, List<String> namespaces, String ident)
          Produces more compact namespace declarations.
 void writeNamespaceAlt(Appendable output, List<String> namespaces, String ident)
          Deprecated. 
 void writeVars(Appendable output, SparseMap items)
          Serializes the items as JavaScript variable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataEncoder

public DataEncoder()

DataEncoder

public DataEncoder(String newline,
                   String indent)
Method Detail

asSnippet

public static DataEncoder.Snippet asSnippet(String text)

isPrettyPrint

public boolean isPrettyPrint()

encode

public String encode(Object data)
Serializes the data as ECMAScript literals

Parameters:
data - Data to serialize
Returns:
encoded data

encodeJSON

public String encodeJSON(Object data)
Serializes the data as JSON

Parameters:
data - Data to serialize
Returns:
encoded data

writeJSON

public void writeJSON(Appendable output,
                      Object data)
               throws IOException
Serializes the data as JSON

Parameters:
output -
data - Data to serialize
Throws:
IOException

write

public void write(Appendable output,
                  Object data)
           throws IOException
Serializes the data as ECMAScript literals

Parameters:
output -
data - Data to serialize
Throws:
IOException

write

public void write(Appendable output,
                  Object data,
                  int depth)
           throws IOException
Serializes the data as ECMAScript literals

Parameters:
output -
data - Data to serialize
depth - Starting indentation depth
Throws:
IOException

writeNamespace

public boolean writeNamespace(Appendable output,
                              List<String> namespaces,
                              String ident)
                       throws IOException
Produces more compact namespace declarations.

Parameters:
output -
namespaces -
ident -
Returns:
true if namespaces were emitted
Throws:
IOException

writeNamespaceAlt

@Deprecated
public void writeNamespaceAlt(Appendable output,
                                         List<String> namespaces,
                                         String ident)
                       throws IOException
Deprecated. 

Produces more verbose but technically more correct namespace declarations

Parameters:
output -
namespaces -
ident -
Throws:
IOException

indent

public void indent(Appendable output,
                   int depth)
            throws IOException
Throws:
IOException

writeln

public void writeln(Appendable output,
                    int depth)
             throws IOException
Throws:
IOException

writeVars

public void writeVars(Appendable output,
                      SparseMap items)
               throws IOException
Serializes the items as JavaScript variable

Parameters:
output -
items - Variables to serialize
Throws:
IOException


Copyright © 2012. All Rights Reserved.