Re: svn commit: r1568683 - in /commons/proper/fileupload/trunk/src: changes/changes.xml main/java/org/apache/commons/fileupload/disk/DiskFileItem.java

2014-02-15 Thread sebb
On 15 February 2014 21:36, Bernd Eckenfels  wrote:
> Am Sat, 15 Feb 2014 21:30:48 -
> schrieb s...@apache.org:
>
>> Author: sebb
>> Date: Sat Feb 15 21:30:47 2014
>> New Revision: 1568683
>>
>> URL: http://svn.apache.org/r1568683
>> Log:
>> FILEUPLOAD-246 FileUpload should use IOUtils.closeQuietly where
>> relevant
>>
>> Modified:
>> commons/proper/fileupload/trunk/src/changes/changes.xml
>> 
>> commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
>>
>> Modified: commons/proper/fileupload/trunk/src/changes/changes.xml
>> URL:
>> http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/changes/changes.xml?rev=1568683&r1=1568682&r2=1568683&view=diff
>> ==
>> --- commons/proper/fileupload/trunk/src/changes/changes.xml
>> (original) +++
>> commons/proper/fileupload/trunk/src/changes/changes.xml Sat Feb 15
>> 21:30:47 2014 @@ -45,6 +45,7 @@ The  type attribute can be
>> add,u  
>> +  > type="update">FileUpload should use IOUtils.closeQuietly where
>> relevant > type="fix">DiskFileItem.get() may not fully read the data
>> Make some MultipartStream private fields final
>> 
>>
>> Modified:
>> commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
>> URL:
>> http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java?rev=1568683&r1=1568682&r2=1568683&view=diff
>> ==
>> ---
>> commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
>> (original) +++
>> commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
>> Sat Feb 15 21:30:47 2014 @@ -316,13 +316,7 @@ public class
>> DiskFileItem } catch (IOException e) { fileData = null; } finally {
>> -if (fis != null) {
>> -try {
>> -fis.close();
>> -} catch (IOException e) {
>> -// ignore
>> -}
>> -}
>> +IOUtils.closeQuietly(fis);
>>  }
>>
>>  return fileData;
>> @@ -418,20 +412,8 @@ public class DiskFileItem
>>  new FileOutputStream(file));
>>  IOUtils.copy(in, out);
>>  } finally {
>> -if (in != null) {
>> -try {
>> -in.close();
>> -} catch (IOException e) {
>> -// ignore
>> -}
>> -}
>> -if (out != null) {
>> -try {
>> -out.close();
>> -} catch (IOException e) {
>> -// ignore
>> -}
>> -}
>> +IOUtils.closeQuietly(in);
>> +IOUtils.closeQuietly(out);
>
> Is it really safe to close output stream quitly in this situations?
> There are file systems which return write problems only on the close().
> It is most always never a good idea to close an output stream and
> ignore errors.

That is a separate issue.
I merely replaced the code with a shorthand; the behaviour is unchanged.

> Bernd
>
> -
> To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
> For additional commands, e-mail: dev-h...@commons.apache.org
>

-
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org



Re: svn commit: r1568683 - in /commons/proper/fileupload/trunk/src: changes/changes.xml main/java/org/apache/commons/fileupload/disk/DiskFileItem.java

2014-02-15 Thread Bernd Eckenfels
Hello,

I also think you can replace the whole code block at 

http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java?annotate=1568683&diff_format=l&pathrev=1568683#l405

with IOUtils.moveFile:

http://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html#moveFile%28java.io.File,%20java.io.File%29

Gruss
Bernd

Am Sat, 15 Feb 2014 21:30:48 -
schrieb s...@apache.org:

> Author: sebb
> Date: Sat Feb 15 21:30:47 2014
> New Revision: 1568683
> 
> URL: http://svn.apache.org/r1568683
> Log:
> FILEUPLOAD-246 FileUpload should use IOUtils.closeQuietly where
> relevant
> 
> Modified:
> commons/proper/fileupload/trunk/src/changes/changes.xml
> 
> commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
> 
> Modified: commons/proper/fileupload/trunk/src/changes/changes.xml
> URL:
> http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/changes/changes.xml?rev=1568683&r1=1568682&r2=1568683&view=diff
> ==
> --- commons/proper/fileupload/trunk/src/changes/changes.xml
> (original) +++
> commons/proper/fileupload/trunk/src/changes/changes.xml Sat Feb 15
> 21:30:47 2014 @@ -45,6 +45,7 @@ The  type attribute can be
> add,u  
> +   type="update">FileUpload should use IOUtils.closeQuietly where
> relevant  type="fix">DiskFileItem.get() may not fully read the data
> Make some MultipartStream private fields final
> 
> 
> Modified:
> commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java?rev=1568683&r1=1568682&r2=1568683&view=diff
> ==
> ---
> commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
> (original) +++
> commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
> Sat Feb 15 21:30:47 2014 @@ -316,13 +316,7 @@ public class
> DiskFileItem } catch (IOException e) { fileData = null; } finally {
> -if (fis != null) {
> -try {
> -fis.close();
> -} catch (IOException e) {
> -// ignore
> -}
> -}
> +IOUtils.closeQuietly(fis);
>  }
>  
>  return fileData;
> @@ -418,20 +412,8 @@ public class DiskFileItem
>  new FileOutputStream(file));
>  IOUtils.copy(in, out);
>  } finally {
> -if (in != null) {
> -try {
> -in.close();
> -} catch (IOException e) {
> -// ignore
> -}
> -}
> -if (out != null) {
> -try {
> -out.close();
> -} catch (IOException e) {
> -// ignore
> -}
> -}
> +IOUtils.closeQuietly(in);
> +IOUtils.closeQuietly(out);
>  }
>  }
>  } else {
> 
> 


-
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org



Re: svn commit: r1568683 - in /commons/proper/fileupload/trunk/src: changes/changes.xml main/java/org/apache/commons/fileupload/disk/DiskFileItem.java

2014-02-15 Thread Bernd Eckenfels
Am Sat, 15 Feb 2014 21:30:48 -
schrieb s...@apache.org:

> Author: sebb
> Date: Sat Feb 15 21:30:47 2014
> New Revision: 1568683
> 
> URL: http://svn.apache.org/r1568683
> Log:
> FILEUPLOAD-246 FileUpload should use IOUtils.closeQuietly where
> relevant
> 
> Modified:
> commons/proper/fileupload/trunk/src/changes/changes.xml
> 
> commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
> 
> Modified: commons/proper/fileupload/trunk/src/changes/changes.xml
> URL:
> http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/changes/changes.xml?rev=1568683&r1=1568682&r2=1568683&view=diff
> ==
> --- commons/proper/fileupload/trunk/src/changes/changes.xml
> (original) +++
> commons/proper/fileupload/trunk/src/changes/changes.xml Sat Feb 15
> 21:30:47 2014 @@ -45,6 +45,7 @@ The  type attribute can be
> add,u  
> +   type="update">FileUpload should use IOUtils.closeQuietly where
> relevant  type="fix">DiskFileItem.get() may not fully read the data
> Make some MultipartStream private fields final
> 
> 
> Modified:
> commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java?rev=1568683&r1=1568682&r2=1568683&view=diff
> ==
> ---
> commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
> (original) +++
> commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
> Sat Feb 15 21:30:47 2014 @@ -316,13 +316,7 @@ public class
> DiskFileItem } catch (IOException e) { fileData = null; } finally {
> -if (fis != null) {
> -try {
> -fis.close();
> -} catch (IOException e) {
> -// ignore
> -}
> -}
> +IOUtils.closeQuietly(fis);
>  }
>  
>  return fileData;
> @@ -418,20 +412,8 @@ public class DiskFileItem
>  new FileOutputStream(file));
>  IOUtils.copy(in, out);
>  } finally {
> -if (in != null) {
> -try {
> -in.close();
> -} catch (IOException e) {
> -// ignore
> -}
> -}
> -if (out != null) {
> -try {
> -out.close();
> -} catch (IOException e) {
> -// ignore
> -}
> -}
> +IOUtils.closeQuietly(in);
> +IOUtils.closeQuietly(out);

Is it really safe to close output stream quitly in this situations?
There are file systems which return write problems only on the close().
It is most always never a good idea to close an output stream and
ignore errors.

Bernd

-
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org