public byte[] toByteArray(){
  return Arrays.copyOf(buf,cnt);
}

public byte [ ] toByteArray ( ) { return Arrays . copyOf ( buf , cnt ) ; }
creates a newly allocated byte array . its size is the current size of this output stream and the valid contents of the buffer have been copied into it .
