mirror of
https://github.com/xerial/snappy-java.git
synced 2025-04-08 19:35:08 +02:00
Make close() idempotent (fixes #107).
This commit is contained in:
parent
c5a3b102bc
commit
2b6c8dc896
@ -69,6 +69,7 @@ public class SnappyOutputStream extends OutputStream {
|
||||
protected final byte[] outputBuffer;
|
||||
private int inputCursor = 0;
|
||||
private int outputCursor = 0;
|
||||
private boolean closed;
|
||||
|
||||
public SnappyOutputStream(OutputStream out) {
|
||||
this(out, DEFAULT_BLOCK_SIZE);
|
||||
@ -320,10 +321,14 @@ public class SnappyOutputStream extends OutputStream {
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
if (closed) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
flush();
|
||||
out.close();
|
||||
} finally {
|
||||
closed = true;
|
||||
inputBufferAllocator.release(inputBuffer);
|
||||
outputBufferAllocator.release(outputBuffer);
|
||||
}
|
||||
|
@ -187,8 +187,10 @@ public class SnappyOutputStreamTest
|
||||
os3.close();
|
||||
SnappyInputStream in2 = new SnappyInputStream(new ByteArrayInputStream(ba2.toByteArray()));
|
||||
assertEquals(2, in2.read());
|
||||
in2.close();
|
||||
SnappyInputStream in3 = new SnappyInputStream(new ByteArrayInputStream(ba3.toByteArray()));
|
||||
assertEquals(3, in3.read());
|
||||
in3.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user