home *** CD-ROM | disk | FTP | other *** search
- package java.io;
-
- public class PipedInputStream extends InputStream {
- boolean closed = true;
- boolean closedByReader = false;
- boolean connected = false;
- Thread readSide;
- Thread writeSide;
- protected static final int PIPE_SIZE = 1024;
- protected byte[] buffer = new byte[1024];
- // $FF: renamed from: in int
- protected int field_0 = -1;
- protected int out;
-
- public PipedInputStream(PipedOutputStream var1) throws IOException {
- this.connect(var1);
- }
-
- public PipedInputStream() {
- }
-
- public void connect(PipedOutputStream var1) throws IOException {
- if (this.connected) {
- throw new IOException("Pipe already connected");
- } else {
- var1.connect(this);
- this.connected = true;
- }
- }
-
- protected synchronized void receive(int var1) throws IOException {
- this.writeSide = Thread.currentThread();
-
- while(this.field_0 == this.out) {
- if (this.readSide != null && !this.readSide.isAlive()) {
- throw new IOException("Pipe broken");
- }
-
- this.notifyAll();
-
- try {
- this.wait(1000L);
- } catch (InterruptedException var2) {
- throw new InterruptedIOException();
- }
- }
-
- if (this.field_0 < 0) {
- this.field_0 = 0;
- this.out = 0;
- }
-
- this.buffer[this.field_0++] = (byte)(var1 & 255);
- if (this.field_0 >= this.buffer.length) {
- this.field_0 = 0;
- }
-
- }
-
- synchronized void receive(byte[] var1, int var2, int var3) throws IOException {
- while(true) {
- --var3;
- if (var3 < 0) {
- return;
- }
-
- this.receive(var1[var2++]);
- }
- }
-
- synchronized void receivedLast() {
- this.closed = true;
- this.notifyAll();
- }
-
- public synchronized int read() throws IOException {
- if (this.closedByReader) {
- throw new IOException("InputStream closed");
- } else {
- int var1 = 2;
-
- while(this.field_0 < 0) {
- this.readSide = Thread.currentThread();
- if (this.closed) {
- return -1;
- }
-
- if (this.writeSide != null && !this.writeSide.isAlive()) {
- --var1;
- if (var1 < 0) {
- throw new IOException("Pipe broken");
- }
- }
-
- this.notifyAll();
-
- try {
- this.wait(1000L);
- } catch (InterruptedException var3) {
- throw new InterruptedIOException();
- }
- }
-
- int var2 = this.buffer[this.out++] & 255;
- if (this.out >= this.buffer.length) {
- this.out = 0;
- }
-
- if (this.field_0 == this.out) {
- this.field_0 = -1;
- }
-
- return var2;
- }
- }
-
- public synchronized int read(byte[] var1, int var2, int var3) throws IOException {
- if (var1 == null) {
- throw new NullPointerException();
- } else if (var2 >= 0 && var3 >= 0 && var2 + var3 <= var1.length) {
- if (var3 == 0) {
- return 0;
- } else {
- int var4 = this.read();
- if (var4 < 0) {
- return -1;
- } else {
- var1[var2] = (byte)var4;
- int var5 = 1;
-
- while(this.field_0 >= 0) {
- --var3;
- if (var3 <= 0) {
- break;
- }
-
- var1[var2 + var5] = this.buffer[this.out++];
- ++var5;
- if (this.out >= this.buffer.length) {
- this.out = 0;
- }
-
- if (this.field_0 == this.out) {
- this.field_0 = -1;
- }
- }
-
- return var5;
- }
- }
- } else {
- throw new ArrayIndexOutOfBoundsException();
- }
- }
-
- public synchronized int available() throws IOException {
- if (this.field_0 < 0) {
- return 0;
- } else if (this.field_0 == this.out) {
- return this.buffer.length;
- } else {
- return this.field_0 > this.out ? this.field_0 - this.out : this.field_0 + this.buffer.length - this.out;
- }
- }
-
- public void close() throws IOException {
- this.field_0 = -1;
- this.closedByReader = true;
- }
- }
-