1 54 55 68 package org.wings.template.parser; 69 70 import java.io.IOException ; 71 import java.io.Reader ; 72 73 80 public class PositionReader 81 extends Reader { 82 83 private Reader reader = null; 84 private long position; 85 private long savePosition = -1; 86 87 public PositionReader(Reader r) { 88 this.reader = r; 89 position = 0; 90 } 91 92 93 public long getPosition() { 94 return position; 95 } 96 97 98 99 public int read() 100 throws IOException { 101 int c = reader.read(); 102 if (c != -1) position++; 103 return c; 104 } 105 106 public int read(char cbuff[]) 107 throws IOException { 108 int num = reader.read(cbuff); 109 if (num > 0) position += num; 110 return num; 111 } 112 113 public int read(char cbuff[], int off, int len) 114 throws IOException { 115 int num = reader.read(cbuff, off, len); 116 if (num > 0) position += num; 117 return num; 118 } 119 120 public long skip(long n) 121 throws IOException { 122 long skipped = reader.skip(n); 123 position += skipped; 124 return skipped; 125 } 126 127 public boolean ready() 128 throws IOException { 129 return reader.ready(); 130 } 131 132 public boolean markSupported() { 133 return reader.markSupported(); 134 } 135 136 public void mark(int readAheadLimit) 137 throws IOException { 138 savePosition = position; 139 reader.mark(readAheadLimit); 140 } 141 142 public void reset() 143 throws IOException { 144 reader.reset(); 145 if (savePosition < 0) 147 throw new IOException ("mark() not set before"); 148 position = savePosition; 149 } 150 151 public void close() 152 throws IOException { 153 reader.close(); 154 } 155 } 156 157 158 | Popular Tags |