home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VPage / Java.bin / CLASSES.ZIP / sun / rmi / transport / proxy / HttpInputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-07-08  |  2.8 KB  |  127 lines

  1. package sun.rmi.transport.proxy;
  2.  
  3. import java.io.DataInputStream;
  4. import java.io.EOFException;
  5. import java.io.FilterInputStream;
  6. import java.io.IOException;
  7. import java.io.InputStream;
  8. import java.rmi.server.LogStream;
  9.  
  10. class HttpInputStream extends FilterInputStream {
  11.    protected int bytesLeft;
  12.    protected int bytesLeftAtMark;
  13.  
  14.    public HttpInputStream(InputStream var1) throws IOException {
  15.       super(var1);
  16.       if (var1.markSupported()) {
  17.          var1.mark(0);
  18.       }
  19.  
  20.       DataInputStream var2 = new DataInputStream(var1);
  21.       String var3 = "Content-length:".toLowerCase();
  22.       boolean var4 = false;
  23.  
  24.       String var5;
  25.       do {
  26.          var5 = var2.readLine();
  27.          if (RMIMasterSocketFactory.logLevel >= 20) {
  28.             LogStream.log("proxy").println("HttpInputStream.<init>: received header line: \"" + var5 + "\"");
  29.          }
  30.  
  31.          if (var5 == null) {
  32.             throw new EOFException();
  33.          }
  34.  
  35.          if (var5.toLowerCase().startsWith(var3)) {
  36.             this.bytesLeft = Integer.parseInt(var5.substring(var3.length()).trim());
  37.             var4 = true;
  38.          }
  39.       } while(var5.length() != 0 && var5.charAt(0) != '\r' && var5.charAt(0) != '\n');
  40.  
  41.       if (!var4 || this.bytesLeft < 0) {
  42.          this.bytesLeft = Integer.MAX_VALUE;
  43.       }
  44.  
  45.       this.bytesLeftAtMark = this.bytesLeft;
  46.       if (RMIMasterSocketFactory.logLevel >= 10) {
  47.          LogStream.log("proxy").println("HttpInputStream.<init>: content length: " + this.bytesLeft);
  48.       }
  49.  
  50.    }
  51.  
  52.    public int available() throws IOException {
  53.       int var1 = super.in.available();
  54.       if (var1 > this.bytesLeft) {
  55.          var1 = this.bytesLeft;
  56.       }
  57.  
  58.       return var1;
  59.    }
  60.  
  61.    public int read() throws IOException {
  62.       if (this.bytesLeft > 0) {
  63.          int var1 = super.in.read();
  64.          if (var1 != -1) {
  65.             --this.bytesLeft;
  66.          }
  67.  
  68.          if (RMIMasterSocketFactory.logLevel >= 20) {
  69.             LogStream.log("proxy").println("HttpInputStream.read: received byte: '" + ((var1 & 127) < 32 ? " " : String.valueOf((char)var1)) + "' " + var1);
  70.          }
  71.  
  72.          return var1;
  73.       } else {
  74.          if (RMIMasterSocketFactory.logLevel >= 20) {
  75.             LogStream.log("proxy").println("HttpInputStream.read: read past content length");
  76.          }
  77.  
  78.          return -1;
  79.       }
  80.    }
  81.  
  82.    public int read(byte[] var1, int var2, int var3) throws IOException {
  83.       if (this.bytesLeft == 0 && var3 > 0) {
  84.          if (RMIMasterSocketFactory.logLevel >= 20) {
  85.             LogStream.log("proxy").println("HttpInputStream.read: read past content length");
  86.          }
  87.  
  88.          return -1;
  89.       } else {
  90.          if (var3 > this.bytesLeft) {
  91.             var3 = this.bytesLeft;
  92.          }
  93.  
  94.          int var4 = super.in.read(var1, var2, var3);
  95.          this.bytesLeft -= var4;
  96.          if (RMIMasterSocketFactory.logLevel >= 20) {
  97.             LogStream.log("proxy").println("HttpInputStream.read: read " + var4 + " bytes, " + this.bytesLeft + " remaining");
  98.          }
  99.  
  100.          return var4;
  101.       }
  102.    }
  103.  
  104.    public void mark(int var1) {
  105.       super.in.mark(var1);
  106.       if (super.in.markSupported()) {
  107.          this.bytesLeftAtMark = this.bytesLeft;
  108.       }
  109.  
  110.    }
  111.  
  112.    public void reset() throws IOException {
  113.       super.in.reset();
  114.       this.bytesLeft = this.bytesLeftAtMark;
  115.    }
  116.  
  117.    public long skip(long var1) throws IOException {
  118.       if (var1 > (long)this.bytesLeft) {
  119.          var1 = (long)this.bytesLeft;
  120.       }
  121.  
  122.       long var3 = super.in.skip(var1);
  123.       this.bytesLeft = (int)((long)this.bytesLeft - var3);
  124.       return var3;
  125.    }
  126. }
  127.