You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ba...@apache.org on 2008/07/06 07:01:38 UTC
svn commit: r674258 -
/commons/sandbox/compress/trunk/src/java/org/apache/commons/compress/AbstractCompressor.java
Author: bayard
Date: Sat Jul 5 22:01:38 2008
New Revision: 674258
URL: http://svn.apache.org/viewvc?rev=674258&view=rev
Log:
Fixing the finally code which wasn't null-protecting, catching an exception in the code I'd previously 'fixed' and removing the outputStream variable as it was unused
Modified:
commons/sandbox/compress/trunk/src/java/org/apache/commons/compress/AbstractCompressor.java
Modified: commons/sandbox/compress/trunk/src/java/org/apache/commons/compress/AbstractCompressor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/java/org/apache/commons/compress/AbstractCompressor.java?rev=674258&r1=674257&r2=674258&view=diff
==============================================================================
--- commons/sandbox/compress/trunk/src/java/org/apache/commons/compress/AbstractCompressor.java (original)
+++ commons/sandbox/compress/trunk/src/java/org/apache/commons/compress/AbstractCompressor.java Sat Jul 5 22:01:38 2008
@@ -50,7 +50,6 @@
* @see org.apache.commons.compress.Compressor#compressStream(java.io.FileInputStream)
*/
public InputStream compress(InputStream input) throws CompressException {
- FileOutputStream outputStream = null;
FileOutputStream tempFileOutputStream = null;
try {
File temp = File.createTempFile("commons_","jkt");
@@ -58,18 +57,15 @@
compressTo(input, tempFileOutputStream);
return new FileInputStream(temp);
} catch (IOException e) {
- throw new CompressException("An IO Exception has occured", e);
+ throw new CompressException("An I/O Exception has occured", e);
} finally {
- try {
+ try {
if(tempFileOutputStream != null) {
- tempFileOutputStream.close();
- }
- if(outputStream != null) {
- outputStream.close();
+ tempFileOutputStream.close();
}
- } catch (IOException e) {
- throw new CompressException("An IO Exception occured while closing the streams", e);
- }
+ } catch (IOException e) {
+ throw new CompressException("An I/O Exception occured while closing the streams", e);
+ }
}
}
@@ -156,12 +152,21 @@
} catch (FileNotFoundException e) {
throw new CompressException("File could not be found", e);
} finally {
- try {
- inputStream.close();
- outputStream.close();
- } catch (IOException e1) {
- throw new CompressException("An I/O Exception has occured while closing a stream", e1);
- }
+ try {
+ if(inputStream != null) {
+ inputStream.close();
+ }
+ } catch (IOException e) {
+ throw new CompressException("An I/O Exception occured while closing the streams", e);
+ } finally {
+ try {
+ if(outputStream != null) {
+ outputStream.close();
+ }
+ } catch (IOException e) {
+ throw new CompressException("An I/O Exception occured while closing the streams", e);
+ }
+ }
}
}
}