Repository: mina Updated Branches: refs/heads/2.0 59b7dbabc -> eb2786150
Minor refactoring in Javadoc Project: http://git-wip-us.apache.org/repos/asf/mina/repo Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/91ec8652 Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/91ec8652 Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/91ec8652 Branch: refs/heads/2.0 Commit: 91ec86521a6039f7832859e69ff8b53b98d095e9 Parents: 59b7dba Author: Emmanuel Lécharny <[email protected]> Authored: Mon Dec 22 09:00:55 2014 +0100 Committer: Emmanuel Lécharny <[email protected]> Committed: Mon Dec 22 09:00:55 2014 +0100 ---------------------------------------------------------------------- .../mina/core/buffer/AbstractIoBuffer.java | 3 ++ .../org/apache/mina/core/buffer/IoBuffer.java | 51 +++++++++++++++++--- 2 files changed, 46 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mina/blob/91ec8652/mina-core/src/main/java/org/apache/mina/core/buffer/AbstractIoBuffer.java ---------------------------------------------------------------------- diff --git a/mina-core/src/main/java/org/apache/mina/core/buffer/AbstractIoBuffer.java b/mina-core/src/main/java/org/apache/mina/core/buffer/AbstractIoBuffer.java index 0b5a397..fee0091 100644 --- a/mina-core/src/main/java/org/apache/mina/core/buffer/AbstractIoBuffer.java +++ b/mina-core/src/main/java/org/apache/mina/core/buffer/AbstractIoBuffer.java @@ -274,6 +274,7 @@ public abstract class AbstractIoBuffer extends IoBuffer { int end = pos + expectedRemaining; int newCapacity; + if (autoExpand) { newCapacity = IoBuffer.normalizeCapacity(end); } else { @@ -366,9 +367,11 @@ public abstract class AbstractIoBuffer extends IoBuffer { public final IoBuffer position(int newPosition) { autoExpand(newPosition, 0); buf().position(newPosition); + if (mark > newPosition) { mark = -1; } + return this; } http://git-wip-us.apache.org/repos/asf/mina/blob/91ec8652/mina-core/src/main/java/org/apache/mina/core/buffer/IoBuffer.java ---------------------------------------------------------------------- diff --git a/mina-core/src/main/java/org/apache/mina/core/buffer/IoBuffer.java b/mina-core/src/main/java/org/apache/mina/core/buffer/IoBuffer.java index 19827c2..9ef8ce3 100644 --- a/mina-core/src/main/java/org/apache/mina/core/buffer/IoBuffer.java +++ b/mina-core/src/main/java/org/apache/mina/core/buffer/IoBuffer.java @@ -373,9 +373,9 @@ public abstract class IoBuffer implements Comparable<IoBuffer> { * | | | * pos limit capacity * - * V < C : + * V <= C : * - * 0 L V + * 0 L C * +--------+----------+ * |XXXXXXXX| | * +--------+----------+ @@ -393,6 +393,8 @@ public abstract class IoBuffer implements Comparable<IoBuffer> { * | | | | * pos limit oldCapacity newCapacity * + * The buffer has been increased. + * * </pre> * * @param capacity the wanted capacity @@ -446,7 +448,7 @@ public abstract class IoBuffer implements Comparable<IoBuffer> { * | | | * pos limit capacity * - * ( pos + V) <= L, no change : + * ( pos + V ) <= L, no change : * * 0 L C * +--------+----------+ @@ -468,7 +470,7 @@ public abstract class IoBuffer implements Comparable<IoBuffer> { * | | | * pos newlimit newCapacity * - * You can now put ( L - pos + V) bytes in the buffer. + * You can now put ( L - pos + V ) bytes in the buffer. * * * ( pos + V ) > C @@ -515,7 +517,7 @@ public abstract class IoBuffer implements Comparable<IoBuffer> { * | | | * pos limit capacity * - * ( pos + V) <= L, no change : + * ( pos + V ) <= L, no change : * * P L C * +--------+----------+ @@ -569,10 +571,43 @@ public abstract class IoBuffer implements Comparable<IoBuffer> { /** * Changes the capacity of this buffer so this buffer occupies as less * memory as possible while retaining the position, limit and the buffer - * content between the position and limit. The capacity of the buffer never - * becomes less than {@link #minimumCapacity()}. The mark is discarded once - * the capacity changes. + * content between the position and limit. <br/> + * <b>The capacity of the buffer never becomes less than {@link #minimumCapacity()}</b></br>. + * The mark is discarded once the capacity changes.<br/> + * Typically, a call to this method tries to remove as much unused bytes + * as possible, dividing by two the initial capacity until it can't without + * obtaining a new capacity lower than the {@link #minimumCapacity()}. For instance, if + * the limit is 7 and the capacity is 36, with a minimum capacity of 8, + * shrinking the buffer will left a capacity of 9 (we go down from 36 to 18, then from 18 to 9). * + * <pre> + * Initial buffer : + * + * +--------+----------+ + * |XXXXXXXX| | + * +--------+----------+ + * ^ ^ ^ ^ + * | | | | + * pos | | capacity + * | | + * | +-- minimumCapacity + * | + * +-- limit + * + * Resulting buffer : + * + * +--------+--+-+ + * |XXXXXXXX| | | + * +--------+--+-+ + * ^ ^ ^ ^ + * | | | | + * | | | +-- new capacity + * | | | + * pos | +-- minimum capacity + * | + * +-- limit + * </pre> + * * @return The modified IoBuffer instance */ public abstract IoBuffer shrink();
