All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.ebeaninternal.api.BinaryWriteContext Maven / Gradle / Ivy

There is a newer version: 15.8.0
Show newest version
package io.ebeaninternal.api;

import java.io.DataOutputStream;
import java.io.IOException;

/**
 * Context used to write binary message (like RemoteTransactionEvent).
 */
public final class BinaryWriteContext {

  private final DataOutputStream out;
  private long counter;

  public BinaryWriteContext(DataOutputStream out) {
    this.out = out;
  }

  /**
   * Return the number of message parts that have been written.
   */
  public long counter() {
    return counter;
  }

  /**
   * Return the output stream to write to.
   */
  public DataOutputStream os() {
    return out;
  }

  /**
   * Start a message part with a given type code.
   */
  public DataOutputStream start(int type) throws IOException {
    counter++;
    out.writeBoolean(true);
    out.writeInt(type);
    return out;
  }

  /**
   * End of message parts.
   */
  public void end() throws IOException {
    out.writeBoolean(false);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy