1 18 19 package org.objectweb.jac.aspects.gui; 20 21 import java.io.*; 22 import java.util.Map ; 23 24 30 31 public class TemplateReader extends Reader { 32 33 Map params; 34 StringBuffer buffer; 35 Reader in; 36 37 38 int delim_char = '%'; 39 40 public TemplateReader(Reader in, Map params) 41 { 42 this.in = in; 43 this.params = params; 44 this.buffer = new StringBuffer (); 45 } 46 47 public int read(char[] b, int off, int len) throws IOException 48 { 49 50 int i; 51 int ok = 0; 52 while (len-- > 0) { 53 i = read(); 54 if (i == -1) return (ok == 0) ? -1 : ok; 55 b[off++] = (char) i; 56 ok++; 57 } 58 return ok; 59 } 60 61 62 public int read() throws IOException 63 { 64 if (buffer.length()==0) { 65 int b = in.read(); 66 if (b != -1) { 67 if (b == delim_char) { 68 StringWriter param = new StringWriter(); 69 b = in.read(); 70 if (b != delim_char) { 71 while(b!=delim_char && b!=-1) { 72 param.write(b); 73 b = in.read(); 74 } 75 buffer.append(params.get(param.toString())); 76 b = buffer.charAt(0); 77 buffer.deleteCharAt(0); 78 } 79 } 80 } 81 return b; 82 } else { 83 int b = buffer.charAt(0); 84 buffer.deleteCharAt(0); 85 return b; 86 } 87 } 88 89 public void close() throws IOException 90 { 91 in.close(); 92 } 93 } 94 | Popular Tags |