Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package me.prettyprint.cassandra.serializers;
 
 
The ObjectSerializer is used to turn objects into their binary representations.

Author(s):
Bozhidar Bozhanov
public class ObjectSerializer extends AbstractSerializer<Objectimplements Serializer<Object> {
  private static final ObjectSerializer INSTANCE = new ObjectSerializer();
  public ByteBuffer toByteBuffer(Object obj) {
    try {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(baos);
      oos.writeObject(obj);
      oos.close();
      return ByteBuffer.wrap(baos.toByteArray());
    } catch (IOException ex) {
      throw new RuntimeException(ex);
    }
  }
  public Object fromByteBuffer(ByteBuffer bytes) {
    if (bytes == null || !bytes.hasRemaining()) {
      return null;
    }
    try {
      ByteArrayInputStream bais = new ByteArrayInputStream(bytes.array());
      ObjectInputStream ois = new ObjectInputStream(bais);
      Object obj = ois.readObject();
      ois.close();
      return obj;
    } catch (Exception ex) {
      throw new HectorSerializationException(ex);
    }
  }
  public static ObjectSerializer get() {
    return ;
  }
New to GrepCode? Check out our FAQ X