closed unclosed resources in copyCompressed method in Copier

This commit is contained in:
Marc Zwart 2018-03-20 14:20:31 +01:00
parent dc25eedfc3
commit b2e2f48ad9

View file

@ -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;
}