}
public void write(Command command, SocketAddress address) throws IOException {
synchronized (writeLock) {
ByteArrayOutputStream writeBuffer = createByteArrayOutputStream();
DataOutputStream dataOut = new DataOutputStream(writeBuffer);
headerMarshaller.writeHeader(command, dataOut);
int offset = writeBuffer.size();
wireFormat.marshal(command, dataOut);
if (remaining(writeBuffer) >= 0) {
sendWriteBuffer(address, writeBuffer, command.getCommandId());
}
else {
// lets split the command up into chunks
byte[] data = writeBuffer.toByteArray();
boolean lastFragment = false;
for (int fragment = 0, length = data.length; !lastFragment; fragment++) {
writeBuffer = createByteArrayOutputStream();
headerMarshaller.writeHeader(command, dataOut);