1 19 20 21 package org.apache.slide.webdav.logger; 22 23 import java.io.IOException ; 24 25 import javax.servlet.ServletOutputStream ; 26 27 import org.apache.slide.common.Domain; 28 29 32 public class XServletOutputStreamFacade extends ServletOutputStream { 33 34 35 public static final String DEFAULT_CHAR_ENCODING = "8859_1"; 36 public static final byte[] bCRLF = (System.getProperty("line.separator")).getBytes(); 37 38 ServletOutputStream prStream; 39 XByteBuffer bb; 41 42 48 String enc; 49 50 protected XServletOutputStreamFacade( ServletOutputStream soStream, String enc) { 51 Domain.debug("Create XServletOutputStreamFacade"); 52 this.prStream = soStream; 59 bb = new XByteBuffer(); 60 } 61 62 64 public void write(int i) throws IOException { 65 Domain.debug("XServletOutputStreamFacade:write(int)"); 66 bb.write(i); 67 prStream.write(i); 68 } 69 70 public void write(byte[] b) throws IOException { 71 Domain.debug("XServletOutputStreamFacade:write(byte[])"); 72 write(b,0,b.length); 73 } 74 75 public void write(byte[] b, int off, int len) throws IOException { 76 Domain.debug("XServletOutputStreamFacade:write(byte[] b, int off, int len)"); 77 bb.write( b, off, len ); 78 prStream.write(b, off, len); 79 } 80 81 83 92 public void print(String s) throws IOException { 93 Domain.debug("XServletOutputStreamFacade:print(" + s + " )"); 94 if (s==null) { 95 s="null"; 96 } 97 byte b[]=null; 98 if( enc==null) { 99 b=s.getBytes(); 100 } else { 101 try { 102 b=s.getBytes( enc ); 103 } catch (java.io.UnsupportedEncodingException ex) { 104 b=s.getBytes(); 105 enc=null; 106 } 107 } 108 write( b ); 109 prStream.print( s ); 110 } 111 112 public void println() throws IOException { 113 Domain.debug("XServletOutputStreamFacade:println()"); 114 write(bCRLF); 115 prStream.println(); 116 } 117 118 public void println(String s) throws IOException { 119 Domain.debug("XServletOutputStreamFacade:println(" + s + " )"); 120 if (s==null) { 121 s="null"; 122 } 123 byte b[]=null; 124 if( enc==null) { 125 b=s.getBytes(); 126 } else { 127 try { 128 b=s.getBytes( enc ); 129 } catch (java.io.UnsupportedEncodingException ex) { 130 b=s.getBytes(); 131 enc=null; 132 } 133 } 134 write(b); 135 write(bCRLF); 136 prStream.println(s); 137 } 138 139 141 public void flush() throws IOException { 142 Domain.debug("XServletOutputStreamFacade:flush()"); 143 prStream.flush(); 144 } 145 146 public void close() throws IOException { 147 Domain.debug("XServletOutputStreamFacade:close()"); 148 prStream.close(); 149 } 150 151 156 public String getOutputBuffer() throws IOException { 157 return bb.getBufferContent(); 158 } 159 160 161 } 162 163 | Popular Tags |