1 package com.quadcap.app.bugdb; 2 3 40 41 import java.io.IOException ; 42 import java.io.Writer ; 43 44 50 public class HtmlWriter extends Writer { 51 Writer os; 52 static final char[] ampLT = { 53 '&', 'l', 't', ';' 54 }; 55 static final char[] ampGT = { 56 '&', 'g', 't', ';' 57 }; 58 static final char[] ampAMP = { 59 '&', 'a', 'm', 'p', ';' 60 }; 61 62 67 public HtmlWriter(Writer os) { 68 this.os = os; 69 } 70 71 77 public void write(int c) throws IOException { 78 switch (c) { 79 case '<': 80 os.write(ampLT); 81 break; 82 case '>': 83 os.write(ampGT); 84 break; 85 case '&': 86 os.write(ampAMP); 87 break; 88 default: 89 os.write(c); 90 } 91 } 92 93 102 public void write(char cbuf[], int offset, int len) throws IOException { 103 int lim = offset + len; 104 while (offset < lim) write(cbuf[offset++]); 105 } 106 107 112 public void flush() throws IOException { 113 os.flush(); 114 } 115 116 121 public void close() throws IOException { 122 os.close(); 123 } 124 } 125 | Popular Tags |