public final void writeTo(OutputStream out,ByteBuffer buf) throws IOException {
  if (getLength() > 0) {
    if (this.part instanceof byte[]) {
      byte[] bytes=(byte[])this.part;
      out.write(bytes,0,bytes.length);
    }
 else     if (this.part instanceof StoredObject) {
      StoredObject so=(StoredObject)this.part;
      ByteBuffer sobb=so.createDirectByteBuffer();
      if (sobb != null) {
        HeapDataOutputStream.writeByteBufferToStream(out,buf,sobb);
      }
 else {
        int bytesToSend=so.getDataSize();
        long addr=so.getAddressForReadingData(0,bytesToSend);
        while (bytesToSend > 0) {
          if (buf.remaining() == 0) {
            HeapDataOutputStream.flushStream(out,buf);
          }
          buf.put(AddressableMemoryManager.readByte(addr));
          addr++;
          bytesToSend--;
        }
      }
    }
 else {
      HeapDataOutputStream hdos=(HeapDataOutputStream)this.part;
      hdos.sendTo(out,buf);
      hdos.rewind();
    }
  }
}

public final void writeTo ( OutputStream out , ByteBuffer buf ) throws IOException { if ( getLength ( ) > 0 ) { if ( this . part instanceof byte [ ] ) { byte [ ] bytes = ( byte [ ] ) this . part ; out . write ( bytes , 0 , bytes . length ) ; } else if ( this . part instanceof StoredObject ) { StoredObject so = ( StoredObject ) this . part ; ByteBuffer sobb = so . createDirectByteBuffer ( ) ; if ( sobb != null ) { HeapDataOutputStream . writeByteBufferToStream ( out , buf , sobb ) ; } else { int bytesToSend = so . getDataSize ( ) ; long addr = so . getAddressForReadingData ( 0 , bytesToSend ) ; while ( bytesToSend > 0 ) { if ( buf . remaining ( ) == 0 ) { HeapDataOutputStream . flushStream ( out , buf ) ; } buf . put ( AddressableMemoryManager . readByte ( addr ) ) ; addr ++ ; bytesToSend -- ; } } } else { HeapDataOutputStream hdos = ( HeapDataOutputStream ) this . part ; hdos . sendTo ( out , buf ) ; hdos . rewind ( ) ; } } }
write the contents of this part to the specified output stream . this is only called for parts that will not fit into the commbuffer so they need to be written directly to the stream . a stream is used because the client is configured for old io ( instead of nio ) .
