Skip to content

Commit

Permalink
Declare static types as Queue instead of Deque.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cpovirk authored and kevinb9n committed Jul 10, 2020
1 parent d7a2641 commit a47ab01
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions android/guava/src/com/google/common/io/ByteStreams.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<byte[]> bufs, int totalLen)
private static byte[] toByteArrayInternal(InputStream in, Queue<byte[]> 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
Expand Down Expand Up @@ -196,11 +196,11 @@ private static byte[] toByteArrayInternal(InputStream in, Deque<byte[]> bufs, in
}
}

private static byte[] combineBuffers(Deque<byte[]> bufs, int totalLen) {
private static byte[] combineBuffers(Queue<byte[]> 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);
Expand Down Expand Up @@ -253,7 +253,7 @@ static byte[] toByteArray(InputStream in, long expectedSize) throws IOException
}

// the stream was longer, so read the rest normally
Deque<byte[]> bufs = new ArrayDeque<byte[]>(TO_BYTE_ARRAY_DEQUE_SIZE + 2);
Queue<byte[]> bufs = new ArrayDeque<byte[]>(TO_BYTE_ARRAY_DEQUE_SIZE + 2);
bufs.add(bytes);
bufs.add(new byte[] {(byte) b});
return toByteArrayInternal(in, bufs, bytes.length + 1);
Expand Down
10 changes: 5 additions & 5 deletions guava/src/com/google/common/io/ByteStreams.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<byte[]> bufs, int totalLen)
private static byte[] toByteArrayInternal(InputStream in, Queue<byte[]> 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
Expand Down Expand Up @@ -196,11 +196,11 @@ private static byte[] toByteArrayInternal(InputStream in, Deque<byte[]> bufs, in
}
}

private static byte[] combineBuffers(Deque<byte[]> bufs, int totalLen) {
private static byte[] combineBuffers(Queue<byte[]> 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);
Expand Down Expand Up @@ -253,7 +253,7 @@ static byte[] toByteArray(InputStream in, long expectedSize) throws IOException
}

// the stream was longer, so read the rest normally
Deque<byte[]> bufs = new ArrayDeque<byte[]>(TO_BYTE_ARRAY_DEQUE_SIZE + 2);
Queue<byte[]> bufs = new ArrayDeque<byte[]>(TO_BYTE_ARRAY_DEQUE_SIZE + 2);
bufs.add(bytes);
bufs.add(new byte[] {(byte) b});
return toByteArrayInternal(in, bufs, bytes.length + 1);
Expand Down

0 comments on commit a47ab01

Please sign in to comment.