diff --git a/server/src/main/java/org/elasticsearch/common/io/stream/FilterStreamInput.java b/server/src/main/java/org/elasticsearch/common/io/stream/FilterStreamInput.java index 1a3f9fe601da4..2fa700634b851 100644 --- a/server/src/main/java/org/elasticsearch/common/io/stream/FilterStreamInput.java +++ b/server/src/main/java/org/elasticsearch/common/io/stream/FilterStreamInput.java @@ -45,6 +45,21 @@ public void readBytes(byte[] b, int offset, int len) throws IOException { delegate.readBytes(b, offset, len); } + @Override + public short readShort() throws IOException { + return delegate.readShort(); + } + + @Override + public int readInt() throws IOException { + return delegate.readInt(); + } + + @Override + public long readLong() throws IOException { + return delegate.readLong(); + } + @Override public void reset() throws IOException { delegate.reset(); diff --git a/server/src/main/java/org/elasticsearch/index/translog/BufferedChecksumStreamInput.java b/server/src/main/java/org/elasticsearch/index/translog/BufferedChecksumStreamInput.java index 8e815d3599a6b..fa37991d82c04 100644 --- a/server/src/main/java/org/elasticsearch/index/translog/BufferedChecksumStreamInput.java +++ b/server/src/main/java/org/elasticsearch/index/translog/BufferedChecksumStreamInput.java @@ -70,6 +70,30 @@ public void readBytes(byte[] b, int offset, int len) throws IOException { digest.update(b, offset, len); } + private static final ThreadLocal buffer = ThreadLocal.withInitial(() -> new byte[8]); + + @Override + public short readShort() throws IOException { + final byte[] buf = buffer.get(); + readBytes(buf, 0, 2); + return (short) (((buf[0] & 0xFF) << 8) | (buf[1] & 0xFF)); + } + + @Override + public int readInt() throws IOException { + final byte[] buf = buffer.get(); + readBytes(buf, 0, 4); + return ((buf[0] & 0xFF) << 24) | ((buf[1] & 0xFF) << 16) | ((buf[2] & 0xFF) << 8) | (buf[3] & 0xFF); + } + + @Override + public long readLong() throws IOException { + final byte[] buf = buffer.get(); + readBytes(buf, 0, 8); + return (((long) (((buf[0] & 0xFF) << 24) | ((buf[1] & 0xFF) << 16) | ((buf[2] & 0xFF) << 8) | (buf[3] & 0xFF))) << 32) + | ((((buf[4] & 0xFF) << 24) | ((buf[5] & 0xFF) << 16) | ((buf[6] & 0xFF) << 8) | (buf[7] & 0xFF)) & 0xFFFFFFFFL); + } + @Override public void reset() throws IOException { delegate.reset();