home *** CD-ROM | disk | FTP | other *** search
- package java.io;
-
- public class LineNumberInputStream extends FilterInputStream {
- int pushBack = -1;
- int lineNumber;
- int markLineNumber;
-
- public LineNumberInputStream(InputStream in) {
- super(in);
- }
-
- public int read() throws IOException {
- int c = this.pushBack;
- if (c != -1) {
- this.pushBack = -1;
- } else {
- c = super.in.read();
- }
-
- switch (c) {
- case 13:
- this.pushBack = super.in.read();
- if (this.pushBack == 10) {
- this.pushBack = -1;
- }
- case 10:
- ++this.lineNumber;
- return 10;
- default:
- return c;
- }
- }
-
- public int read(byte[] b, int off, int len) throws IOException {
- if (len <= 0) {
- return 0;
- } else {
- int c = this.read();
- if (c == -1) {
- return -1;
- } else {
- b[off] = (byte)c;
- int i = 1;
-
- try {
- for(; i < len; ++i) {
- c = this.read();
- if (c == -1) {
- break;
- }
-
- if (b != null) {
- b[off + i] = (byte)c;
- }
- }
- } catch (IOException var6) {
- }
-
- return i;
- }
- }
- }
-
- public void setLineNumber(int lineNumber) {
- this.lineNumber = lineNumber;
- }
-
- public int getLineNumber() {
- return this.lineNumber;
- }
-
- public long skip(long n) throws IOException {
- return (long)((FilterInputStream)this).read(new byte[(int)n]);
- }
-
- public int available() throws IOException {
- return this.pushBack == -1 ? super.available() : super.available() + 1;
- }
-
- public void mark(int readlimit) {
- this.markLineNumber = this.lineNumber;
- super.in.mark(readlimit);
- }
-
- public void reset() throws IOException {
- this.lineNumber = this.markLineNumber;
- super.in.reset();
- }
- }
-