com.rt.storage.api.client.http.ConsumingInputStream Maven / Gradle / Ivy
package com.rt.storage.api.client.http;
import com.google.common.io.ByteStreams;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* This class in meant to wrap an {@link InputStream} so that all bytes in the steam are read and
* discarded on {@link InputStream#close()}. This ensures that the underlying connection has the
* option to be reused.
*/
final class ConsumingInputStream extends FilterInputStream {
private boolean closed = false;
ConsumingInputStream(InputStream inputStream) {
super(inputStream);
}
@Override
public void close() throws IOException {
if (!closed && in != null) {
try {
ByteStreams.exhaust(this);
super.in.close();
} finally {
this.closed = true;
}
}
}
}