I had a similar problem with returning new InputRepresentation(inputStream, size) when inputStream came directly from a JClouds Blob with more than a few thousand bytes. Reading the blob content into a buffer first and constructing a ByteArrayInputStream on that buffer fixed the problem.
It appears that the new internal NIO-based connector is still a bit shaky. I suspect this is something that, due to the nature of NIO vs. BIO, will never be completely transparent, so the best we can do is document the best practices and warn about fragile constructs. Or have I missed an existing documentation page that says all this already? That said, I'm delighted to have found these workarounds! In short: With the internal NIO connector, prefer (InputRepresentation of) InputStreams based on in-memory buffers to OutputRepresentations. --tim On Sun, Jan 2, 2011 at 12:03 AM, Tim Peierls <[email protected]> wrote: > I had a resource supporting GET with application/pdf implemented using > OutputRepresentation that was working in 2.0.mumble with the internal > connector. Using 2.1-M2, though, the internal connector only sends the first > 250 bytes or so of about 4500 bytes total. > > The code looked like this: > > final ByteArrayOutputStream bytes = ...; > // generate PDF into bytes > bytes.flush(); // didn't make any difference whether I flushed it or > not > return new OutputRepresentation(MediaType.APPLICATION_PDF, > bytes.size()) { > public void write(OutputStream os) { > bytes.writeTo(os); > } > }); > > When I switched to returning InputStream, as in the POST discussion below, > it works fine. > > I'll continue to use InputStream, but why would OutputRepresentation's > behavior suddenly change? > > --tim > > > On Fri, Jul 2, 2010 at 11:50 AM, Jerome Louvel > <[email protected]>wrote: > >> Your annotated method could look like: >> >> @Post("xml:pdf") >> public InputStream submit(Document) >> >> If you can't return an InputStream, then you need to return >> an OutputRepresentation, overriding its write(OutputStream) method. >> >> @Post("xml:pdf") >> public OutputRepresentation submit(Document) >> >> Best regards, >> Jerome Louvel >> >> -----Message d'origine----- >> De : HT [mailto:[email protected]] >> >> Is there somewhere an example of how to send back a byte stream to >> the outputstream ? >> > ------------------------------------------------------ http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2695473

