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

public synchronized byte [ ] toByteArray ( ) { byte [ ] newArray = new byte [ count ] ; System . arraycopy ( buf , 0 , newArray , 0 , count ) ; return newArray ; }
returns the contents of this bytearrayoutputstream as a byte array . any changes made to the receiver after returning will not be reflected in the byte array returned to the caller .
