
package net.kuujo.copycat.io;

import net.kuujo.copycat.io.serializer.Serializer;

import java.io.IOException;
import java.io.ObjectOutput;

/**
 * Buffer object output wrapper.
 *
 * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
 */
public class BufferObjectOutput extends BufferDataOutput implements ObjectOutput {
  private final Serializer serializer;

  public BufferObjectOutput(BufferOutput buffer, Serializer serializer) {
    super(buffer);
    if (serializer == null)
      throw new NullPointerException("serializer cannot be null");
    this.serializer = serializer;
  }

  @Override
  public void writeObject(Object obj) throws IOException {
    serializer.writeObject(obj, buffer);
  }

  @Override
  public void flush() throws IOException {
    buffer.flush();
  }

  @Override
  public void close() throws IOException {
    buffer.close();
  }

}
