Author: trustin
Date: Fri Dec 7 06:40:41 2007
New Revision: 602109
URL: http://svn.apache.org/viewvc?rev=602109&view=rev
Log:
Resolved issue: DIRMINA-490 (Add a getSlice(int) method to IoBuffer)
* Added IoBuffer.getSlice(...) convenience methods
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoBuffer.java
mina/trunk/core/src/main/java/org/apache/mina/common/IoBuffer.java
mina/trunk/core/src/main/java/org/apache/mina/common/IoBufferWrapper.java
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoBuffer.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoBuffer.java?rev=602109&r1=602108&r2=602109&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoBuffer.java
(original)
+++ mina/trunk/core/src/main/java/org/apache/mina/common/AbstractIoBuffer.java
Fri Dec 7 06:40:41 2007
@@ -685,6 +685,42 @@
recapacityAllowed = false;
return slice0();
}
+
+ @Override
+ public final IoBuffer getSlice(int index, int length) {
+ if (length < 0) {
+ throw new IllegalArgumentException("length: " + length);
+ }
+ int pos = position();
+ int limit = limit();
+ position(index);
+ limit(index + length);
+ IoBuffer slice = slice();
+ position(pos);
+ limit(limit);
+ return slice;
+ }
+
+ @Override
+ public final IoBuffer getSlice(int length) {
+ if (length < 0) {
+ throw new IllegalArgumentException("length: " + length);
+ }
+ int pos = position();
+ int limit = limit();
+ int nextPos = pos + length;
+ if (limit < nextPos) {
+ throw new IndexOutOfBoundsException(
+ "position + length (" + nextPos + ") is greater " +
+ "than limit (" + limit + ").");
+ }
+
+ limit(pos + length);
+ IoBuffer slice = slice();
+ position(nextPos);
+ limit(limit);
+ return slice;
+ }
/**
* Implement this method to return the unexpandable slice of this
Modified: mina/trunk/core/src/main/java/org/apache/mina/common/IoBuffer.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/IoBuffer.java?rev=602109&r1=602108&r2=602109&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/common/IoBuffer.java
(original)
+++ mina/trunk/core/src/main/java/org/apache/mina/common/IoBuffer.java Fri Dec
7 06:40:41 2007
@@ -515,7 +515,7 @@
* @see ByteBuffer#slice()
*/
public abstract IoBuffer slice();
-
+
/**
* @see ByteBuffer#asReadOnlyBuffer()
*/
@@ -575,6 +575,16 @@
* @see ByteBuffer#get(byte[])
*/
public abstract IoBuffer get(byte[] dst);
+
+ /**
+ * TODO document me.
+ */
+ public abstract IoBuffer getSlice(int index, int length);
+
+ /**
+ * TODO document me.
+ */
+ public abstract IoBuffer getSlice(int length);
/**
* Writes the content of the specified <tt>src</tt> into this buffer.
Modified:
mina/trunk/core/src/main/java/org/apache/mina/common/IoBufferWrapper.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/IoBufferWrapper.java?rev=602109&r1=602108&r2=602109&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/common/IoBufferWrapper.java
(original)
+++ mina/trunk/core/src/main/java/org/apache/mina/common/IoBufferWrapper.java
Fri Dec 7 06:40:41 2007
@@ -199,6 +199,16 @@
}
@Override
+ public IoBuffer getSlice(int index, int length) {
+ return buf.getSlice(index, length);
+ }
+
+ @Override
+ public IoBuffer getSlice(int length) {
+ return buf.getSlice(length);
+ }
+
+ @Override
public IoBuffer get(byte[] dst) {
buf.get(dst);
return this;