public final void writeTo(ByteBuffer buf){
  if (getLength() > 0) {
    if (this.part instanceof byte[]) {
      buf.put((byte[])this.part);
    }
 else     if (this.part instanceof StoredObject) {
      StoredObject c=(StoredObject)this.part;
      ByteBuffer bb=c.createDirectByteBuffer();
      if (bb != null) {
        buf.put(bb);
      }
 else {
        int bytesToSend=c.getDataSize();
        long addr=c.getAddressForReadingData(0,bytesToSend);
        while (bytesToSend > 0) {
          buf.put(AddressableMemoryManager.readByte(addr));
          addr++;
          bytesToSend--;
        }
      }
    }
 else {
      HeapDataOutputStream hdos=(HeapDataOutputStream)this.part;
      hdos.sendTo(buf);
      hdos.rewind();
    }
  }
}

public final void writeTo ( ByteBuffer buf ) { if ( getLength ( ) > 0 ) { if ( this . part instanceof byte [ ] ) { buf . put ( ( byte [ ] ) this . part ) ; } else if ( this . part instanceof StoredObject ) { StoredObject c = ( StoredObject ) this . part ; ByteBuffer bb = c . createDirectByteBuffer ( ) ; if ( bb != null ) { buf . put ( bb ) ; } else { int bytesToSend = c . getDataSize ( ) ; long addr = c . getAddressForReadingData ( 0 , bytesToSend ) ; while ( bytesToSend > 0 ) { buf . put ( AddressableMemoryManager . readByte ( addr ) ) ; addr ++ ; bytesToSend -- ; } } } else { HeapDataOutputStream hdos = ( HeapDataOutputStream ) this . part ; hdos . sendTo ( buf ) ; hdos . rewind ( ) ; } } }
write the contents of this part to the specified byte buffer . precondition : caller has already checked the length of this part and it will fit into " buf " .
