diff --git a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/ByteBufStreamInput.java b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/ByteBufStreamInput.java index 4f0917fd99a..643478e0916 100644 --- a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/ByteBufStreamInput.java +++ b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/ByteBufStreamInput.java @@ -28,7 +28,7 @@ import java.io.EOFException; import java.io.IOException; /** - * A Netty {@link io.netty.buffer.ByteBuf} based {@link org.elasticsearch.common.io.stream.StreamInput}. + * A Netty {@link ByteBuf} based {@link StreamInput}. */ class ByteBufStreamInput extends StreamInput { @@ -109,6 +109,39 @@ class ByteBufStreamInput extends StreamInput { return len; } + @Override + public short readShort() throws IOException { + try { + return buffer.readShort(); + } catch (IndexOutOfBoundsException ex) { + EOFException eofException = new EOFException(); + eofException.initCause(ex); + throw eofException; + } + } + + @Override + public int readInt() throws IOException { + try { + return buffer.readInt(); + } catch (IndexOutOfBoundsException ex) { + EOFException eofException = new EOFException(); + eofException.initCause(ex); + throw eofException; + } + } + + @Override + public long readLong() throws IOException { + try { + return buffer.readLong(); + } catch (IndexOutOfBoundsException ex) { + EOFException eofException = new EOFException(); + eofException.initCause(ex); + throw eofException; + } + } + @Override public void reset() throws IOException { buffer.resetReaderIndex(); diff --git a/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/ByteBufUtils.java b/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/ByteBufUtils.java index 5c857869d09..f805773c46c 100644 --- a/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/ByteBufUtils.java +++ b/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/ByteBufUtils.java @@ -226,6 +226,39 @@ class ByteBufUtils { return len; } + @Override + public short readShort() throws IOException { + try { + return buffer.readShort(); + } catch (IndexOutOfBoundsException ex) { + EOFException eofException = new EOFException(); + eofException.initCause(ex); + throw eofException; + } + } + + @Override + public int readInt() throws IOException { + try { + return buffer.readInt(); + } catch (IndexOutOfBoundsException ex) { + EOFException eofException = new EOFException(); + eofException.initCause(ex); + throw eofException; + } + } + + @Override + public long readLong() throws IOException { + try { + return buffer.readLong(); + } catch (IndexOutOfBoundsException ex) { + EOFException eofException = new EOFException(); + eofException.initCause(ex); + throw eofException; + } + } + @Override public void reset() throws IOException { buffer.resetReaderIndex(); diff --git a/server/src/main/java/org/elasticsearch/common/io/stream/ByteBufferStreamInput.java b/server/src/main/java/org/elasticsearch/common/io/stream/ByteBufferStreamInput.java index d0f39545856..0668fcb85fe 100644 --- a/server/src/main/java/org/elasticsearch/common/io/stream/ByteBufferStreamInput.java +++ b/server/src/main/java/org/elasticsearch/common/io/stream/ByteBufferStreamInput.java @@ -20,6 +20,7 @@ package org.elasticsearch.common.io.stream; import java.io.EOFException; import java.io.IOException; +import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; public class ByteBufferStreamInput extends StreamInput { @@ -76,6 +77,39 @@ public class ByteBufferStreamInput extends StreamInput { buffer.get(b, offset, len); } + @Override + public short readShort() throws IOException { + try { + return buffer.getShort(); + } catch (BufferUnderflowException ex) { + EOFException eofException = new EOFException(); + eofException.initCause(ex); + throw eofException; + } + } + + @Override + public int readInt() throws IOException { + try { + return buffer.getInt(); + } catch (BufferUnderflowException ex) { + EOFException eofException = new EOFException(); + eofException.initCause(ex); + throw eofException; + } + } + + @Override + public long readLong() throws IOException { + try { + return buffer.getLong(); + } catch (BufferUnderflowException ex) { + EOFException eofException = new EOFException(); + eofException.initCause(ex); + throw eofException; + } + } + @Override public void reset() throws IOException { buffer.reset(); diff --git a/server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java index f361225b48f..7a763c5a049 100644 --- a/server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java +++ b/server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java @@ -415,7 +415,6 @@ public abstract class StreamInput extends InputStream { return spare.toString(); } - public final float readFloat() throws IOException { return Float.intBitsToFloat(readInt()); }