home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML Construction Kit / Dynamic HTML Construction Kit.iso / earthlink / nscomm / java40.jar / java / io / LineNumberInputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-03  |  1.1 KB  |  92 lines

  1. package java.io;
  2.  
  3. public class LineNumberInputStream extends FilterInputStream {
  4.    int pushBack = -1;
  5.    int lineNumber;
  6.    int markLineNumber;
  7.  
  8.    public LineNumberInputStream(InputStream var1) {
  9.       super(var1);
  10.    }
  11.  
  12.    public int read() throws IOException {
  13.       int var1 = this.pushBack;
  14.       if (var1 != -1) {
  15.          this.pushBack = -1;
  16.       } else {
  17.          var1 = super.in.read();
  18.       }
  19.  
  20.       switch (var1) {
  21.          case 11:
  22.          case 12:
  23.          default:
  24.             return var1;
  25.          case 13:
  26.             this.pushBack = super.in.read();
  27.             if (this.pushBack == 10) {
  28.                this.pushBack = -1;
  29.             }
  30.          case 10:
  31.             ++this.lineNumber;
  32.             return 10;
  33.       }
  34.    }
  35.  
  36.    public int read(byte[] var1, int var2, int var3) throws IOException {
  37.       if (var3 <= 0) {
  38.          return 0;
  39.       } else {
  40.          int var4 = this.read();
  41.          if (var4 == -1) {
  42.             return -1;
  43.          } else {
  44.             var1[var2] = (byte)var4;
  45.             int var5 = 1;
  46.  
  47.             try {
  48.                for(; var5 < var3; ++var5) {
  49.                   var4 = this.read();
  50.                   if (var4 == -1) {
  51.                      break;
  52.                   }
  53.  
  54.                   if (var1 != null) {
  55.                      var1[var2 + var5] = (byte)var4;
  56.                   }
  57.                }
  58.             } catch (IOException var6) {
  59.             }
  60.  
  61.             return var5;
  62.          }
  63.       }
  64.    }
  65.  
  66.    public void setLineNumber(int var1) {
  67.       this.lineNumber = var1;
  68.    }
  69.  
  70.    public int getLineNumber() {
  71.       return this.lineNumber;
  72.    }
  73.  
  74.    public long skip(long var1) throws IOException {
  75.       return (long)((FilterInputStream)this).read(new byte[(int)var1]);
  76.    }
  77.  
  78.    public int available() throws IOException {
  79.       return this.pushBack == -1 ? super.available() : super.available() + 1;
  80.    }
  81.  
  82.    public void mark(int var1) {
  83.       this.markLineNumber = this.lineNumber;
  84.       super.in.mark(var1);
  85.    }
  86.  
  87.    public void reset() throws IOException {
  88.       this.lineNumber = this.markLineNumber;
  89.       super.in.reset();
  90.    }
  91. }
  92.