cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Parimal Dhinoja <pdhin...@gmail.com>
Subject how to close inputStream before returning response
Date Mon, 30 Nov 2009 17:27:12 GMT
Hi All,

Following is my service method where I am reading file and feed it into
Response object.  Even if I try to close my file streams in finally block, I
didn't receive any file back in response. if I remove stream closing
statements from finally block, I am getting my file in response body when
checked in browser. Can someone please let me know how I can close my
streams or does it will close automatically after Response object is
returned?


@GET
    @Path("/message1")
    public Response getMessage1(@QueryParam("propertyName")
    String propertyName)
    {
        String param = propertyName;
        String filePath = "I://abc.xml";

        FileInputStream fis = null;
        BufferedInputStream bis = null;
        ResponseBuilder rs = null;
        Response response = null;
        try
        {
            fis = new FileInputStream(new File(filePath));
            bis = new BufferedInputStream(fis);
            rs = Response.status(200).entity(bis);
            response = rs.build();
            // bis.close();
            // fis.close();
        }
        catch (Exception e)
        {
            LOGGER.info(e.getMessage());
        }
        finally
        {
            try
            {
                if (bis != null)
                {
                    bis.close();
                    LOGGER.info("===>bis is closed");
                }
                if (fis != null)
                {
                    fis.close();
                }
            }
            catch (Exception e)
            {
                LOGGER.info("Exception occured while closing streams");
            }
        }
        // return Response.status(200).entity(bis).build();
        return response;

    }

-- 
Regards,
Parimal
"Nothing is stationary,Change is a part of Life"

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message