You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by ed...@apache.org on 2008/08/17 15:31:26 UTC
svn commit: r686610 - in /mina/trunk:
core/src/main/java/org/apache/mina/core/buffer/
core/src/main/java/org/apache/mina/core/filterchain/
core/src/main/java/org/apache/mina/handler/chain/
core/src/main/java/org/apache/mina/util/ core/src/test/java/org...
Author: edeoliveira
Date: Sun Aug 17 06:31:25 2008
New Revision: 686610
URL: http://svn.apache.org/viewvc?rev=686610&view=rev
Log:
Reformatted and substituted StringBuffer by StringBuilder
Modified:
mina/trunk/core/src/main/java/org/apache/mina/core/buffer/AbstractIoBuffer.java
mina/trunk/core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChain.java
mina/trunk/core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChainBuilder.java
mina/trunk/core/src/main/java/org/apache/mina/handler/chain/IoHandlerChain.java
mina/trunk/core/src/main/java/org/apache/mina/util/Transform.java
mina/trunk/core/src/test/java/org/apache/mina/core/IoFilterChainTest.java
mina/trunk/core/src/test/java/org/apache/mina/handler/chain/ChainedIoHandlerTest.java
mina/trunk/example/src/main/java/org/apache/mina/example/imagine/step3/server/ImageServerIoHandler.java
mina/trunk/example/src/main/java/org/apache/mina/example/reverser/ReverseProtocolHandler.java
Modified: mina/trunk/core/src/main/java/org/apache/mina/core/buffer/AbstractIoBuffer.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/core/buffer/AbstractIoBuffer.java?rev=686610&r1=686609&r2=686610&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/core/buffer/AbstractIoBuffer.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/core/buffer/AbstractIoBuffer.java Sun Aug 17 06:31:25 2008
@@ -44,8 +44,6 @@
import java.util.EnumSet;
import java.util.Set;
-
-
/**
* A base implementation of {@link IoBuffer}. This implementation
* assumes that {@link IoBuffer#buf()} always returns a correct NIO
@@ -59,10 +57,15 @@
public abstract class AbstractIoBuffer extends IoBuffer {
private final IoBufferAllocator allocator;
+
private final boolean derived;
+
private boolean autoExpand;
+
private boolean autoShrink;
+
private boolean recapacityAllowed = true;
+
private int minimumCapacity;
/**
@@ -74,8 +77,7 @@
/**
* Creates a new parent buffer.
*/
- protected AbstractIoBuffer(
- IoBufferAllocator allocator, int initialCapacity) {
+ protected AbstractIoBuffer(IoBufferAllocator allocator, int initialCapacity) {
this.allocator = allocator;
this.recapacityAllowed = true;
this.derived = false;
@@ -115,8 +117,8 @@
@Override
public final IoBuffer minimumCapacity(int minimumCapacity) {
if (minimumCapacity < 0) {
- throw new IllegalArgumentException(
- "minimumCapacity: " + minimumCapacity);
+ throw new IllegalArgumentException("minimumCapacity: "
+ + minimumCapacity);
}
this.minimumCapacity = minimumCapacity;
return this;
@@ -144,8 +146,8 @@
//// Reallocate.
ByteBuffer oldBuf = buf();
- ByteBuffer newBuf =
- allocator.allocateNioBuffer(newCapacity, isDirect());
+ ByteBuffer newBuf = allocator.allocateNioBuffer(newCapacity,
+ isDirect());
oldBuf.clear();
newBuf.put(oldBuf);
buf(newBuf);
@@ -273,8 +275,8 @@
//// Reallocate.
ByteBuffer oldBuf = buf();
- ByteBuffer newBuf =
- allocator.allocateNioBuffer(newCapacity, isDirect());
+ ByteBuffer newBuf = allocator
+ .allocateNioBuffer(newCapacity, isDirect());
oldBuf.position(0);
oldBuf.limit(limit);
newBuf.put(oldBuf);
@@ -443,7 +445,8 @@
return this;
}
- if (isAutoShrink() && remaining <= capacity >>> 2 && capacity > minimumCapacity) {
+ if (isAutoShrink() && remaining <= capacity >>> 2
+ && capacity > minimumCapacity) {
int newCapacity = capacity;
int minCapacity = Math.max(minimumCapacity, remaining << 1);
for (;;) {
@@ -466,14 +469,14 @@
//// Sanity check.
if (remaining > newCapacity) {
throw new IllegalStateException(
- "The amount of the remaining bytes is greater than " +
- "the new capacity.");
+ "The amount of the remaining bytes is greater than "
+ + "the new capacity.");
}
//// Reallocate.
ByteBuffer oldBuf = buf();
- ByteBuffer newBuf =
- allocator.allocateNioBuffer(newCapacity, isDirect());
+ ByteBuffer newBuf = allocator.allocateNioBuffer(newCapacity,
+ isDirect());
newBuf.put(oldBuf);
buf(newBuf);
@@ -711,9 +714,8 @@
int endIndex = pos + length;
if (capacity() < endIndex) {
- throw new IndexOutOfBoundsException(
- "index + length (" + endIndex + ") is greater " +
- "than capacity (" + capacity() + ").");
+ throw new IndexOutOfBoundsException("index + length (" + endIndex
+ + ") is greater " + "than capacity (" + capacity() + ").");
}
clear();
@@ -735,9 +737,8 @@
int limit = limit();
int nextPos = pos + length;
if (limit < nextPos) {
- throw new IndexOutOfBoundsException(
- "position + length (" + nextPos + ") is greater " +
- "than limit (" + limit + ").");
+ throw new IndexOutOfBoundsException("position + length (" + nextPos
+ + ") is greater " + "than limit (" + limit + ").");
}
limit(pos + length);
@@ -804,7 +805,7 @@
@Override
public String toString() {
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder();
if (isDirect()) {
buf.append("DirectBuffer");
} else {
@@ -995,7 +996,8 @@
if (n > Integer.MAX_VALUE) {
bytes = AbstractIoBuffer.this.remaining();
} else {
- bytes = Math.min(AbstractIoBuffer.this.remaining(), (int) n);
+ bytes = Math
+ .min(AbstractIoBuffer.this.remaining(), (int) n);
}
AbstractIoBuffer.this.skip(bytes);
return bytes;
@@ -1029,7 +1031,8 @@
}
@Override
- public String getString(CharsetDecoder decoder) throws CharacterCodingException {
+ public String getString(CharsetDecoder decoder)
+ throws CharacterCodingException {
if (!hasRemaining()) {
return "";
}
@@ -1131,447 +1134,449 @@
@Override
public String getString(int fieldSize, CharsetDecoder decoder)
throws CharacterCodingException {
- checkFieldSize(fieldSize);
-
- if (fieldSize == 0) {
- return "";
- }
-
- if (!hasRemaining()) {
- return "";
- }
+ checkFieldSize(fieldSize);
- boolean utf16 = decoder.charset().name().startsWith("UTF-16");
+ if (fieldSize == 0) {
+ return "";
+ }
- if (utf16 && (fieldSize & 1) != 0) {
- throw new IllegalArgumentException("fieldSize is not even.");
- }
+ if (!hasRemaining()) {
+ return "";
+ }
- int oldPos = position();
- int oldLimit = limit();
- int end = oldPos + fieldSize;
+ boolean utf16 = decoder.charset().name().startsWith("UTF-16");
- if (oldLimit < end) {
- throw new BufferUnderflowException();
- }
+ if (utf16 && (fieldSize & 1) != 0) {
+ throw new IllegalArgumentException("fieldSize is not even.");
+ }
- int i;
+ int oldPos = position();
+ int oldLimit = limit();
+ int end = oldPos + fieldSize;
- if (!utf16) {
- for (i = oldPos; i < end; i++) {
- if (get(i) == 0) {
- break;
- }
- }
+ if (oldLimit < end) {
+ throw new BufferUnderflowException();
+ }
- if (i == end) {
- limit(end);
- } else {
- limit(i);
- }
- } else {
- for (i = oldPos; i < end; i += 2) {
- if (get(i) == 0 && get(i + 1) == 0) {
- break;
- }
- }
+ int i;
- if (i == end) {
- limit(end);
- } else {
- limit(i);
- }
+ if (!utf16) {
+ for (i = oldPos; i < end; i++) {
+ if (get(i) == 0) {
+ break;
}
+ }
- if (!hasRemaining()) {
- limit(oldLimit);
- position(end);
- return "";
+ if (i == end) {
+ limit(end);
+ } else {
+ limit(i);
+ }
+ } else {
+ for (i = oldPos; i < end; i += 2) {
+ if (get(i) == 0 && get(i + 1) == 0) {
+ break;
}
- decoder.reset();
+ }
- int expectedLength = (int) (remaining() * decoder.averageCharsPerByte()) + 1;
- CharBuffer out = CharBuffer.allocate(expectedLength);
- for (;;) {
- CoderResult cr;
- if (hasRemaining()) {
- cr = decoder.decode(buf(), out, true);
- } else {
- cr = decoder.flush(out);
- }
+ if (i == end) {
+ limit(end);
+ } else {
+ limit(i);
+ }
+ }
- if (cr.isUnderflow()) {
- break;
- }
+ if (!hasRemaining()) {
+ limit(oldLimit);
+ position(end);
+ return "";
+ }
+ decoder.reset();
- if (cr.isOverflow()) {
- CharBuffer o = CharBuffer.allocate(out.capacity()
- + expectedLength);
- out.flip();
- o.put(out);
- out = o;
- continue;
- }
+ int expectedLength = (int) (remaining() * decoder.averageCharsPerByte()) + 1;
+ CharBuffer out = CharBuffer.allocate(expectedLength);
+ for (;;) {
+ CoderResult cr;
+ if (hasRemaining()) {
+ cr = decoder.decode(buf(), out, true);
+ } else {
+ cr = decoder.flush(out);
+ }
- if (cr.isError()) {
- // Revert the buffer back to the previous state.
- limit(oldLimit);
- position(oldPos);
- cr.throwException();
- }
- }
+ if (cr.isUnderflow()) {
+ break;
+ }
+ if (cr.isOverflow()) {
+ CharBuffer o = CharBuffer.allocate(out.capacity()
+ + expectedLength);
+ out.flip();
+ o.put(out);
+ out = o;
+ continue;
+ }
+
+ if (cr.isError()) {
+ // Revert the buffer back to the previous state.
limit(oldLimit);
- position(end);
- return out.flip().toString();
+ position(oldPos);
+ cr.throwException();
}
+ }
+
+ limit(oldLimit);
+ position(end);
+ return out.flip().toString();
+ }
@Override
public IoBuffer putString(CharSequence val, CharsetEncoder encoder)
throws CharacterCodingException {
- if (val.length() == 0) {
- return this;
- }
+ if (val.length() == 0) {
+ return this;
+ }
- CharBuffer in = CharBuffer.wrap(val);
- encoder.reset();
+ CharBuffer in = CharBuffer.wrap(val);
+ encoder.reset();
- int expandedState = 0;
+ int expandedState = 0;
- for (;;) {
- CoderResult cr;
- if (in.hasRemaining()) {
- cr = encoder.encode(in, buf(), true);
- } else {
- cr = encoder.flush(buf());
- }
+ for (;;) {
+ CoderResult cr;
+ if (in.hasRemaining()) {
+ cr = encoder.encode(in, buf(), true);
+ } else {
+ cr = encoder.flush(buf());
+ }
- if (cr.isUnderflow()) {
+ if (cr.isUnderflow()) {
+ break;
+ }
+ if (cr.isOverflow()) {
+ if (isAutoExpand()) {
+ switch (expandedState) {
+ case 0:
+ autoExpand((int) Math.ceil(in.remaining()
+ * encoder.averageBytesPerChar()));
+ expandedState++;
break;
+ case 1:
+ autoExpand((int) Math.ceil(in.remaining()
+ * encoder.maxBytesPerChar()));
+ expandedState++;
+ break;
+ default:
+ throw new RuntimeException("Expanded by "
+ + (int) Math.ceil(in.remaining()
+ * encoder.maxBytesPerChar())
+ + " but that wasn't enough for '" + val + "'");
}
- if (cr.isOverflow()) {
- if (isAutoExpand()) {
- switch (expandedState) {
- case 0:
- autoExpand((int) Math.ceil(in.remaining()
- * encoder.averageBytesPerChar()));
- expandedState++;
- break;
- case 1:
- autoExpand((int) Math.ceil(in.remaining()
- * encoder.maxBytesPerChar()));
- expandedState++;
- break;
- default:
- throw new RuntimeException("Expanded by "
- + (int) Math.ceil(in.remaining()
- * encoder.maxBytesPerChar())
- + " but that wasn't enough for '" + val + "'");
- }
- continue;
- }
- } else {
- expandedState = 0;
- }
- cr.throwException();
+ continue;
}
- return this;
+ } else {
+ expandedState = 0;
}
+ cr.throwException();
+ }
+ return this;
+ }
@Override
- public IoBuffer putString(CharSequence val, int fieldSize, CharsetEncoder encoder)
- throws CharacterCodingException {
- checkFieldSize(fieldSize);
-
- if (fieldSize == 0) {
- return this;
- }
+ public IoBuffer putString(CharSequence val, int fieldSize,
+ CharsetEncoder encoder) throws CharacterCodingException {
+ checkFieldSize(fieldSize);
- autoExpand(fieldSize);
+ if (fieldSize == 0) {
+ return this;
+ }
- boolean utf16 = encoder.charset().name().startsWith("UTF-16");
+ autoExpand(fieldSize);
- if (utf16 && (fieldSize & 1) != 0) {
- throw new IllegalArgumentException("fieldSize is not even.");
- }
+ boolean utf16 = encoder.charset().name().startsWith("UTF-16");
- int oldLimit = limit();
- int end = position() + fieldSize;
+ if (utf16 && (fieldSize & 1) != 0) {
+ throw new IllegalArgumentException("fieldSize is not even.");
+ }
- if (oldLimit < end) {
- throw new BufferOverflowException();
- }
+ int oldLimit = limit();
+ int end = position() + fieldSize;
- if (val.length() == 0) {
- if (!utf16) {
- put((byte) 0x00);
- } else {
- put((byte) 0x00);
- put((byte) 0x00);
- }
- position(end);
- return this;
- }
+ if (oldLimit < end) {
+ throw new BufferOverflowException();
+ }
- CharBuffer in = CharBuffer.wrap(val);
- limit(end);
- encoder.reset();
+ if (val.length() == 0) {
+ if (!utf16) {
+ put((byte) 0x00);
+ } else {
+ put((byte) 0x00);
+ put((byte) 0x00);
+ }
+ position(end);
+ return this;
+ }
- for (;;) {
- CoderResult cr;
- if (in.hasRemaining()) {
- cr = encoder.encode(in, buf(), true);
- } else {
- cr = encoder.flush(buf());
- }
+ CharBuffer in = CharBuffer.wrap(val);
+ limit(end);
+ encoder.reset();
- if (cr.isUnderflow() || cr.isOverflow()) {
- break;
- }
- cr.throwException();
- }
+ for (;;) {
+ CoderResult cr;
+ if (in.hasRemaining()) {
+ cr = encoder.encode(in, buf(), true);
+ } else {
+ cr = encoder.flush(buf());
+ }
- limit(oldLimit);
+ if (cr.isUnderflow() || cr.isOverflow()) {
+ break;
+ }
+ cr.throwException();
+ }
- if (position() < end) {
- if (!utf16) {
- put((byte) 0x00);
- } else {
- put((byte) 0x00);
- put((byte) 0x00);
- }
- }
+ limit(oldLimit);
- position(end);
- return this;
+ if (position() < end) {
+ if (!utf16) {
+ put((byte) 0x00);
+ } else {
+ put((byte) 0x00);
+ put((byte) 0x00);
}
+ }
+
+ position(end);
+ return this;
+ }
@Override
public String getPrefixedString(CharsetDecoder decoder)
throws CharacterCodingException {
- return getPrefixedString(2, decoder);
- }
+ return getPrefixedString(2, decoder);
+ }
- /**
- * Reads a string which has a length field before the actual
- * encoded string, using the specified <code>decoder</code> and returns it.
- *
- * @param prefixLength the length of the length field (1, 2, or 4)
- * @param decoder the decoder to use for decoding the string
- * @return the prefixed string
- * @throws CharacterCodingException when decoding fails
- * @throws BufferUnderflowException when there is not enough data available
- */
+ /**
+ * Reads a string which has a length field before the actual
+ * encoded string, using the specified <code>decoder</code> and returns it.
+ *
+ * @param prefixLength the length of the length field (1, 2, or 4)
+ * @param decoder the decoder to use for decoding the string
+ * @return the prefixed string
+ * @throws CharacterCodingException when decoding fails
+ * @throws BufferUnderflowException when there is not enough data available
+ */
@Override
public String getPrefixedString(int prefixLength, CharsetDecoder decoder)
throws CharacterCodingException {
- if (!prefixedDataAvailable(prefixLength)) {
- throw new BufferUnderflowException();
- }
+ if (!prefixedDataAvailable(prefixLength)) {
+ throw new BufferUnderflowException();
+ }
- int fieldSize = 0;
+ int fieldSize = 0;
- switch (prefixLength) {
- case 1:
- fieldSize = getUnsigned();
- break;
- case 2:
- fieldSize = getUnsignedShort();
- break;
- case 4:
- fieldSize = getInt();
- break;
- }
+ switch (prefixLength) {
+ case 1:
+ fieldSize = getUnsigned();
+ break;
+ case 2:
+ fieldSize = getUnsignedShort();
+ break;
+ case 4:
+ fieldSize = getInt();
+ break;
+ }
- if (fieldSize == 0) {
- return "";
- }
+ if (fieldSize == 0) {
+ return "";
+ }
- boolean utf16 = decoder.charset().name().startsWith("UTF-16");
+ boolean utf16 = decoder.charset().name().startsWith("UTF-16");
- if (utf16 && (fieldSize & 1) != 0) {
- throw new BufferDataException(
- "fieldSize is not even for a UTF-16 string.");
- }
+ if (utf16 && (fieldSize & 1) != 0) {
+ throw new BufferDataException(
+ "fieldSize is not even for a UTF-16 string.");
+ }
- int oldLimit = limit();
- int end = position() + fieldSize;
+ int oldLimit = limit();
+ int end = position() + fieldSize;
- if (oldLimit < end) {
- throw new BufferUnderflowException();
- }
+ if (oldLimit < end) {
+ throw new BufferUnderflowException();
+ }
- limit(end);
- decoder.reset();
+ limit(end);
+ decoder.reset();
- int expectedLength = (int) (remaining() * decoder.averageCharsPerByte()) + 1;
- CharBuffer out = CharBuffer.allocate(expectedLength);
- for (;;) {
- CoderResult cr;
- if (hasRemaining()) {
- cr = decoder.decode(buf(), out, true);
- } else {
- cr = decoder.flush(out);
- }
+ int expectedLength = (int) (remaining() * decoder.averageCharsPerByte()) + 1;
+ CharBuffer out = CharBuffer.allocate(expectedLength);
+ for (;;) {
+ CoderResult cr;
+ if (hasRemaining()) {
+ cr = decoder.decode(buf(), out, true);
+ } else {
+ cr = decoder.flush(out);
+ }
- if (cr.isUnderflow()) {
- break;
- }
+ if (cr.isUnderflow()) {
+ break;
+ }
- if (cr.isOverflow()) {
- CharBuffer o = CharBuffer.allocate(out.capacity()
- + expectedLength);
- out.flip();
- o.put(out);
- out = o;
- continue;
- }
+ if (cr.isOverflow()) {
+ CharBuffer o = CharBuffer.allocate(out.capacity()
+ + expectedLength);
+ out.flip();
+ o.put(out);
+ out = o;
+ continue;
+ }
- cr.throwException();
- }
+ cr.throwException();
+ }
- limit(oldLimit);
- position(end);
- return out.flip().toString();
- }
+ limit(oldLimit);
+ position(end);
+ return out.flip().toString();
+ }
@Override
public IoBuffer putPrefixedString(CharSequence in, CharsetEncoder encoder)
throws CharacterCodingException {
- return putPrefixedString(in, 2, 0, encoder);
- }
+ return putPrefixedString(in, 2, 0, encoder);
+ }
+
+ @Override
+ public IoBuffer putPrefixedString(CharSequence in, int prefixLength,
+ CharsetEncoder encoder) throws CharacterCodingException {
+ return putPrefixedString(in, prefixLength, 0, encoder);
+ }
@Override
- public IoBuffer putPrefixedString(CharSequence in, int prefixLength, CharsetEncoder encoder)
+ public IoBuffer putPrefixedString(CharSequence in, int prefixLength,
+ int padding, CharsetEncoder encoder)
throws CharacterCodingException {
- return putPrefixedString(in, prefixLength, 0, encoder);
- }
+ return putPrefixedString(in, prefixLength, padding, (byte) 0, encoder);
+ }
@Override
- public IoBuffer putPrefixedString(CharSequence in, int prefixLength, int padding,
- CharsetEncoder encoder) throws CharacterCodingException {
- return putPrefixedString(in, prefixLength, padding, (byte) 0, encoder);
+ public IoBuffer putPrefixedString(CharSequence val, int prefixLength,
+ int padding, byte padValue, CharsetEncoder encoder)
+ throws CharacterCodingException {
+ int maxLength;
+ switch (prefixLength) {
+ case 1:
+ maxLength = 255;
+ break;
+ case 2:
+ maxLength = 65535;
+ break;
+ case 4:
+ maxLength = Integer.MAX_VALUE;
+ break;
+ default:
+ throw new IllegalArgumentException("prefixLength: " + prefixLength);
+ }
+
+ if (val.length() > maxLength) {
+ throw new IllegalArgumentException(
+ "The specified string is too long.");
+ }
+ if (val.length() == 0) {
+ switch (prefixLength) {
+ case 1:
+ put((byte) 0);
+ break;
+ case 2:
+ putShort((short) 0);
+ break;
+ case 4:
+ putInt(0);
+ break;
}
+ return this;
+ }
- @Override
- public IoBuffer putPrefixedString(CharSequence val, int prefixLength, int padding,
- byte padValue, CharsetEncoder encoder) throws CharacterCodingException {
- int maxLength;
- switch (prefixLength) {
- case 1:
- maxLength = 255;
- break;
- case 2:
- maxLength = 65535;
- break;
- case 4:
- maxLength = Integer.MAX_VALUE;
- break;
- default:
- throw new IllegalArgumentException("prefixLength: " + prefixLength);
- }
+ int padMask;
+ switch (padding) {
+ case 0:
+ case 1:
+ padMask = 0;
+ break;
+ case 2:
+ padMask = 1;
+ break;
+ case 4:
+ padMask = 3;
+ break;
+ default:
+ throw new IllegalArgumentException("padding: " + padding);
+ }
- if (val.length() > maxLength) {
- throw new IllegalArgumentException(
- "The specified string is too long.");
- }
- if (val.length() == 0) {
- switch (prefixLength) {
- case 1:
- put((byte) 0);
- break;
- case 2:
- putShort((short) 0);
- break;
- case 4:
- putInt(0);
- break;
- }
- return this;
- }
+ CharBuffer in = CharBuffer.wrap(val);
+ skip(prefixLength); // make a room for the length field
+ int oldPos = position();
+ encoder.reset();
- int padMask;
- switch (padding) {
- case 0:
- case 1:
- padMask = 0;
- break;
- case 2:
- padMask = 1;
- break;
- case 4:
- padMask = 3;
- break;
- default:
- throw new IllegalArgumentException("padding: " + padding);
- }
+ int expandedState = 0;
- CharBuffer in = CharBuffer.wrap(val);
- skip(prefixLength); // make a room for the length field
- int oldPos = position();
- encoder.reset();
-
- int expandedState = 0;
-
- for (;;) {
- CoderResult cr;
- if (in.hasRemaining()) {
- cr = encoder.encode(in, buf(), true);
- } else {
- cr = encoder.flush(buf());
- }
+ for (;;) {
+ CoderResult cr;
+ if (in.hasRemaining()) {
+ cr = encoder.encode(in, buf(), true);
+ } else {
+ cr = encoder.flush(buf());
+ }
- if (position() - oldPos > maxLength) {
- throw new IllegalArgumentException(
- "The specified string is too long.");
- }
+ if (position() - oldPos > maxLength) {
+ throw new IllegalArgumentException(
+ "The specified string is too long.");
+ }
- if (cr.isUnderflow()) {
+ if (cr.isUnderflow()) {
+ break;
+ }
+ if (cr.isOverflow()) {
+ if (isAutoExpand()) {
+ switch (expandedState) {
+ case 0:
+ autoExpand((int) Math.ceil(in.remaining()
+ * encoder.averageBytesPerChar()));
+ expandedState++;
break;
+ case 1:
+ autoExpand((int) Math.ceil(in.remaining()
+ * encoder.maxBytesPerChar()));
+ expandedState++;
+ break;
+ default:
+ throw new RuntimeException("Expanded by "
+ + (int) Math.ceil(in.remaining()
+ * encoder.maxBytesPerChar())
+ + " but that wasn't enough for '" + val + "'");
}
- if (cr.isOverflow()) {
- if (isAutoExpand()) {
- switch (expandedState) {
- case 0:
- autoExpand((int) Math.ceil(in.remaining()
- * encoder.averageBytesPerChar()));
- expandedState++;
- break;
- case 1:
- autoExpand((int) Math.ceil(in.remaining()
- * encoder.maxBytesPerChar()));
- expandedState++;
- break;
- default:
- throw new RuntimeException("Expanded by "
- + (int) Math.ceil(in.remaining()
- * encoder.maxBytesPerChar())
- + " but that wasn't enough for '" + val + "'");
- }
- continue;
- }
- } else {
- expandedState = 0;
- }
- cr.throwException();
+ continue;
}
-
- // Write the length field
- fill(padValue, padding - (position() - oldPos & padMask));
- int length = position() - oldPos;
- switch (prefixLength) {
- case 1:
- put(oldPos - 1, (byte) length);
- break;
- case 2:
- putShort(oldPos - 2, (short) length);
- break;
- case 4:
- putInt(oldPos - 4, length);
- break;
- }
- return this;
+ } else {
+ expandedState = 0;
}
+ cr.throwException();
+ }
+
+ // Write the length field
+ fill(padValue, padding - (position() - oldPos & padMask));
+ int length = position() - oldPos;
+ switch (prefixLength) {
+ case 1:
+ put(oldPos - 1, (byte) length);
+ break;
+ case 2:
+ putShort(oldPos - 2, (short) length);
+ break;
+ case 4:
+ putInt(oldPos - 4, length);
+ break;
+ }
+ return this;
+ }
@Override
public Object getObject() throws ClassNotFoundException {
@@ -1579,7 +1584,8 @@
}
@Override
- public Object getObject(final ClassLoader classLoader) throws ClassNotFoundException {
+ public Object getObject(final ClassLoader classLoader)
+ throws ClassNotFoundException {
if (!prefixedDataAvailable(4)) {
throw new BufferUnderflowException();
}
@@ -1606,8 +1612,8 @@
return super.readClassDescriptor();
case 1: // Non-primitive types
String className = readUTF();
- Class<?> clazz =
- Class.forName(className, true, classLoader);
+ Class<?> clazz = Class.forName(className, true,
+ classLoader);
return ObjectStreamClass.lookup(clazz);
default:
throw new StreamCorruptedException(
@@ -1616,7 +1622,8 @@
}
@Override
- protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
+ protected Class<?> resolveClass(ObjectStreamClass desc)
+ throws IOException, ClassNotFoundException {
String name = desc.getName();
try {
return Class.forName(name, false, classLoader);
@@ -1828,7 +1835,9 @@
}
private static final long BYTE_MASK = 0xFFL;
+
private static final long SHORT_MASK = 0xFFFFL;
+
private static final long INT_MASK = 0xFFFFFFFFL;
@Override
@@ -1927,7 +1936,8 @@
}
@Override
- public <E extends Enum<E>> EnumSet<E> getEnumSet(int index, Class<E> enumClass) {
+ public <E extends Enum<E>> EnumSet<E> getEnumSet(int index,
+ Class<E> enumClass) {
return toEnumSet(enumClass, get(index) & BYTE_MASK);
}
@@ -1937,7 +1947,8 @@
}
@Override
- public <E extends Enum<E>> EnumSet<E> getEnumSetShort(int index, Class<E> enumClass) {
+ public <E extends Enum<E>> EnumSet<E> getEnumSetShort(int index,
+ Class<E> enumClass) {
return toEnumSet(enumClass, getShort(index) & SHORT_MASK);
}
@@ -1947,7 +1958,8 @@
}
@Override
- public <E extends Enum<E>> EnumSet<E> getEnumSetInt(int index, Class<E> enumClass) {
+ public <E extends Enum<E>> EnumSet<E> getEnumSetInt(int index,
+ Class<E> enumClass) {
return toEnumSet(enumClass, getInt(index) & INT_MASK);
}
@@ -1957,7 +1969,8 @@
}
@Override
- public <E extends Enum<E>> EnumSet<E> getEnumSetLong(int index, Class<E> enumClass) {
+ public <E extends Enum<E>> EnumSet<E> getEnumSetLong(int index,
+ Class<E> enumClass) {
return toEnumSet(enumClass, getLong(index));
}
Modified: mina/trunk/core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChain.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChain.java?rev=686610&r1=686609&r2=686610&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChain.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChain.java Sun Aug 17 06:31:25 2008
@@ -53,7 +53,8 @@
* attribute and notifies the future when {@link #fireSessionCreated()}
* or {@link #fireExceptionCaught(Throwable)} is invoked.
*/
- public static final AttributeKey SESSION_CREATED_FUTURE = new AttributeKey(DefaultIoFilterChain.class, "connectFuture");
+ public static final AttributeKey SESSION_CREATED_FUTURE = new AttributeKey(
+ DefaultIoFilterChain.class, "connectFuture");
private final AbstractIoSession session;
@@ -232,8 +233,8 @@
+ oldFilter.getClass().getName());
}
- public synchronized IoFilter replace(Class<? extends IoFilter> oldFilterType,
- IoFilter newFilter) {
+ public synchronized IoFilter replace(
+ Class<? extends IoFilter> oldFilterType, IoFilter newFilter) {
EntryImpl e = head.nextEntry;
while (e != tail) {
if (oldFilterType.isAssignableFrom(e.getFilter().getClass())) {
@@ -387,8 +388,8 @@
callNextSessionIdle(head, session, status);
}
- private void callNextSessionIdle(
- Entry entry, IoSession session, IdleStatus status) {
+ private void callNextSessionIdle(Entry entry, IoSession session,
+ IdleStatus status) {
try {
entry.getFilter().sessionIdle(entry.getNextFilter(), session,
status);
@@ -399,20 +400,19 @@
public void fireMessageReceived(Object message) {
if (message instanceof IoBuffer) {
- session.increaseReadBytes(
- ((IoBuffer) message).remaining(),
- System.currentTimeMillis());
+ session.increaseReadBytes(((IoBuffer) message).remaining(), System
+ .currentTimeMillis());
}
Entry head = this.head;
callNextMessageReceived(head, session, message);
}
- private void callNextMessageReceived(
- Entry entry, IoSession session, Object message) {
+ private void callNextMessageReceived(Entry entry, IoSession session,
+ Object message) {
try {
- entry.getFilter().messageReceived(
- entry.getNextFilter(), session, message);
+ entry.getFilter().messageReceived(entry.getNextFilter(), session,
+ message);
} catch (Throwable e) {
fireExceptionCaught(e);
}
@@ -430,7 +430,7 @@
Entry head = this.head;
callNextMessageSent(head, session, request);
}
-
+
private void callNextMessageSent(Entry entry, IoSession session,
WriteRequest writeRequest) {
try {
@@ -449,13 +449,17 @@
private void callNextExceptionCaught(Entry entry, IoSession session,
Throwable cause) {
// Notify the related future.
- ConnectFuture future = (ConnectFuture) session.removeAttribute(SESSION_CREATED_FUTURE);
+ ConnectFuture future = (ConnectFuture) session
+ .removeAttribute(SESSION_CREATED_FUTURE);
if (future == null) {
try {
- entry.getFilter().exceptionCaught(entry.getNextFilter(), session,
- cause);
+ entry.getFilter().exceptionCaught(entry.getNextFilter(),
+ session, cause);
} catch (Throwable e) {
- logger.warn("Unexpected exception from exceptionCaught handler.", e);
+ logger
+ .warn(
+ "Unexpected exception from exceptionCaught handler.",
+ e);
}
} else {
// Please note that this place is not the only place that
@@ -499,14 +503,16 @@
callPreviousFilterSetTrafficMask(tail, session, trafficMask);
}
- private void callPreviousFilterSetTrafficMask(Entry entry, IoSession session, TrafficMask trafficMask) {
+ private void callPreviousFilterSetTrafficMask(Entry entry,
+ IoSession session, TrafficMask trafficMask) {
try {
- entry.getFilter().filterSetTrafficMask(entry.getNextFilter(), session, trafficMask);
+ entry.getFilter().filterSetTrafficMask(entry.getNextFilter(),
+ session, trafficMask);
} catch (Throwable e) {
fireExceptionCaught(e);
}
}
-
+
public List<Entry> getAll() {
List<Entry> list = new ArrayList<Entry>();
EntryImpl e = head.nextEntry;
@@ -542,7 +548,7 @@
@Override
public String toString() {
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder();
buf.append("{ ");
boolean empty = true;
@@ -669,7 +675,7 @@
s.setTrafficMaskNow(trafficMask);
s.getProcessor().updateTrafficMask(s);
}
-
+
}
private static class TailFilter extends IoFilterAdapter {
@@ -680,7 +686,8 @@
session.getHandler().sessionCreated(session);
} finally {
// Notify the related future.
- ConnectFuture future = (ConnectFuture) session.removeAttribute(SESSION_CREATED_FUTURE);
+ ConnectFuture future = (ConnectFuture) session
+ .removeAttribute(SESSION_CREATED_FUTURE);
if (future != null) {
future.setSession(session);
}
@@ -852,7 +859,8 @@
public void filterSetTrafficMask(IoSession session,
TrafficMask trafficMask) {
Entry nextEntry = EntryImpl.this.prevEntry;
- callPreviousFilterSetTrafficMask(nextEntry, session, trafficMask);
+ callPreviousFilterSetTrafficMask(nextEntry, session,
+ trafficMask);
}
};
}
Modified: mina/trunk/core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChainBuilder.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChainBuilder.java?rev=686610&r1=686609&r2=686610&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChainBuilder.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/core/filterchain/DefaultIoFilterChainBuilder.java Sun Aug 17 06:31:25 2008
@@ -454,7 +454,7 @@
@Override
public String toString() {
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder();
buf.append("{ ");
boolean empty = true;
Modified: mina/trunk/core/src/main/java/org/apache/mina/handler/chain/IoHandlerChain.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/handler/chain/IoHandlerChain.java?rev=686610&r1=686609&r2=686610&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/handler/chain/IoHandlerChain.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/handler/chain/IoHandlerChain.java Sun Aug 17 06:31:25 2008
@@ -250,7 +250,7 @@
@Override
public String toString() {
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder();
buf.append("{ ");
boolean empty = true;
Modified: mina/trunk/core/src/main/java/org/apache/mina/util/Transform.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/util/Transform.java?rev=686610&r1=686609&r2=686610&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/util/Transform.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/util/Transform.java Sun Aug 17 06:31:25 2008
@@ -64,7 +64,7 @@
return input;
}
- StringBuffer buf = new StringBuffer(input.length() + 6);
+ StringBuilder buf = new StringBuilder(input.length() + 6);
char ch;
int len = input.length();
Modified: mina/trunk/core/src/test/java/org/apache/mina/core/IoFilterChainTest.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/test/java/org/apache/mina/core/IoFilterChainTest.java?rev=686610&r1=686609&r2=686610&view=diff
==============================================================================
--- mina/trunk/core/src/test/java/org/apache/mina/core/IoFilterChainTest.java (original)
+++ mina/trunk/core/src/test/java/org/apache/mina/core/IoFilterChainTest.java Sun Aug 17 06:31:25 2008
@@ -225,7 +225,7 @@
private String formatResult(String result) {
result = result.replaceAll("\\s", "");
- StringBuffer buf = new StringBuffer(result.length() * 4 / 3);
+ StringBuilder buf = new StringBuilder(result.length() * 4 / 3);
for (int i = 0; i < result.length(); i++) {
buf.append(result.charAt(i));
if (i % 3 == 2) {
Modified: mina/trunk/core/src/test/java/org/apache/mina/handler/chain/ChainedIoHandlerTest.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/test/java/org/apache/mina/handler/chain/ChainedIoHandlerTest.java?rev=686610&r1=686609&r2=686610&view=diff
==============================================================================
--- mina/trunk/core/src/test/java/org/apache/mina/handler/chain/ChainedIoHandlerTest.java (original)
+++ mina/trunk/core/src/test/java/org/apache/mina/handler/chain/ChainedIoHandlerTest.java Sun Aug 17 06:31:25 2008
@@ -38,7 +38,7 @@
public void testChainedCommand() throws Exception {
IoHandlerChain chain = new IoHandlerChain();
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder();
chain.addLast("A", new TestCommand(buf, 'A'));
chain.addLast("B", new TestCommand(buf, 'B'));
chain.addLast("C", new TestCommand(buf, 'C'));
@@ -49,11 +49,11 @@
}
private class TestCommand implements IoHandlerCommand {
- private final StringBuffer buf;
+ private final StringBuilder buf;
private final char ch;
- private TestCommand(StringBuffer buf, char ch) {
+ private TestCommand(StringBuilder buf, char ch) {
this.buf = buf;
this.ch = ch;
}
Modified: mina/trunk/example/src/main/java/org/apache/mina/example/imagine/step3/server/ImageServerIoHandler.java
URL: http://svn.apache.org/viewvc/mina/trunk/example/src/main/java/org/apache/mina/example/imagine/step3/server/ImageServerIoHandler.java?rev=686610&r1=686609&r2=686610&view=diff
==============================================================================
--- mina/trunk/example/src/main/java/org/apache/mina/example/imagine/step3/server/ImageServerIoHandler.java (original)
+++ mina/trunk/example/src/main/java/org/apache/mina/example/imagine/step3/server/ImageServerIoHandler.java Sun Aug 17 06:31:25 2008
@@ -158,7 +158,7 @@
*/
private String generateString(IoSession session, int length) {
Integer index = (Integer) session.getAttribute(INDEX_KEY);
- StringBuffer buffer = new StringBuffer(length);
+ StringBuilder buffer = new StringBuilder(length);
while (buffer.length() < length) {
buffer.append(characters.charAt(index));
index++;
Modified: mina/trunk/example/src/main/java/org/apache/mina/example/reverser/ReverseProtocolHandler.java
URL: http://svn.apache.org/viewvc/mina/trunk/example/src/main/java/org/apache/mina/example/reverser/ReverseProtocolHandler.java?rev=686610&r1=686609&r2=686610&view=diff
==============================================================================
--- mina/trunk/example/src/main/java/org/apache/mina/example/reverser/ReverseProtocolHandler.java (original)
+++ mina/trunk/example/src/main/java/org/apache/mina/example/reverser/ReverseProtocolHandler.java Sun Aug 17 06:31:25 2008
@@ -40,7 +40,7 @@
public void messageReceived(IoSession session, Object message) {
// Reverse reveiced string
String str = message.toString();
- StringBuffer buf = new StringBuffer(str.length());
+ StringBuilder buf = new StringBuilder(str.length());
for (int i = str.length() - 1; i >= 0; i--) {
buf.append(str.charAt(i));
}