1 2 17 20 21 package org.apache.pluto.util; 22 23 import java.io.IOException ; 24 import java.io.PrintWriter ; 25 import java.io.UnsupportedEncodingException ; 26 27 import javax.servlet.ServletOutputStream ; 28 29 35 public class PrintWriterServletOutputStream extends ServletOutputStream 36 { 37 38 41 PrintWriter mPrintWriter; 42 43 46 private String characterEncoding; 47 48 56 public PrintWriterServletOutputStream(PrintWriter pO) 57 { 58 this(pO, null); 59 } 60 61 public PrintWriterServletOutputStream(PrintWriter pw, String encoding) 62 { 63 super(); 64 mPrintWriter = pw; 65 characterEncoding = encoding; 66 } 67 68 69 74 public void write(int pVal) throws IOException 75 { 76 mPrintWriter.write(pVal); 77 } 78 79 85 public void write(byte[] pBuf) throws IOException 86 { 87 this.write(pBuf, 0, pBuf.length); 88 } 89 90 100 public void write(byte[] pBuf, int pOffset, int pLength) throws IOException 101 { 102 String strValue = null; 103 if(characterEncoding != null && !"".equals(characterEncoding)) { 104 try { 105 strValue = new String (pBuf, pOffset, pLength, characterEncoding); 106 } 107 catch(UnsupportedEncodingException uee) { 108 } 110 } 111 112 if(strValue == null) { 113 strValue = new String (pBuf, pOffset, pLength); 114 } 115 116 mPrintWriter.write(strValue); 117 } 118 119 124 public void flush() throws IOException 125 { 126 mPrintWriter.flush(); 127 } 128 129 134 public void close() throws IOException 135 { 136 mPrintWriter.close(); 137 } 138 139 146 public void print(String pVal) throws IOException 147 { 148 mPrintWriter.print(pVal); 149 } 150 151 158 public void println(String pVal) throws IOException 159 { 160 mPrintWriter.println(pVal); 161 } 162 163 170 public void println() throws IOException 171 { 172 mPrintWriter.println(); 173 } 174 175 } 176 | Popular Tags |