/* * Decompiled with CFR 0.152. * * Could not load the following classes: * javax.baja.log.Log */ package com.tridium.platform.daemon; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; import java.io.InterruptedIOException; import javax.baja.log.Log; /* * Illegal identifiers - consider using --renameillegalidents true */ public class ConsoleInputStream extends InputStream { public static Log log = Log.getLog((String)"platform.console"); private InputStream in; private byte[] buf; private int bufSize; private int pendingRead; private int nextRead; public static ConsoleInputStream make(InputStream inputStream) { return inputStream == null ? null : new ConsoleInputStream(inputStream); } public void close() throws IOException { this.in.close(); this.in = null; } public long skip(long l) throws IOException { if (this.in == null) { throw new IOException("skip() on closed stream"); } if (!this.checkBuffer()) { return 0L; } long l2 = this.bufSize - this.nextRead; long l3 = l <= l2 ? l : l2; this.nextRead = (int)((long)this.nextRead + l3); return l3; } public int read(byte[] byArray) throws IOException { return this.read(byArray, 0, byArray.length); } public int read(byte[] byArray, int n, int n2) throws IOException { int n3; if (this.in == null) { throw new IOException("read() on closed stream"); } if (!this.checkBuffer()) { this.throwEOFException("error in checkBuffer"); } int n4 = n2 <= (n3 = this.bufSize - this.nextRead) ? n2 : n3; System.arraycopy(this.buf, this.nextRead, byArray, n, n4); this.nextRead += n4; return n4; } public int read() throws IOException { if (this.in == null) { throw new IOException("read() on closed stream"); } if (!this.checkBuffer()) { return -1; } int n = this.buf[this.nextRead] & 0xFF; ++this.nextRead; return n; } private final void throwEOFException(String string) throws EOFException { EOFException eOFException = new EOFException(); log.trace(string, (Throwable)eOFException); throw eOFException; } /* * Unable to fully structure code */ private final boolean checkBuffer() throws IOException { if (this.in != null) ** GOTO lbl43 throw new IOException("checkBuffer() on closed stream"); lbl-1000: // 1 sources { if (this.pendingRead == 0) { var1_1 = this.in.read(); if (var1_1 == -1) { this.throwEOFException("invalid buflength byte 0"); } this.pendingRead = var1_1 << 24; try { var1_1 = this.in.read(); if (var1_1 == -1) { this.throwEOFException("invalid buflength byte 1"); } this.pendingRead += var1_1 << 16; var1_1 = this.in.read(); if (var1_1 == -1) { this.throwEOFException("invalid buflength byte 2"); } this.pendingRead += var1_1 << 8; var1_1 = this.in.read(); if (var1_1 == -1) { this.throwEOFException("invalid buflength byte 3"); } this.pendingRead += var1_1; } catch (InterruptedIOException var2_2) { this.pendingRead = 0; throw new IOException("Timeout while reading buffer size"); } } if (this.pendingRead > 1024) { this.bufSize = 0; this.nextRead = 0; this.pendingRead = 0; throw new IOException("Improper buffer size (" + this.bufSize + "), stream probably corrupt"); } if (this.pendingRead > 0) { this.bufSize = this.in.read(this.buf, 0, this.pendingRead); if (this.bufSize < 0) { this.bufSize = 0; this.nextRead = 0; return false; } this.pendingRead -= this.bufSize; this.nextRead = 0; return true; } if (this.pendingRead >= 0) continue; this.bufSize = 0; this.nextRead = 0; throw new IOException("Improper buffer size, stream probably corrupt"); lbl43: // 2 sources ** while (this.nextRead >= this.bufSize) } lbl44: // 1 sources return true; } private final /* synthetic */ void this() { this.buf = new byte[1024]; this.bufSize = 0; this.pendingRead = 0; this.nextRead = 0; } private ConsoleInputStream(InputStream inputStream) { this.this(); this.in = inputStream; } }