home *** CD-ROM | disk | FTP | other *** search
- package sun.rmi.transport.proxy;
-
- import java.io.DataInputStream;
- import java.io.EOFException;
- import java.io.FilterInputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.rmi.server.LogStream;
-
- class HttpInputStream extends FilterInputStream {
- protected int bytesLeft;
- protected int bytesLeftAtMark;
-
- public HttpInputStream(InputStream var1) throws IOException {
- super(var1);
- if (var1.markSupported()) {
- var1.mark(0);
- }
-
- DataInputStream var2 = new DataInputStream(var1);
- String var3 = "Content-length:".toLowerCase();
- boolean var4 = false;
-
- String var5;
- do {
- var5 = var2.readLine();
- if (RMIMasterSocketFactory.logLevel >= 20) {
- LogStream.log("proxy").println("HttpInputStream.<init>: received header line: \"" + var5 + "\"");
- }
-
- if (var5 == null) {
- throw new EOFException();
- }
-
- if (var5.toLowerCase().startsWith(var3)) {
- this.bytesLeft = Integer.parseInt(var5.substring(var3.length()).trim());
- var4 = true;
- }
- } while(var5.length() != 0 && var5.charAt(0) != '\r' && var5.charAt(0) != '\n');
-
- if (!var4 || this.bytesLeft < 0) {
- this.bytesLeft = Integer.MAX_VALUE;
- }
-
- this.bytesLeftAtMark = this.bytesLeft;
- if (RMIMasterSocketFactory.logLevel >= 10) {
- LogStream.log("proxy").println("HttpInputStream.<init>: content length: " + this.bytesLeft);
- }
-
- }
-
- public int available() throws IOException {
- int var1 = super.in.available();
- if (var1 > this.bytesLeft) {
- var1 = this.bytesLeft;
- }
-
- return var1;
- }
-
- public int read() throws IOException {
- if (this.bytesLeft > 0) {
- int var1 = super.in.read();
- if (var1 != -1) {
- --this.bytesLeft;
- }
-
- if (RMIMasterSocketFactory.logLevel >= 20) {
- LogStream.log("proxy").println("HttpInputStream.read: received byte: '" + ((var1 & 127) < 32 ? " " : String.valueOf((char)var1)) + "' " + var1);
- }
-
- return var1;
- } else {
- if (RMIMasterSocketFactory.logLevel >= 20) {
- LogStream.log("proxy").println("HttpInputStream.read: read past content length");
- }
-
- return -1;
- }
- }
-
- public int read(byte[] var1, int var2, int var3) throws IOException {
- if (this.bytesLeft == 0 && var3 > 0) {
- if (RMIMasterSocketFactory.logLevel >= 20) {
- LogStream.log("proxy").println("HttpInputStream.read: read past content length");
- }
-
- return -1;
- } else {
- if (var3 > this.bytesLeft) {
- var3 = this.bytesLeft;
- }
-
- int var4 = super.in.read(var1, var2, var3);
- this.bytesLeft -= var4;
- if (RMIMasterSocketFactory.logLevel >= 20) {
- LogStream.log("proxy").println("HttpInputStream.read: read " + var4 + " bytes, " + this.bytesLeft + " remaining");
- }
-
- return var4;
- }
- }
-
- public void mark(int var1) {
- super.in.mark(var1);
- if (super.in.markSupported()) {
- this.bytesLeftAtMark = this.bytesLeft;
- }
-
- }
-
- public void reset() throws IOException {
- super.in.reset();
- this.bytesLeft = this.bytesLeftAtMark;
- }
-
- public long skip(long var1) throws IOException {
- if (var1 > (long)this.bytesLeft) {
- var1 = (long)this.bytesLeft;
- }
-
- long var3 = super.in.skip(var1);
- this.bytesLeft = (int)((long)this.bytesLeft - var3);
- return var3;
- }
- }
-