public final void sendTo(DataOutput out) throws IOException {
  finishWriting();
  if (this.chunks != null) {
    for (    ByteBuffer bb : this.chunks) {
      int bytesToWrite=bb.remaining();
      if (bytesToWrite > 0) {
        if (bb.hasArray()) {
          out.write(bb.array(),bb.arrayOffset() + bb.position(),bytesToWrite);
          bb.position(bb.limit());
        }
 else {
          byte[] bytes=new byte[bytesToWrite];
          bb.get(bytes);
          out.write(bytes);
        }
        this.size-=bytesToWrite;
      }
    }
  }
{
    ByteBuffer bb=this.buffer;
    int bytesToWrite=bb.remaining();
    if (bytesToWrite > 0) {
      if (bb.hasArray()) {
        out.write(bb.array(),bb.arrayOffset() + bb.position(),bytesToWrite);
        bb.position(bb.limit());
      }
 else {
        byte[] bytes=new byte[bytesToWrite];
        bb.get(bytes);
        out.write(bytes);
      }
      this.size-=bytesToWrite;
    }
  }
}

public final void sendTo ( DataOutput out ) throws IOException { finishWriting ( ) ; if ( this . chunks != null ) { for ( ByteBuffer bb : this . chunks ) { int bytesToWrite = bb . remaining ( ) ; if ( bytesToWrite > 0 ) { if ( bb . hasArray ( ) ) { out . write ( bb . array ( ) , bb . arrayOffset ( ) + bb . position ( ) , bytesToWrite ) ; bb . position ( bb . limit ( ) ) ; } else { byte [ ] bytes = new byte [ bytesToWrite ] ; bb . get ( bytes ) ; out . write ( bytes ) ; } this . size -= bytesToWrite ; } } } { ByteBuffer bb = this . buffer ; int bytesToWrite = bb . remaining ( ) ; if ( bytesToWrite > 0 ) { if ( bb . hasArray ( ) ) { out . write ( bb . array ( ) , bb . arrayOffset ( ) + bb . position ( ) , bytesToWrite ) ; bb . position ( bb . limit ( ) ) ; } else { byte [ ] bytes = new byte [ bytesToWrite ] ; bb . get ( bytes ) ; out . write ( bytes ) ; } this . size -= bytesToWrite ; } } }
write the contents of this stream to the specified stream . < p > note this implementation is exactly the same as writeto ( outputstream ) but they do not both implement a common interface .
