From 6d04c1e78e24481d4144e10137d577839718f13e Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 22 Jun 2016 11:56:04 -0400 Subject: [PATCH] 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 --- .../common/io/stream/StreamInput.java | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java index 30b5cd7f2cf..ceb909fb49a 100644 --- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java +++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java @@ -439,7 +439,7 @@ public abstract class StreamInput extends InputStream { case 5: return readBoolean(); case 6: - return fastReadByteArray(); + return readByteArray(); case 7: return readArrayList(); 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") private List readArrayList() throws IOException { int size = readVInt(); @@ -609,12 +602,10 @@ public abstract class StreamInput extends InputStream { } public byte[] readByteArray() throws IOException { - int length = readVInt(); - byte[] values = new byte[length]; - for (int i = 0; i < length; i++) { - values[i] = readByte(); - } - return values; + final int length = readVInt(); + final byte[] bytes = new byte[length]; + readBytes(bytes, 0, bytes.length); + return bytes; } /**