import java.util.concurrent.atomic.AtomicLong;
import java.util.zip.GZIPInputStream;
-public class CompressedBytesReadAwareGZIPInputStream extends GZIPInputStream {
- private final BytesReadAwareInputStream myInputStream;
+public class CountingGZIPInputStream extends GZIPInputStream {
+ private final CountingInputStream myInputStream;
- private CompressedBytesReadAwareGZIPInputStream(@NotNull BytesReadAwareInputStream inputStream) throws IOException {
+ private CountingGZIPInputStream(@NotNull CountingInputStream inputStream) throws IOException {
super(inputStream);
myInputStream = inputStream;
}
}
@NotNull
- public static CompressedBytesReadAwareGZIPInputStream create(@NotNull InputStream inputStream) throws IOException {
- return new CompressedBytesReadAwareGZIPInputStream(new BytesReadAwareInputStream(inputStream));
+ public static CountingGZIPInputStream create(@NotNull InputStream inputStream) throws IOException {
+ return new CountingGZIPInputStream(new CountingInputStream(inputStream));
}
- private static class BytesReadAwareInputStream extends InputStream {
+ private static class CountingInputStream extends InputStream {
private final InputStream myInputStream;
private final AtomicLong myBytesRead = new AtomicLong(0);
- public BytesReadAwareInputStream(@NotNull InputStream inputStream) {
+ public CountingInputStream(@NotNull InputStream inputStream) {
myInputStream = inputStream;
}
public int read() throws IOException {
- long bytesReadBefore = myBytesRead.get();
int data = myInputStream.read();
- myBytesRead.compareAndSet(bytesReadBefore, bytesReadBefore + 1);
+ myBytesRead.incrementAndGet();
return data;
}
@Override
public int read(@NotNull byte[] b) throws IOException {
- long bytesReadBefore = myBytesRead.get();
int bytesRead = myInputStream.read(b);
- myBytesRead.compareAndSet(bytesReadBefore, bytesReadBefore + bytesRead);
+ myBytesRead.addAndGet(bytesRead);
return bytesRead;
}
@Override
public int read(@NotNull byte[] b, int off, int len) throws IOException {
- long bytesReadBefore = myBytesRead.get();
int bytesRead = myInputStream.read(b, off, len);
- myBytesRead.compareAndSet(bytesReadBefore, bytesReadBefore + bytesRead);
+ myBytesRead.addAndGet(bytesRead);
return bytesRead;
}
public long skip(long n) throws IOException {
- long bytesReadBefore = myBytesRead.get();
long bytesSkipped = myInputStream.skip(n);
- myBytesRead.compareAndSet(bytesReadBefore, bytesReadBefore + bytesSkipped);
+ myBytesRead.addAndGet(bytesSkipped);
return bytesSkipped;
}
import com.intellij.openapi.util.SystemInfo;
import com.intellij.util.ObjectUtils;
import com.intellij.util.SystemProperties;
-import com.intellij.util.io.CompressedBytesReadAwareGZIPInputStream;
+import com.intellij.util.io.CountingGZIPInputStream;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
indicator.setIndeterminate(true);
}
}
- CompressedBytesReadAwareGZIPInputStream gzipStream = ObjectUtils.tryCast(inputStream, CompressedBytesReadAwareGZIPInputStream.class);
+ CountingGZIPInputStream gzipStream = ObjectUtils.tryCast(inputStream, CountingGZIPInputStream.class);
final byte[] buffer = new byte[8 * 1024];
int count;
int bytesWritten = 0;