* Use bulk methods to read numbers faster from byte buffers
This commit is contained in:
parent
a30bf27b2f
commit
13d76239a0
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -415,7 +415,6 @@ public abstract class StreamInput extends InputStream {
|
|||
return spare.toString();
|
||||
}
|
||||
|
||||
|
||||
public final float readFloat() throws IOException {
|
||||
return Float.intBitsToFloat(readInt());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue