home *** CD-ROM | disk | FTP | other *** search
- package sun.rmi.transport.tcp;
-
- import java.io.DataInputStream;
- import java.io.IOException;
- import java.io.InputStream;
-
- final class MultiplexInputStream extends InputStream {
- private ConnectionMultiplexer manager;
- private MultiplexConnectionInfo info;
- private byte[] buffer;
- private int present;
- private int pos;
- private int requested;
- private boolean disconnected = false;
- private Object lock = new Object();
- private int waterMark;
- private byte[] temp = new byte[1];
-
- MultiplexInputStream(ConnectionMultiplexer var1, MultiplexConnectionInfo var2, int var3) {
- this.manager = var1;
- this.info = var2;
- this.buffer = new byte[var3];
- this.waterMark = var3 / 2;
- }
-
- public synchronized int read() throws IOException {
- int var1 = this.read(this.temp, 0, 1);
- return var1 != 1 ? -1 : this.temp[0] & 255;
- }
-
- public synchronized int read(byte[] var1, int var2, int var3) throws IOException {
- if (var3 <= 0) {
- return 0;
- } else {
- Object var5 = this.lock;
- synchronized(var5){}
-
- int var4;
- try {
- if (this.pos >= this.present) {
- this.pos = this.present = 0;
- } else if (this.pos >= this.waterMark) {
- System.arraycopy(this.buffer, this.pos, this.buffer, 0, this.waterMark);
- this.present -= this.waterMark;
- this.pos -= this.waterMark;
- }
-
- int var7 = this.buffer.length - this.present;
- var4 = Math.max(var7 - this.requested, 0);
- } catch (Throwable var16) {
- throw var16;
- }
-
- if (var4 > 0) {
- this.manager.sendRequest(this.info, var4);
- }
-
- Object var6 = this.lock;
- synchronized(var6){}
-
- try {
- this.requested += var4;
-
- while(this.pos >= this.present && !this.disconnected) {
- try {
- this.lock.wait();
- } catch (InterruptedException var15) {
- }
- }
-
- if (this.disconnected && this.pos >= this.present) {
- byte var20 = -1;
- return var20;
- }
-
- int var8 = this.present - this.pos;
- if (var3 >= var8) {
- System.arraycopy(this.buffer, this.pos, var1, var2, var8);
- this.pos = this.present = 0;
- int var19 = var8;
- return var19;
- }
-
- System.arraycopy(this.buffer, this.pos, var1, var2, var3);
- this.pos += var3;
- var18 = var3;
- } catch (Throwable var17) {
- throw var17;
- }
-
- return var18;
- }
- }
-
- public int available() throws IOException {
- Object var2 = this.lock;
- synchronized(var2){}
-
- int var1;
- try {
- var1 = this.present - this.pos;
- } catch (Throwable var5) {
- throw var5;
- }
-
- return var1;
- }
-
- public void close() throws IOException {
- this.manager.sendClose(this.info);
- }
-
- void receive(int var1, DataInputStream var2) throws IOException {
- Object var3 = this.lock;
- synchronized(var3){}
-
- try {
- if (this.pos > 0 && this.buffer.length - this.present < var1) {
- System.arraycopy(this.buffer, this.pos, this.buffer, 0, this.present - this.pos);
- this.present -= this.pos;
- this.pos = 0;
- }
-
- if (this.buffer.length - this.present < var1) {
- throw new IOException("Receive buffer overflow");
- }
-
- var2.readFully(this.buffer, this.present, var1);
- this.present += var1;
- this.requested -= var1;
- this.lock.notifyAll();
- } catch (Throwable var5) {
- throw var5;
- }
-
- }
-
- void disconnect() {
- Object var1 = this.lock;
- synchronized(var1){}
-
- try {
- this.disconnected = true;
- this.lock.notifyAll();
- } catch (Throwable var3) {
- throw var3;
- }
-
- }
- }
-