@Override
 public synchronized void write(int b) throws IOException {
   checkOpen();
   if (currentOutputCell == null || currentOutputCell.cellBytesRemaining() == 0)
     flushCurrentOutputCell();
   currentOutputCell.putByte(b);
 }
  public synchronized void write(byte[] data, int offset, int length) throws IOException {
    checkOpen();
    if (currentOutputCell == null || currentOutputCell.cellBytesRemaining() == 0)
      flushCurrentOutputCell();

    while (length > 0) {
      if (length < currentOutputCell.cellBytesRemaining()) {
        currentOutputCell.putByteArray(data, offset, length);
        return;
      }
      final int writeCount = currentOutputCell.cellBytesRemaining();
      currentOutputCell.putByteArray(data, offset, writeCount);
      flushCurrentOutputCell();
      offset += writeCount;
      length -= writeCount;
    }
  }