1 17 18 package org.apache.jasper.xmlparser; 19 20 import java.io.InputStream ; 21 import java.io.IOException ; 22 import java.io.Reader ; 23 import org.apache.jasper.compiler.Localizer; 24 25 33 public class ASCIIReader 34 extends Reader { 35 36 40 41 public static final int DEFAULT_BUFFER_SIZE = 2048; 42 43 47 48 protected InputStream fInputStream; 49 50 51 protected byte[] fBuffer; 52 53 57 64 public ASCIIReader(InputStream inputStream, int size) { 65 fInputStream = inputStream; 66 fBuffer = new byte[size]; 67 } 68 69 73 86 public int read() throws IOException { 87 int b0 = fInputStream.read(); 88 if (b0 > 0x80) { 89 throw new IOException (Localizer.getMessage("jsp.error.xml.invalidASCII", 90 Integer.toString(b0))); 91 } 92 return b0; 93 } 95 109 public int read(char ch[], int offset, int length) throws IOException { 110 if (length > fBuffer.length) { 111 length = fBuffer.length; 112 } 113 int count = fInputStream.read(fBuffer, 0, length); 114 for (int i = 0; i < count; i++) { 115 int b0 = fBuffer[i]; 116 if (b0 > 0x80) { 117 throw new IOException (Localizer.getMessage("jsp.error.xml.invalidASCII", 118 Integer.toString(b0))); 119 } 120 ch[offset + i] = (char)b0; 121 } 122 return count; 123 } 125 135 public long skip(long n) throws IOException { 136 return fInputStream.skip(n); 137 } 139 148 public boolean ready() throws IOException { 149 return false; 150 } 152 155 public boolean markSupported() { 156 return fInputStream.markSupported(); 157 } 159 172 public void mark(int readAheadLimit) throws IOException { 173 fInputStream.mark(readAheadLimit); 174 } 176 189 public void reset() throws IOException { 190 fInputStream.reset(); 191 } 193 200 public void close() throws IOException { 201 fInputStream.close(); 202 } 204 } | Popular Tags |