Hi Rafael,
You found a bug! The InputStream should be closed (in a finally block)
after all the bytes read from it have been written out. I have just
fixed it, see the latest build.
Note that you can also return an instance File instead (i also fixed
some performance bugs in the File entity provider). The File
implementation currently does:
new BufferedInputStream(FileInputStream(f))
but if the underlying HTTP container supported writing the file directly
we could support that (unfortunately AFAIK servlet does not support that
so we have to write to the servlet OutputStream).
Paul.
Rafael de F. Ferreira wrote:
> Hi.
>
> I'm just getting started with Jersey, so I'll apologize upfront for my
> newbieness :)
>
> Anyway, I'm writing a resource class using streams as an entity type.
> This is the whole of my GET method (for now):
>
> @HttpMethod("GET")
> @ProduceMime("application/xml")
> public InputStream getXml() {
> try {
> return new BufferedInputStream(
> new FileInputStream(
>
> "C:\\temp\\docs\\xmlrepo\\net\\rafaelferreira\\jserverdoc\\sample\\ClasseA.xml"));
>
> } catch (FileNotFoundException ex) {
> throw new NotFoundException(ex.getMessage());
> }
> }
>
> I noticed that glassfish was keeping a handle to the file after
> invocation. Is this behaviour expected? In cases such as this, does the
> user need to explicitly read from an origin stream into memory and then
> return the buffer to the framework?
>
> Poking around with the source code, I think that maybe
> AbstractTypeEntityProvider.writeTo(InputStream in, OutputStream out)
> could take care of closing the input stream, but I don't know if this
> would interact badly with the rest of the code.
>
> Thanks!
> --
> *Rafael de França Ferreira *
> Sun Campus Ambassador at USP - Brazil
> http://blogs.sun.com/rafaelferreira
> http://www.rafaelferreira.net/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
--
| ? + ? = To question
----------------\
Paul Sandoz
x38109
+33-4-76188109