home *** CD-ROM | disk | FTP | other *** search
- package java.io;
-
- public class PipedInputStream extends InputStream {
- boolean closed = true;
- Thread readSide;
- Thread writeSide;
- private byte[] buffer = new byte[1024];
- // $FF: renamed from: in int
- int field_0 = -1;
- int out;
-
- public PipedInputStream(PipedOutputStream src) throws IOException {
- this.connect(src);
- }
-
- public PipedInputStream() {
- }
-
- public void connect(PipedOutputStream src) throws IOException {
- src.connect(this);
- }
-
- synchronized void receive(int b) 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)(b & 255);
- if (this.field_0 >= this.buffer.length) {
- this.field_0 = 0;
- }
-
- }
-
- synchronized void receive(byte[] b, int off, int len) throws IOException {
- while(true) {
- --len;
- if (len < 0) {
- return;
- }
-
- this.receive(b[off++]);
- }
- }
-
- synchronized void receivedLast() {
- this.closed = true;
- this.notifyAll();
- }
-
- public synchronized int read() throws IOException {
- int trials = 2;
-
- while(this.field_0 < 0) {
- this.readSide = Thread.currentThread();
- if (this.writeSide != null && !this.writeSide.isAlive()) {
- --trials;
- if (trials < 0) {
- throw new IOException("Pipe broken");
- }
- }
-
- if (this.closed) {
- return -1;
- }
-
- this.notifyAll();
-
- try {
- this.wait(1000L);
- } catch (InterruptedException var3) {
- throw new InterruptedIOException();
- }
- }
-
- int ret = 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 ret;
- }
-
- public synchronized int read(byte[] b, int off, int len) throws IOException {
- if (len <= 0) {
- return 0;
- } else {
- int c = this.read();
- if (c < 0) {
- return -1;
- } else {
- b[off] = (byte)c;
- int rlen = 1;
-
- while(this.field_0 >= 0) {
- --len;
- if (len <= 0) {
- break;
- }
-
- b[off + rlen] = this.buffer[this.out++];
- ++rlen;
- if (this.out >= this.buffer.length) {
- this.out = 0;
- }
-
- if (this.field_0 == this.out) {
- this.field_0 = -1;
- }
- }
-
- return rlen;
- }
- }
- }
-
- public void close() throws IOException {
- this.field_0 = -1;
- this.closed = true;
- }
- }
-