@Override public void write(byte[] buffer,int offset,int length) throws IOException {
  int toSend=length;
  int sent;
  long start=System.currentTimeMillis();
  while (toSend > 0) {
synchronized (pseudoTcp) {
      sent=pseudoTcp.send(buffer,offset + length - toSend,toSend);
    }
    if (sent > 0) {
      toSend-=sent;
    }
 else {
      try {
        logger.log(Level.FINER,"Write wait for notify");
synchronized (write_notify) {
          if (writeTimeout > 0) {
            long elapsed=System.currentTimeMillis() - start;
            long left=writeTimeout - elapsed;
            if (left <= 0) {
              IOException exc=new IOException("Write operation timeout");
              pseudoTcp.closedown(exc);
              throw exc;
            }
            write_notify.wait(left);
          }
 else {
            write_notify.wait();
          }
        }
        logger.log(Level.FINER,"Write notified, available: " + pseudoTcp.getAvailableSendBuffer());
        if (exception != null) {
          throw exception;
        }
      }
 catch (      InterruptedException ex) {
        if (exception != null) {
          throw new IOException("Write aborted",exception);
        }
 else {
          throw new IOException("Write aborted",ex);
        }
      }
    }
  }
}

@ Override public void write ( byte [ ] buffer , int offset , int length ) throws IOException { int toSend = length ; int sent ; long start = System . currentTimeMillis ( ) ; while ( toSend > 0 ) { synchronized ( pseudoTcp ) { sent = pseudoTcp . send ( buffer , offset + length - toSend , toSend ) ; } if ( sent > 0 ) { toSend -= sent ; } else { try { logger . log ( Level . FINER , "Write wait for notify" ) ; synchronized ( write_notify ) { if ( writeTimeout > 0 ) { long elapsed = System . currentTimeMillis ( ) - start ; long left = writeTimeout - elapsed ; if ( left <= 0 ) { IOException exc = new IOException ( "Write operation timeout" ) ; pseudoTcp . closedown ( exc ) ; throw exc ; } write_notify . wait ( left ) ; } else { write_notify . wait ( ) ; } } logger . log ( Level . FINER , "Write notified, available: " + pseudoTcp . getAvailableSendBuffer ( ) ) ; if ( exception != null ) { throw exception ; } } catch ( InterruptedException ex ) { if ( exception != null ) { throw new IOException ( "Write aborted" , exception ) ; } else { throw new IOException ( "Write aborted" , ex ) ; } } } } }
this method blocks until all data has been written .
