Class OutputSerializer

java.lang.Object
marauroa.common.net.OutputSerializer

public class OutputSerializer extends Object
OutputSerializer is used to serialize classes that implement the Serializable interface into a OutputStream.
  • Constructor Details

    • OutputSerializer

      public OutputSerializer(OutputStream out)
      Constructor that defines a specified OutputStream for the serializer
      Parameters:
      out - the OutputStream to which objects are serialized
  • Method Details

    • write

      public void write(Serializable obj) throws IOException
      Add the Object to the serializer, if it implements the marauroa.common.net.Serializable interface
      Parameters:
      obj - the object to serialize
      Throws:
      IOException - in case of an IO-error
    • write

      public void write(byte a) throws IOException
      Add the byte to the serializer
      Parameters:
      a - the byte to serialize
      Throws:
      IOException - in case of an IO-error
    • write

      public void write(byte[] a) throws IOException
      Add the byte array to the serializer
      Parameters:
      a - the byte array to serialize
      Throws:
      IOException - in case of an IO-error
    • write255LongArray

      public void write255LongArray(byte[] a) throws IOException
      Add a byte array whose size is smaller than 255 to the serializer
      Parameters:
      a - the byte array to serialize
      Throws:
      IOException - in case of an IO-error
    • write65536LongArray

      public void write65536LongArray(byte[] a) throws IOException
      Add a long byte array whose size is smaller than 2^31 to the serializer
      Parameters:
      a - the byte array to serialize
      Throws:
      IOException - in case of an IO-error
    • write

      public void write(short a) throws IOException
      Add the short to the serializer
      Parameters:
      a - the short to serialize
      Throws:
      IOException - in case of an IO-error
    • write

      public void write(int a) throws IOException
      Add the int to the serializer
      Parameters:
      a - the int to serialize
      Throws:
      IOException - in case of an IO-error
    • write

      public void write(long a) throws IOException
      Add the long to the serializer
      Parameters:
      a - the long to serialize
      Throws:
      IOException - in case of an IO-error
    • write

      public void write(float a) throws IOException
      Add the float to the serializer
      Parameters:
      a - the int to serialize
      Throws:
      IOException - in case of an IO-error
    • write

      public void write(String a) throws IOException
      Add the String to the serializer, using UTF-8 encoding
      Parameters:
      a - the String to serialize
      Throws:
      IOException - in case of an IO-error
    • write255LongString

      public void write255LongString(String a) throws IOException
      Add a short string to the serializer, using UTF-8 encoding
      Parameters:
      a - the String to serialize
      Throws:
      IOException - in case of an IO-error
    • write65536LongString

      public void write65536LongString(String a) throws IOException
      /** Add a long string to the serializer, using UTF-8 encoding
      Parameters:
      a - the String to serialize
      Throws:
      IOException - in case of an IO-error
    • write

      public void write(String[] a) throws IOException
      Add the String array to the serializer, using UTF-8 encoding
      Parameters:
      a - the String array to serialize
      Throws:
      IOException - in case of an IO-error
    • write

      public void write(Serializable[] objs) throws IOException
      Add the Object array to the serializer, if it implements the marauroa.common.net.Serializable interface
      Parameters:
      objs - the object array to serialize
      Throws:
      IOException - in case of an IO-error
    • getProtocolVersion

      public int getProtocolVersion()
      gets the protocolVersion
      Returns:
      protocol version
    • setProtocolVersion

      public void setProtocolVersion(int protocolVersion)
      sets the protocol version
      Parameters:
      protocolVersion - protocol version
    • escapeJsonString

      public static String escapeJsonString(String value)
      escapes a JSON string
      Parameters:
      value - json string to escape
      Returns:
      escaped json string
    • writeJson

      public static void writeJson(StringBuilder out, String value)
      writes a json key-value-pair
      Parameters:
      out - buffer to write to
      value - value
    • writeJson

      public static void writeJson(StringBuilder out, String key, String value)
      writes a json key-value-pair
      Parameters:
      out - buffer to write to
      key - key
      value - value
    • writeObjectCollectionToJson

      public static void writeObjectCollectionToJson(StringBuilder out, String name, Collection<? extends Attributes> collection, DetailLevel level)
      converts a list of objects into a json fragment
      Parameters:
      out - output buffer
      name - trusted name of list (will not be escaped).
      collection - list of rpobjects
      level - serialization level