com.twitter.common.io
Interface Codec<T>

Type Parameters:
T - The type of object the Codec can handle.
All Known Implementing Classes:
CompatibilityCodec, JsonCodec, ThriftCodec

public interface Codec<T>

A Codec represents a reversible encoding for a given type. Codecs are able to both read items from streams and write items to streams.

TODO(John Sirois): consider whether this interface should optionally support null items to be read and written.


Method Summary
 T deserialize(InputStream source)
          Reads an item from the source stream that was written by serialize(Object, java.io.OutputStream).
 void serialize(T item, OutputStream sink)
          Writes a representation of item to the sink that can be read back by deserialize(java.io.InputStream).
 

Method Detail

serialize

void serialize(T item,
               OutputStream sink)
               throws IOException
Writes a representation of item to the sink that can be read back by deserialize(java.io.InputStream).

Parameters:
item - the item to serialize
sink - the stream to write the item out to
Throws:
IOException - if there is a problem serializing the item

deserialize

T deserialize(InputStream source)
              throws IOException
Reads an item from the source stream that was written by serialize(Object, java.io.OutputStream).

Parameters:
source - the stream to read an item from
Returns:
the deserialized item
Throws:
IOException - if there is a problem reading an item