Author: remy.maucherat(a)jboss.com
Date: 2008-03-31 20:45:28 -0400 (Mon, 31 Mar 2008)
New Revision: 574
Modified:
trunk/java/org/apache/tomcat/util/buf/B2CConverter.java
trunk/java/org/apache/tomcat/util/buf/C2BConverter.java
Log:
- Cleanup, no change.
Modified: trunk/java/org/apache/tomcat/util/buf/B2CConverter.java
===================================================================
--- trunk/java/org/apache/tomcat/util/buf/B2CConverter.java 2008-03-31 16:23:06 UTC (rev
573)
+++ trunk/java/org/apache/tomcat/util/buf/B2CConverter.java 2008-04-01 00:45:28 UTC (rev
574)
@@ -26,7 +26,7 @@
import java.nio.charset.CoderResult;
/**
- * Helper class to handle byte to char conversion using NIO.
+ * NIO based character decoder.
*
* @author Remy Maucherat
*/
@@ -54,10 +54,18 @@
}
/**
- * Convert the given bytes to chars.
+ * Reset the decoder state, and empty the leftover buffer.
+ */
+ public void recycle() {
+ decoder.reset();
+ leftovers.position(0);
+ }
+
+ /**
+ * Convert the given bytes to characters.
*
- * @param bc
- * @param cc
+ * @param bc byte input
+ * @param cc char output
*/
public void convert(ByteChunk bc, CharChunk cc)
throws IOException {
@@ -78,10 +86,11 @@
cb.position(cc.getEnd());
cb.limit(cc.getBuffer().length);
}
+ CoderResult result = null;
// Parse leftover if any are present
- CoderResult result = null;
if (leftovers.position() > 0) {
int pos = cb.position();
+ // Loop until one char is decoded or there is a decoder error
do {
leftovers.put(bc.substractB());
leftovers.flip();
@@ -117,13 +126,4 @@
}
}
- /**
- * Reset the internal state, empty the buffers.
- * The encoding remain in effect, the internal buffers remain allocated.
- */
- public void recycle() {
- decoder.reset();
- leftovers.position(0);
- }
-
}
Modified: trunk/java/org/apache/tomcat/util/buf/C2BConverter.java
===================================================================
--- trunk/java/org/apache/tomcat/util/buf/C2BConverter.java 2008-03-31 16:23:06 UTC (rev
573)
+++ trunk/java/org/apache/tomcat/util/buf/C2BConverter.java 2008-04-01 00:45:28 UTC (rev
574)
@@ -26,8 +26,10 @@
/**
* NIO based character encoder.
+ *
+ * @author Remy Maucherat
*/
-public final class C2BConverter {
+public class C2BConverter {
protected static org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(C2BConverter.class);
@@ -44,14 +46,17 @@
}
/**
- * The encoding remain in effect, the encoder remains allocated.
+ * Reset the encoder state.
*/
public void recycle() {
encoder.reset();
}
/**
- * Convert the given charaters to bytes.
+ * Convert the given characters to bytes.
+ *
+ * @param cc char input
+ * @param bc byte output
*/
public void convert(CharChunk cc, ByteChunk bc)
throws IOException {
@@ -73,10 +78,8 @@
cb.position(cc.getStart());
cb.limit(cc.getEnd());
}
- // Parse leftover if any are present
- CoderResult result = null;
// Do the decoding and get the results into the byte chunk and the char chunk
- result = encoder.encode(cb, bb, false);
+ CoderResult result = encoder.encode(cb, bb, false);
if (result.isError() || result.isMalformed()) {
result.throwException();
} else if (result.isOverflow()) {
Show replies by date