117 lines
3.3 KiB
Java
117 lines
3.3 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* com.tridium.fox.message.FoxMessage
|
|
* com.tridium.fox.session.FoxCircuit
|
|
* javax.baja.sys.BajaRuntimeException
|
|
*/
|
|
package com.tridium.platform.fox;
|
|
|
|
import com.tridium.fox.message.FoxMessage;
|
|
import com.tridium.fox.session.FoxCircuit;
|
|
import com.tridium.platform.fox.MessageClient;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import javax.baja.sys.BajaRuntimeException;
|
|
|
|
/*
|
|
* Illegal identifiers - consider using --renameillegalidents true
|
|
*/
|
|
public class ChunkedInputStream
|
|
extends InputStream {
|
|
private FoxCircuit circuit;
|
|
private byte[] chunk;
|
|
private int nextRead;
|
|
private MessageClient[] messageClients;
|
|
|
|
public int read() throws IOException {
|
|
int n = this.available();
|
|
if (n <= 0) {
|
|
return -1;
|
|
}
|
|
byte by = this.chunk[this.nextRead];
|
|
++this.nextRead;
|
|
return by;
|
|
}
|
|
|
|
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 = this.available();
|
|
if (n3 <= 0) {
|
|
return -1;
|
|
}
|
|
int n4 = n2 > n3 ? n3 : n2;
|
|
System.arraycopy(this.chunk, this.nextRead, byArray, n, n4);
|
|
this.nextRead += n4;
|
|
return n4;
|
|
}
|
|
|
|
public int available() throws IOException {
|
|
try {
|
|
if (this.chunk == null || this.nextRead >= this.chunk.length) {
|
|
boolean bl = true;
|
|
FoxMessage foxMessage = null;
|
|
block4: while (bl) {
|
|
bl = false;
|
|
foxMessage = this.circuit.readMessage();
|
|
int n = 0;
|
|
while (n < this.messageClients.length) {
|
|
if (this.messageClients[n].handleMessage(foxMessage)) {
|
|
bl = true;
|
|
continue block4;
|
|
}
|
|
++n;
|
|
}
|
|
}
|
|
this.chunk = foxMessage.getBlob("chunk");
|
|
this.nextRead = 0;
|
|
}
|
|
return this.chunk.length - this.nextRead;
|
|
}
|
|
catch (IOException iOException) {
|
|
throw iOException;
|
|
}
|
|
catch (RuntimeException runtimeException) {
|
|
throw runtimeException;
|
|
}
|
|
catch (Exception exception) {
|
|
throw new BajaRuntimeException((Throwable)exception);
|
|
}
|
|
}
|
|
|
|
public void close() throws IOException {
|
|
try {
|
|
this.circuit.writeMessage(new FoxMessage());
|
|
}
|
|
catch (IOException iOException) {
|
|
throw iOException;
|
|
}
|
|
catch (RuntimeException runtimeException) {
|
|
throw runtimeException;
|
|
}
|
|
catch (Exception exception) {
|
|
throw new BajaRuntimeException((Throwable)exception);
|
|
}
|
|
}
|
|
|
|
private final /* synthetic */ void this() {
|
|
this.chunk = null;
|
|
this.nextRead = -1;
|
|
}
|
|
|
|
public ChunkedInputStream(FoxCircuit foxCircuit) {
|
|
this(foxCircuit, new MessageClient[0]);
|
|
}
|
|
|
|
public ChunkedInputStream(FoxCircuit foxCircuit, MessageClient[] messageClientArray) {
|
|
this.this();
|
|
this.circuit = foxCircuit;
|
|
this.messageClients = messageClientArray;
|
|
}
|
|
}
|
|
|