You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by rb...@apache.org on 2013/07/04 00:53:55 UTC
[3/5] git commit: IoBuffer.read(byte[],int,int) fix
IoBuffer.read(byte[],int,int) fix
Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/e5641807
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/e5641807
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/e5641807
Branch: refs/heads/trunk
Commit: e56418078455274a7ca3f3575c01feb3c643887f
Parents: 47c4113
Author: Raphaël P. Barazzutti <rb...@apache.org>
Authored: Wed Jul 3 23:58:59 2013 +0200
Committer: Raphaël P. Barazzutti <rb...@apache.org>
Committed: Thu Jul 4 00:41:04 2013 +0200
----------------------------------------------------------------------
.../main/java/org/apache/mina/codec/IoBuffer.java | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina/blob/e5641807/codec/src/main/java/org/apache/mina/codec/IoBuffer.java
----------------------------------------------------------------------
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 @@ public final class IoBuffer {
@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 @@ public final class IoBuffer {
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 @@ public final class IoBuffer {
remainsToCopy -= blocksize;
position.incrementPosition(blocksize);
+
+ position.getNode().getBuffer().position(0);
}
- position.getNode().getBuffer().position(0);
return this;
}
@@ -670,13 +674,12 @@ public final class IoBuffer {
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();
}