1 28 29 package com.caucho.xml.readers; 30 31 import com.caucho.util.CharBuffer; 32 import com.caucho.vfs.ReadStream; 33 import com.caucho.xml.XmlParser; 34 35 import java.io.IOException ; 36 37 40 public class MacroReader extends XmlReader { 41 char []_buffer = new char[256]; 42 int _offset; 43 int _length; 44 45 48 public MacroReader() 49 { 50 } 51 52 public void init(XmlParser parser, XmlReader next) 53 { 54 _parser = parser; 55 _next = next; 56 _offset = 0; 57 _length = 0; 58 } 59 60 public ReadStream getReadStream() 61 { 62 return _next.getReadStream(); 63 } 64 65 public String getSystemId() 66 { 67 if (_next != null) 68 return _next.getSystemId(); 69 else 70 return super.getSystemId(); 71 } 72 73 public String getPublicId() 74 { 75 if (_next != null) 76 return _next.getPublicId(); 77 else 78 return super.getPublicId(); 79 } 80 81 public String getFilename() 82 { 83 if (_next != null) 84 return _next.getFilename(); 85 else 86 return super.getFilename(); 87 } 88 89 public int getLine() 90 { 91 if (_next != null) 92 return _next.getLine(); 93 else 94 return super.getLine(); 95 } 96 97 100 public void add(String s) 101 { 102 int len = s.length(); 103 104 for (int i = 0; i < len; i++) 105 add(s.charAt(i)); 106 } 107 108 111 public void add(CharBuffer cb) 112 { 113 int len = cb.length(); 114 115 for (int i = 0; i < len; i++) 116 add(cb.charAt(i)); 117 } 118 119 122 public void add(char ch) 123 { 124 if (_offset == _length) { 125 _offset = 0; 126 _length = 0; 127 } 128 129 if (_buffer.length == _length) { 130 char []newBuffer = new char[2 * _buffer.length]; 131 System.arraycopy(_buffer, 0, newBuffer, 0, _length); 132 _buffer = newBuffer; 133 } 134 135 _buffer[_length++] = ch; 136 } 137 138 public void prepend(char ch) 139 { 140 if (_offset == _length) { 141 _offset = 0; 142 _length = 0; 143 } 144 145 if (_buffer.length == _length) { 146 char []newBuffer = new char[2 * _buffer.length]; 147 System.arraycopy(_buffer, 0, newBuffer, 0, _length); 148 _buffer = newBuffer; 149 } 150 151 for (int i = _length; i >= 0; i--) 152 _buffer[i + 1] = _buffer[i]; 153 154 _length++; 155 _buffer[0] = ch; 156 } 157 158 161 public int read() 162 throws IOException 163 { 164 if (_offset < _length) 165 return _buffer[_offset++]; 166 else 167 return _next.read(); 168 } 169 } 170 171 | Popular Tags |