Remove duplicated read byte array methods

This commit removes duplicated methods for reading byte arrays in
StreamInput. One method would read a byte array by repeatedly calling
StreamInput#readByte in a loop, and the other would just call
StreamInput#readBytes. In this commit, we remove the former.

Relates #19023
This commit is contained in:
Jason Tedor 2016-06-22 11:56:04 -04:00 committed by GitHub
parent a379d62187
commit 6d04c1e78e
1 changed files with 5 additions and 14 deletions

View File

@ -439,7 +439,7 @@ public abstract class StreamInput extends InputStream {
case 5: case 5:
return readBoolean(); return readBoolean();
case 6: case 6:
return fastReadByteArray(); return readByteArray();
case 7: case 7:
return readArrayList(); return readArrayList();
case 8: case 8:
@ -477,13 +477,6 @@ public abstract class StreamInput extends InputStream {
} }
} }
private byte[] fastReadByteArray() throws IOException {
int bytesSize = readVInt();
byte[] value = new byte[bytesSize];
readBytes(value, 0, bytesSize);
return value;
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private List readArrayList() throws IOException { private List readArrayList() throws IOException {
int size = readVInt(); int size = readVInt();
@ -609,12 +602,10 @@ public abstract class StreamInput extends InputStream {
} }
public byte[] readByteArray() throws IOException { public byte[] readByteArray() throws IOException {
int length = readVInt(); final int length = readVInt();
byte[] values = new byte[length]; final byte[] bytes = new byte[length];
for (int i = 0; i < length; i++) { readBytes(bytes, 0, bytes.length);
values[i] = readByte(); return bytes;
}
return values;
} }
/** /**