closed unclosed resources in copyCompressed method in Copier
@@ -79,14 +79,15 @@ public class Copier<T> {
}
public byte[] copyCompressed(T obj) {
+ FastByteArrayOutputStream fbos = null;
+ ObjectOutputStream out = null;
try {
- FastByteArrayOutputStream fbos = new FastByteArrayOutputStream();
- ObjectOutputStream out= new ObjectOutputStream(new GZIPOutputStream(fbos));
+ fbos = new FastByteArrayOutputStream();
+ out = new ObjectOutputStream(new GZIPOutputStream(fbos));
// Write the object out to a byte array
out.writeObject(obj);
out.flush();
- out.close();
byte[] copy = new byte[fbos.getSize()];
System.arraycopy(fbos.getByteArray(), 0, copy, 0, fbos.getSize());
@@ -94,6 +95,9 @@ public class Copier<T> {
}
catch(IOException e) {
e.printStackTrace();
+ } finally {
+ StreamUtils.closeQuietly(fbos);
+ StreamUtils.closeQuietly(out);
}
return null;
}
