IoBuffer.read(byte[],int,int) fix
diff --git a/codec/src/main/java/org/apache/mina/codec/IoBuffer.java b/codec/src/main/java/org/apache/mina/codec/IoBuffer.java
index 1be49a5..e3ff463 100644
--- a/codec/src/main/java/org/apache/mina/codec/IoBuffer.java
+++ b/codec/src/main/java/org/apache/mina/codec/IoBuffer.java
@@ -181,6 +181,10 @@
@Override
public int read(byte[] b, int off, int len) throws IOException {
+ if (!hasRemaining()) {
+ return -1;
+ }
+
int toRead = Math.min(remaining(), len);
get(b, off, toRead);
return toRead;
@@ -350,13 +354,12 @@
if (remaining() < length) {
throw new BufferUnderflowException();
}
- position.getNode().getBuffer().position(position.getPositionInNode());
int remainsToCopy = length;
int currentOffset = offset;
while (remainsToCopy > 0) {
position.updatePos();
-
+ position.getNode().getBuffer().position(position.getPositionInNode());
ByteBuffer currentBuffer = position.getNode().getBuffer();
int blocksize = Math.min(remainsToCopy, currentBuffer.remaining());
position.getNode().getBuffer().get(dst, currentOffset, blocksize);
@@ -365,8 +368,9 @@
remainsToCopy -= blocksize;
position.incrementPosition(blocksize);
+
+ position.getNode().getBuffer().position(0);
}
- position.getNode().getBuffer().position(0);
return this;
}
@@ -670,13 +674,12 @@
return this;
}
-
-
+
/**
* @see ByteBuffer#put(ByteBuffer)
*/
public IoBuffer put(IoBuffer src) {
- if(src==this){ // NOSONAR, checking the instance
+ if (src == this) { // NOSONAR, checking the instance
throw new IllegalArgumentException();
}