You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2012/01/10 22:01:32 UTC
svn commit: r1229729 - in /tomcat/trunk/java/org/apache/tomcat/util/buf:
C2BConverter.java LocalStrings.properties
Author: markt
Date: Tue Jan 10 21:01:32 2012
New Revision: 1229729
URL: http://svn.apache.org/viewvc?rev=1229729&view=rev
Log:
Improve logging
Modified:
tomcat/trunk/java/org/apache/tomcat/util/buf/C2BConverter.java
tomcat/trunk/java/org/apache/tomcat/util/buf/LocalStrings.properties
Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/C2BConverter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/C2BConverter.java?rev=1229729&r1=1229728&r2=1229729&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/buf/C2BConverter.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/buf/C2BConverter.java Tue Jan 10 21:01:32 2012
@@ -22,6 +22,10 @@ import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.util.res.StringManager;
+
/**
* Efficient conversion of character to bytes.
*
@@ -31,9 +35,14 @@ import java.nio.charset.Charset;
*/
public final class C2BConverter {
- private final BufferedWriter writer;
- private final WriteConvertor conv;
- private final IntermediateOutputStream ios;
+ private static final Log log = LogFactory.getLog(C2BConverter.class);
+ private static final StringManager sm =
+ StringManager.getManager(Constants.Package);
+
+ private final String encoding;
+ private BufferedWriter writer;
+ private WriteConvertor conv;
+ private IntermediateOutputStream ios;
private final ByteChunk bb;
/**
@@ -41,9 +50,8 @@ public final class C2BConverter {
*/
public C2BConverter(ByteChunk output, String encoding) throws IOException {
this.bb = output;
- ios = new IntermediateOutputStream(output);
- conv = new WriteConvertor(ios, B2CConverter.getCharset(encoding));
- writer = new BufferedWriter(conv);
+ this.encoding = encoding;
+ init();
}
/**
@@ -57,14 +65,25 @@ public final class C2BConverter {
try {
writer.flush();
} catch (IOException e) {
- // TODO Better logging
- e.printStackTrace();
+ log.warn(sm.getString("c2bConverter.recycleFailed"), e);
+ try {
+ init();
+ } catch (IOException ignore) {
+ // Should never happen since this means encoding is invalid and
+ // in that case, the constructor will have failed.
+ }
}
// Re-enable ready for re-use
ios.enable();
bb.recycle();
}
+ private void init() throws IOException {
+ ios = new IntermediateOutputStream(bb);
+ conv = new WriteConvertor(ios, B2CConverter.getCharset(encoding));
+ writer = new BufferedWriter(conv);
+ }
+
/**
* Generate the bytes using the specified encoding.
*/
Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/LocalStrings.properties?rev=1229729&r1=1229728&r2=1229729&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/buf/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/buf/LocalStrings.properties Tue Jan 10 21:01:32 2012
@@ -14,3 +14,4 @@
# limitations under the License.
b2cConvertor.unknownEncoding=The character encoding [{0}] is not supported
+c2bConverter.recycleFailed=Failed to recycle the C2B Converter. Creating new BufferedWriter, WriteConvertor and IntermediateOutputStream.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org