This creates a copy of the data, which means we are copying the data twice.  Since this code is part of the inner loop of IndexPack I would like to avoid that copying by properly allocating the output buffer and writing into it directly.

That might mean a variant of ByteArrayOutputStream has to be written and put into jgit.util.io.