public byte[] toByteArray(){
  byte[] toBuf=new byte[count];
  System.arraycopy(buf,0,toBuf,0,count);
  return toBuf;
}

public byte [ ] toByteArray ( ) { byte [ ] toBuf = new byte [ count ] ; System . arraycopy ( buf , 0 , toBuf , 0 , count ) ; return toBuf ; }
returns the written bytes in a newly allocated byte [ ] of length getsize ( ) .
