I'm wondering if I'm misunderstanding something about
OutputRepresentation and binary content.
I've got a test where I write the contents of a byte array in my
OutputRepresentation.write() method. It appears that this output is
getting truncated when it hits a -1 in the binary content.
For example, with this test:
OutputRepresentation r = new
OutputRepresentation(MediaType.APPLICATION_EXCEL) {
public void write(OutputStream stream) throws IOException {
byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9};
stream.write(bytes);
}
};
I get 20 bytes when I read the stream later.
If I do this:
OutputRepresentation r = new
OutputRepresentation(MediaType.APPLICATION_EXCEL) {
public void write(OutputStream stream) throws IOException {
byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9,
-1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9};
stream.write(bytes);
}
};
I only get 9 bytes when I read it. Inspecting ByteUtils.getStream
indicates this might be true, that -1 is being used as a flag byte to
indicate the end of the stream.
Is that correct?
As you can see fromm this example, what I'm really trying to do is
deliver Excel content to the browser... in this case it's an in-memory
workbook (generated with Poi) and I'm just sending the bytes down. I'm
actually not sure if I need some encoding or whether just writing the
byte stream is sufficient.
Thoughts?
Thanks,
Denis haskin