From 9f0ecf26adb6ec236cc03c4eba716e744b339e8c Mon Sep 17 00:00:00 2001 From: Sergey Simonchik Date: Thu, 11 Aug 2016 20:34:28 +0300 Subject: [PATCH] clear code by converting AtomicLong to long as GZIPInputStream is designed for single threaded access only (following IDEA-CR-12695) --- .../util/io/CountingGZIPInputStream.java | 19 ++++++++++++------- .../com/intellij/util/io/HttpRequests.java | 1 - 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/platform/platform-api/src/com/intellij/util/io/CountingGZIPInputStream.java b/platform/platform-api/src/com/intellij/util/io/CountingGZIPInputStream.java index a5affad9f14a..287d0a5b3354 100644 --- a/platform/platform-api/src/com/intellij/util/io/CountingGZIPInputStream.java +++ b/platform/platform-api/src/com/intellij/util/io/CountingGZIPInputStream.java @@ -19,9 +19,14 @@ import org.jetbrains.annotations.NotNull; import java.io.IOException; import java.io.InputStream; -import java.util.concurrent.atomic.AtomicLong; import java.util.zip.GZIPInputStream; +/** + * A stream for reading compressed data in the GZIP file format. + * Total amount of compressed read bytes can be accessed via {@link #getCompressedBytesRead()}. + * + * Note that this implementation is not thread safe. + */ public class CountingGZIPInputStream extends GZIPInputStream { private final CountingInputStream myInputStream; @@ -31,7 +36,7 @@ public class CountingGZIPInputStream extends GZIPInputStream { } public long getCompressedBytesRead() { - return myInputStream.myBytesRead.get(); + return myInputStream.myBytesRead; } @NotNull @@ -41,7 +46,7 @@ public class CountingGZIPInputStream extends GZIPInputStream { private static class CountingInputStream extends InputStream { private final InputStream myInputStream; - private final AtomicLong myBytesRead = new AtomicLong(0); + private long myBytesRead = 0; public CountingInputStream(@NotNull InputStream inputStream) { myInputStream = inputStream; @@ -49,27 +54,27 @@ public class CountingGZIPInputStream extends GZIPInputStream { public int read() throws IOException { int data = myInputStream.read(); - myBytesRead.incrementAndGet(); + myBytesRead++; return data; } @Override public int read(@NotNull byte[] b) throws IOException { int bytesRead = myInputStream.read(b); - myBytesRead.addAndGet(bytesRead); + myBytesRead += bytesRead; return bytesRead; } @Override public int read(@NotNull byte[] b, int off, int len) throws IOException { int bytesRead = myInputStream.read(b, off, len); - myBytesRead.addAndGet(bytesRead); + myBytesRead += bytesRead; return bytesRead; } public long skip(long n) throws IOException { long bytesSkipped = myInputStream.skip(n); - myBytesRead.addAndGet(bytesSkipped); + myBytesRead += bytesSkipped; return bytesSkipped; } diff --git a/platform/platform-api/src/com/intellij/util/io/HttpRequests.java b/platform/platform-api/src/com/intellij/util/io/HttpRequests.java index 819101865ae5..98952a16bb33 100644 --- a/platform/platform-api/src/com/intellij/util/io/HttpRequests.java +++ b/platform/platform-api/src/com/intellij/util/io/HttpRequests.java @@ -278,7 +278,6 @@ public final class HttpRequests { if (myInputStream == null) { myInputStream = getConnection().getInputStream(); if (myBuilder.myGzip && "gzip".equalsIgnoreCase(getConnection().getContentEncoding())) { - //noinspection IOResourceOpenedButNotSafelyClosed myInputStream = CountingGZIPInputStream.create(myInputStream); } }