1 23 24 package org.enhydra.xml.xmlc.misc; 25 26 import java.io.IOException ; 27 import java.io.LineNumberReader ; 28 import java.io.Reader ; 29 30 import org.enhydra.xml.io.InputSourceOps; 31 import org.xml.sax.InputSource ; 32 33 38 public final class LineNumberMapReader extends Reader { 39 42 private InputSource fInputSource; 43 44 47 private LineNumberRecorder fLineNumbers; 48 49 52 private Reader fReader; 53 54 57 public LineNumberMapReader(InputSource inputSource) throws IOException { 58 fInputSource = inputSource; 59 fLineNumbers = new LineNumberRecorder(fInputSource.getSystemId()); 60 fReader = new LineNumberReader (InputSourceOps.open(fInputSource)); 61 } 62 63 66 public final LineNumberMap getLineNumberMap() { 67 return fLineNumbers; 68 } 69 70 76 public int read() throws IOException { 77 int ch = fReader.read(); 78 if (ch >= 0) { 79 fLineNumbers.countChar((char)ch); 80 } 81 return ch; 82 } 83 84 90 public int read(char cbuf[], int off, int len) throws IOException { 91 int num = fReader.read(cbuf, off, len); 92 if (num < 0) { 93 return num; 94 } 95 fLineNumbers.countChars(cbuf, off, len); 96 return num; 97 } 98 99 105 public void close() throws IOException { 106 fReader.close(); 107 } 108 } 109 | Popular Tags |