Hi Denis,

Indeed, -1 is used as a marker for the end of an input stream by Restlets
and actually by the JDK, see:
http://java.sun.com/j2se/1.5.0/docs/api/java/io/InputStream.html#read()

The other important point is that bytes are handled by streams as ints
within the 0 to 255 range. 

I'm not too familiar with POI, but from what I've seen in the Javadocs, you
do something like this:
 - prepare your POI's POIFSDocument or DocumentEntry instance
 - create a new org.apache.poi.poifs.filesystem.DocumentInputStream
 - create a new org.restlet.resource.InputRepresentation, passing the
DocumentInputStream created before
 - set the InputRepresentation instance as the entity of your Restlet
response.
 - the rest (actual writing of the document will transparently by handled by
the InputRepresentation class)

Let me know if it doesn't work!

Best regards,
Jerome  

> -----Message d'origine-----
> De : Denis Haskin [mailto:[EMAIL PROTECTED] 
> Envoyé : jeudi 1 mars 2007 05:39
> À : [email protected]
> Objet : OutputRepresentation, binary, and -1
> 
> 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
> 
> 
> 

Reply via email to