// execute the pipeline:
this.generator.generate();
byte[] data = os.toByteArray();
environment.setContentLength(data.length);
environment.getOutputStream(0).write(data);But from the javadocs of java.io.ByteArrayOutputStream#toByteArray, I read:
"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."
Thus I wonder: why are we doing this copy instead of doing:
// execute the pipeline:
this.generator.generate();
environment.setContentLength(os.size());
os.writeTo(environment.getOutputStream(0));If I'm not mistaken, this would avoid allocating and copying an array as large as the serializer's output. Or am I missing something subtle here?
Ugo
