home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 June / CHIPHEFT062001.ISO / browser / nc32lyc / comm.z / java40.jar / java / io / LineNumberInputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-08-15  |  1.4 KB  |  90 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 13:
  22.             this.pushBack = super.in.read();
  23.             if (this.pushBack == 10) {
  24.                this.pushBack = -1;
  25.             }
  26.          case 10:
  27.             ++this.lineNumber;
  28.             return 10;
  29.          default:
  30.             return var1;
  31.       }
  32.    }
  33.  
  34.    public int read(byte[] var1, int var2, int var3) throws IOException {
  35.       if (var3 <= 0) {
  36.          return 0;
  37.       } else {
  38.          int var4 = this.read();
  39.          if (var4 == -1) {
  40.             return -1;
  41.          } else {
  42.             var1[var2] = (byte)var4;
  43.             int var5 = 1;
  44.  
  45.             try {
  46.                for(; var5 < var3; ++var5) {
  47.                   var4 = this.read();
  48.                   if (var4 == -1) {
  49.                      break;
  50.                   }
  51.  
  52.                   if (var1 != null) {
  53.                      var1[var2 + var5] = (byte)var4;
  54.                   }
  55.                }
  56.             } catch (IOException var6) {
  57.             }
  58.  
  59.             return var5;
  60.          }
  61.       }
  62.    }
  63.  
  64.    public void setLineNumber(int var1) {
  65.       this.lineNumber = var1;
  66.    }
  67.  
  68.    public int getLineNumber() {
  69.       return this.lineNumber;
  70.    }
  71.  
  72.    public long skip(long var1) throws IOException {
  73.       return (long)((FilterInputStream)this).read(new byte[(int)var1]);
  74.    }
  75.  
  76.    public int available() throws IOException {
  77.       return this.pushBack == -1 ? super.available() : super.available() + 1;
  78.    }
  79.  
  80.    public void mark(int var1) {
  81.       this.markLineNumber = this.lineNumber;
  82.       super.in.mark(var1);
  83.    }
  84.  
  85.    public void reset() throws IOException {
  86.       this.lineNumber = this.markLineNumber;
  87.       super.in.reset();
  88.    }
  89. }
  90.