Okie, so here on the ptr  you mean.  I foudn that internally if we are able to specify  a correct size for the TrustedByteStream then calling toByteArray does not do a copy internally in ByteArrayOutputStream.  So that is why trying to frame a correct size needed for the varlength array elements.  Okie let me try write the code on how i calculated it and push it here.  Let me know if that way is fine with you.