Package network

Source Code of network.ConnectionWriter

package network;

import java.io.DataOutputStream;
import java.io.IOException;
import java.util.concurrent.locks.ReentrantLock;

import exceptions.MCConnectionException;

/**
* Before sending multiple messages please use the lock()
* and unlock() methods.
*/
public class ConnectionWriter {

  /**
   *
   */
  private DataOutputStream os;

  public ConnectionWriter(DataOutputStream outputStream) {
    this.os = outputStream;
 
 
  /**
   * Send a sequence of bytes to the client.
   *
   * This method is thread-safe.
   *
   * @param message
   * @throws MCConnectionException
   */
  public synchronized void send(byte[] message) throws MCConnectionException {
    try {
      os.write(message);
    } catch (IOException e) {
      throw new MCConnectionException();
    }
  }


}
TOP

Related Classes of network.ConnectionWriter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.