DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUGĀ·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=40835>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED ANDĀ·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=40835


[EMAIL PROTECTED] changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |




------- Additional Comments From [EMAIL PROTECTED]  2007-02-08 14:38 -------
I realize now that my proposed fix for this is inadequate.  The problem will
still arise if an exception occurs at any time after the FileInputStream 'fis'
is opened but before it is closed.  In that case, the method will exit without
having called fis.close().

Below is a solution that will ensure the stream closes even in the event of an
exception:

    public boolean putMethod(String path, File file)
        throws HttpException, IOException {


        FileInputStream fis = null;  // <- * declared outside of try block *
        try {        // <----------------- * try block added *


            setClient();
            PutMethod method = new PutMethod(URIUtil.encodePathQuery(path));
            generateIfHeader(method);
            if (getGetContentType() != null && !getGetContentType().equals(""))
                method.setRequestHeader("Content-Type", getGetContentType());
            long fileLength = file.length();
            method.setRequestContentLength(fileLength <= Integer.MAX_VALUE
                                           ? (int) fileLength
                                           : PutMethod.CONTENT_LENGTH_CHUNKED);
            fis = new FileInputStream(file);
            method.setRequestBody(fis);
            generateTransactionHeader(method);
            int statusCode = client.executeMethod(method);

            setStatusCode(statusCode);
            return (statusCode >= 200 && statusCode < 300) ? true : false;
            

        } finally {
            if(fis != null)      // <---- * stream closed in finally block *
                fis.close();
        }


    } 

By closing the stream in the finally block we gaurantee the stream will close.

Note: This is also an issue for putMethod(String, File) of the same class.  I
will submit a bug report and fix for this shortly.



Cheers!


Mike N. Christoff
[EMAIL PROTECTED]

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to