You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by at...@apache.org on 2008/10/24 01:12:47 UTC
svn commit: r707494 -
/portals/pluto/branches/2.0-spi-refactoring/pluto-container/src/main/java/org/apache/pluto/util/PrintWriterServletOutputStream.java
Author: ate
Date: Thu Oct 23 16:12:46 2008
New Revision: 707494
URL: http://svn.apache.org/viewvc?rev=707494&view=rev
Log:
Bringing back character encoding support on the PrintWriterServletOutputStream.
That was provided by Pluto 1.0.1 and somehow got "lost" afterwards.
Modified:
portals/pluto/branches/2.0-spi-refactoring/pluto-container/src/main/java/org/apache/pluto/util/PrintWriterServletOutputStream.java
Modified: portals/pluto/branches/2.0-spi-refactoring/pluto-container/src/main/java/org/apache/pluto/util/PrintWriterServletOutputStream.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-container/src/main/java/org/apache/pluto/util/PrintWriterServletOutputStream.java?rev=707494&r1=707493&r2=707494&view=diff
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-container/src/main/java/org/apache/pluto/util/PrintWriterServletOutputStream.java (original)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-container/src/main/java/org/apache/pluto/util/PrintWriterServletOutputStream.java Thu Oct 23 16:12:46 2008
@@ -18,6 +18,7 @@
import java.io.IOException;
import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
import javax.servlet.ServletOutputStream;
@@ -35,26 +36,35 @@
PrintWriter mPrintWriter;
/**
+ * The character encoding of the response.
+ */
+ private String characterEncoding;
+
+ /**
* Construct a ServletOutputStream that coordinates output using a base
* ServletOutputStream and a PrintWriter that is wrapped on top of that
* OutputStream.
+ * @deprecated use {@link PrintWriterServletOutputStream(PrintWriter,String)}
*/
public PrintWriterServletOutputStream(PrintWriter pO) {
super();
mPrintWriter = pO;
}
+ public PrintWriterServletOutputStream(PrintWriter pw, String encoding)
+ {
+ super();
+ mPrintWriter = pw;
+ characterEncoding = encoding;
+ }
+
/**
* Writes an array of bytes
* @param pBuf the array to be written
* @throws IOException if an I/O error occurred
*/
public void write(byte[] pBuf) throws IOException {
- char[] cbuf = new char[pBuf.length];
- for (int i = 0; i < cbuf.length; i++) {
- cbuf[i] = (char) (pBuf[i] & 0xff);
- }
- mPrintWriter.write(cbuf, 0, pBuf.length);
+ this.write(pBuf, 0, pBuf.length);
}
/**
@@ -73,11 +83,21 @@
*/
public void write(byte[] pBuf, int pOffset, int pLength)
throws IOException {
- char[] cbuf = new char[pLength];
- for (int i = 0; i < pLength; i++) {
- cbuf[i] = (char) (pBuf[i + pOffset] & 0xff);
+ String strValue = null;
+ if(characterEncoding != null && !"".equals(characterEncoding)) {
+ try {
+ strValue = new String(pBuf, pOffset, pLength, characterEncoding);
+ }
+ catch(UnsupportedEncodingException uee) {
+ // ignore and allow the null to handle.
+ }
+ }
+
+ if(strValue == null) {
+ strValue = new String(pBuf, pOffset, pLength);
}
- mPrintWriter.write(cbuf, 0, pLength);
+
+ mPrintWriter.write(strValue);
}
/**