From a47ab01edc470112a24d91f0026b4a369c609989 Mon Sep 17 00:00:00 2001 From: cpovirk Date: Thu, 9 Jul 2020 16:31:39 -0700 Subject: [PATCH] Declare static types as Queue instead of Deque. This may slightly clarify how the object is used. (I was looking through com.google.common for Deque instances that were used as stacks, so I noticed this one that was used only as a queue.) RELNOTES=n/a ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=320498758 --- .../guava/src/com/google/common/io/ByteStreams.java | 10 +++++----- guava/src/com/google/common/io/ByteStreams.java | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/android/guava/src/com/google/common/io/ByteStreams.java b/android/guava/src/com/google/common/io/ByteStreams.java index 868d200ca6f9..05d77cd9a68a 100644 --- a/android/guava/src/com/google/common/io/ByteStreams.java +++ b/android/guava/src/com/google/common/io/ByteStreams.java @@ -40,7 +40,7 @@ import java.nio.channels.WritableByteChannel; import java.util.ArrayDeque; import java.util.Arrays; -import java.util.Deque; +import java.util.Queue; /** * Provides utility methods for working with byte arrays and I/O streams. @@ -165,7 +165,7 @@ public static long copy(ReadableByteChannel from, WritableByteChannel to) throws * a total combined length of {@code totalLen} bytes) followed by all bytes remaining in the given * input stream. */ - private static byte[] toByteArrayInternal(InputStream in, Deque bufs, int totalLen) + private static byte[] toByteArrayInternal(InputStream in, Queue bufs, int totalLen) throws IOException { // Starting with an 8k buffer, double the size of each sucessive buffer. Buffers are retained // in a deque so that there's no copying between buffers while reading and so all of the bytes @@ -196,11 +196,11 @@ private static byte[] toByteArrayInternal(InputStream in, Deque bufs, in } } - private static byte[] combineBuffers(Deque bufs, int totalLen) { + private static byte[] combineBuffers(Queue bufs, int totalLen) { byte[] result = new byte[totalLen]; int remaining = totalLen; while (remaining > 0) { - byte[] buf = bufs.removeFirst(); + byte[] buf = bufs.remove(); int bytesToCopy = Math.min(remaining, buf.length); int resultOffset = totalLen - remaining; System.arraycopy(buf, 0, result, resultOffset, bytesToCopy); @@ -253,7 +253,7 @@ static byte[] toByteArray(InputStream in, long expectedSize) throws IOException } // the stream was longer, so read the rest normally - Deque bufs = new ArrayDeque(TO_BYTE_ARRAY_DEQUE_SIZE + 2); + Queue bufs = new ArrayDeque(TO_BYTE_ARRAY_DEQUE_SIZE + 2); bufs.add(bytes); bufs.add(new byte[] {(byte) b}); return toByteArrayInternal(in, bufs, bytes.length + 1); diff --git a/guava/src/com/google/common/io/ByteStreams.java b/guava/src/com/google/common/io/ByteStreams.java index 868d200ca6f9..05d77cd9a68a 100644 --- a/guava/src/com/google/common/io/ByteStreams.java +++ b/guava/src/com/google/common/io/ByteStreams.java @@ -40,7 +40,7 @@ import java.nio.channels.WritableByteChannel; import java.util.ArrayDeque; import java.util.Arrays; -import java.util.Deque; +import java.util.Queue; /** * Provides utility methods for working with byte arrays and I/O streams. @@ -165,7 +165,7 @@ public static long copy(ReadableByteChannel from, WritableByteChannel to) throws * a total combined length of {@code totalLen} bytes) followed by all bytes remaining in the given * input stream. */ - private static byte[] toByteArrayInternal(InputStream in, Deque bufs, int totalLen) + private static byte[] toByteArrayInternal(InputStream in, Queue bufs, int totalLen) throws IOException { // Starting with an 8k buffer, double the size of each sucessive buffer. Buffers are retained // in a deque so that there's no copying between buffers while reading and so all of the bytes @@ -196,11 +196,11 @@ private static byte[] toByteArrayInternal(InputStream in, Deque bufs, in } } - private static byte[] combineBuffers(Deque bufs, int totalLen) { + private static byte[] combineBuffers(Queue bufs, int totalLen) { byte[] result = new byte[totalLen]; int remaining = totalLen; while (remaining > 0) { - byte[] buf = bufs.removeFirst(); + byte[] buf = bufs.remove(); int bytesToCopy = Math.min(remaining, buf.length); int resultOffset = totalLen - remaining; System.arraycopy(buf, 0, result, resultOffset, bytesToCopy); @@ -253,7 +253,7 @@ static byte[] toByteArray(InputStream in, long expectedSize) throws IOException } // the stream was longer, so read the rest normally - Deque bufs = new ArrayDeque(TO_BYTE_ARRAY_DEQUE_SIZE + 2); + Queue bufs = new ArrayDeque(TO_BYTE_ARRAY_DEQUE_SIZE + 2); bufs.add(bytes); bufs.add(new byte[] {(byte) b}); return toByteArrayInternal(in, bufs, bytes.length + 1);