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();
}
}
}