1 17 18 22 package org.apache.geronimo.system.configuration; 23 24 import java.io.ByteArrayOutputStream ; 25 import java.io.IOException ; 26 import java.io.OutputStreamWriter ; 27 import java.io.Writer ; 28 29 34 public class SieveEncodingInfo extends EncodingInfo { 35 36 BAOutputStream checkerStream = null; 37 Writer checkerWriter = null; 38 String dangerChars = null; 39 40 45 public SieveEncodingInfo(String mimeName, String javaName, 46 int lastPrintable, String dangers) { 47 super(mimeName, javaName, lastPrintable); 48 this.dangerChars = dangers; 49 } 50 51 54 public SieveEncodingInfo(String mimeName, int lastPrintable) { 55 this(mimeName, mimeName, lastPrintable, null); 56 } 57 58 63 public boolean isPrintable(int ch) { 64 if (this.dangerChars != null && ch <= 0xffff) { 65 69 if (this.dangerChars.indexOf(ch) >= 0) 70 return false; 71 } 72 73 if (ch <= this.lastPrintable) 74 return true; 75 76 boolean printable = true; 77 synchronized (this) { 78 try { 79 if (this.checkerWriter == null) { 80 this.checkerStream = new BAOutputStream(10); 81 this.checkerWriter = new OutputStreamWriter (this.checkerStream, this.javaName); 82 } 83 84 if (ch > 0xffff) { 85 this.checkerWriter.write(((ch-0x10000)>>10)+0xd800); 86 this.checkerWriter.write(((ch-0x10000)&0x3ff)+0xdc00); 87 byte[] result = this.checkerStream.getBuffer(); 88 if (this.checkerStream.size() == 2 && result[0] == '?' && result[1] == '?') 89 printable = false; 90 } else { 91 this.checkerWriter.write(ch); 92 this.checkerWriter.flush(); 93 byte[] result = this.checkerStream.getBuffer(); 94 if (this.checkerStream.size() == 1 && result[0] == '?') 95 printable = false; 96 } 97 this.checkerStream.reset(); 98 } catch (IOException ioe) { 99 printable = false; 100 } 101 } 102 103 return printable; 104 } 105 106 111 static class BAOutputStream extends ByteArrayOutputStream { 112 BAOutputStream() { 113 super(); 114 } 115 116 BAOutputStream(int size) { 117 super(size); 118 } 119 120 byte[] getBuffer() { 121 return this.buf; 122 } 123 } 124 125 } 126 | Popular Tags |