link start!
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.tridium.fox.message;
|
||||
|
||||
import com.tridium.fox.message.FoxTuple;
|
||||
import com.tridium.fox.message.MessageReader;
|
||||
import com.tridium.fox.message.MessageWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class FoxBlob
|
||||
extends FoxTuple {
|
||||
public byte[] data;
|
||||
public int offset;
|
||||
public int length;
|
||||
|
||||
public FoxBlob(String string, byte[] byArray, int n) {
|
||||
this.name = string;
|
||||
this.data = byArray;
|
||||
this.offset = 0;
|
||||
this.length = n;
|
||||
}
|
||||
|
||||
public FoxBlob(String string, byte[] byArray, int n, int n2) {
|
||||
this.name = string;
|
||||
this.data = byArray;
|
||||
this.offset = n;
|
||||
this.length = n2;
|
||||
}
|
||||
|
||||
public FoxBlob(String string, byte[] byArray) {
|
||||
this.name = string;
|
||||
this.data = byArray;
|
||||
this.offset = 0;
|
||||
this.length = byArray.length;
|
||||
}
|
||||
|
||||
public FoxBlob() {
|
||||
}
|
||||
|
||||
public final int getType() {
|
||||
return 98;
|
||||
}
|
||||
|
||||
protected final void writeValue(MessageWriter messageWriter) throws IOException {
|
||||
messageWriter.writeInt(this.length).write(91).write(this.data, this.offset, this.length).write(93);
|
||||
}
|
||||
|
||||
protected void readValue(MessageReader messageReader) throws IOException {
|
||||
this.length = messageReader.readInt();
|
||||
messageReader.consume(91);
|
||||
this.data = new byte[this.length];
|
||||
messageReader.readFully(this.data, 0, this.length);
|
||||
messageReader.consume(93);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.tridium.fox.message;
|
||||
|
||||
import com.tridium.fox.message.FoxTuple;
|
||||
import com.tridium.fox.message.MessageReader;
|
||||
import com.tridium.fox.message.MessageWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class FoxBoolean
|
||||
extends FoxTuple {
|
||||
public boolean value;
|
||||
|
||||
public FoxBoolean(String string, boolean bl) {
|
||||
this.name = string;
|
||||
this.value = bl;
|
||||
}
|
||||
|
||||
public FoxBoolean() {
|
||||
}
|
||||
|
||||
public final int getType() {
|
||||
return 122;
|
||||
}
|
||||
|
||||
protected final void writeValue(MessageWriter messageWriter) throws IOException {
|
||||
if (this.value) {
|
||||
messageWriter.write(116);
|
||||
} else {
|
||||
messageWriter.write(102);
|
||||
}
|
||||
}
|
||||
|
||||
protected void readValue(MessageReader messageReader) throws IOException {
|
||||
int n = messageReader.read();
|
||||
if (n == 116) {
|
||||
this.value = true;
|
||||
} else if (n == 102) {
|
||||
this.value = false;
|
||||
} else {
|
||||
throw messageReader.error("Expecting 't' or 'f', not '" + messageReader.toString(n) + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.tridium.fox.message;
|
||||
|
||||
import com.tridium.fox.message.FoxTuple;
|
||||
import com.tridium.fox.message.MessageReader;
|
||||
import com.tridium.fox.message.MessageWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class FoxFloat
|
||||
extends FoxTuple {
|
||||
public double value;
|
||||
|
||||
public FoxFloat(String string, double d) {
|
||||
this.name = string;
|
||||
this.value = d;
|
||||
}
|
||||
|
||||
public FoxFloat() {
|
||||
}
|
||||
|
||||
public final int getType() {
|
||||
return 102;
|
||||
}
|
||||
|
||||
protected final void writeValue(MessageWriter messageWriter) throws IOException {
|
||||
if (Double.isNaN(this.value)) {
|
||||
messageWriter.writeSafe("nan");
|
||||
} else if (this.value == Double.POSITIVE_INFINITY) {
|
||||
messageWriter.writeSafe("+inf");
|
||||
} else if (this.value == Double.NEGATIVE_INFINITY) {
|
||||
messageWriter.writeSafe("-inf");
|
||||
} else {
|
||||
messageWriter.writeSafe(String.valueOf(this.value));
|
||||
}
|
||||
}
|
||||
|
||||
protected void readValue(MessageReader messageReader) throws IOException {
|
||||
String string = messageReader.readSafe();
|
||||
this.value = string.equals("nan") ? Double.NaN : (string.equals("+inf") ? Double.POSITIVE_INFINITY : (string.equals("-inf") ? Double.NEGATIVE_INFINITY : Double.parseDouble(string)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.tridium.fox.message;
|
||||
|
||||
import com.tridium.fox.message.FoxTuple;
|
||||
import com.tridium.fox.message.MessageReader;
|
||||
import com.tridium.fox.message.MessageWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class FoxInteger
|
||||
extends FoxTuple {
|
||||
public int value;
|
||||
|
||||
public FoxInteger(String string, int n) {
|
||||
this.name = string;
|
||||
this.value = n;
|
||||
}
|
||||
|
||||
public FoxInteger() {
|
||||
}
|
||||
|
||||
public final int getType() {
|
||||
return 105;
|
||||
}
|
||||
|
||||
protected final void writeValue(MessageWriter messageWriter) throws IOException {
|
||||
messageWriter.writeInt(this.value);
|
||||
}
|
||||
|
||||
protected void readValue(MessageReader messageReader) throws IOException {
|
||||
this.value = messageReader.readInt();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.tridium.fox.message;
|
||||
|
||||
import com.tridium.fox.message.FoxBlob;
|
||||
import com.tridium.fox.message.FoxBoolean;
|
||||
import com.tridium.fox.message.FoxFloat;
|
||||
import com.tridium.fox.message.FoxInteger;
|
||||
import com.tridium.fox.message.FoxObject;
|
||||
import com.tridium.fox.message.FoxString;
|
||||
import com.tridium.fox.message.FoxTime;
|
||||
import com.tridium.fox.message.FoxTuple;
|
||||
import com.tridium.fox.message.MessageReader;
|
||||
import com.tridium.fox.message.MessageWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Vector;
|
||||
|
||||
public class FoxMessage
|
||||
extends FoxTuple {
|
||||
public static final FoxTuple[] noTuples = new FoxTuple[0];
|
||||
public FoxTuple[] tuples = noTuples;
|
||||
public int count;
|
||||
|
||||
public FoxMessage(String string) {
|
||||
this.name = string;
|
||||
}
|
||||
|
||||
public FoxMessage() {
|
||||
}
|
||||
|
||||
public final int getType() {
|
||||
return 109;
|
||||
}
|
||||
|
||||
public final void writeValue(MessageWriter messageWriter) throws IOException {
|
||||
boolean bl = messageWriter.isDebug;
|
||||
messageWriter.write(123).write(10);
|
||||
++messageWriter.indent;
|
||||
for (int i = 0; i < this.count; ++i) {
|
||||
if (bl) {
|
||||
messageWriter.writeIndent();
|
||||
}
|
||||
this.tuples[i].write(messageWriter);
|
||||
messageWriter.write(10);
|
||||
}
|
||||
--messageWriter.indent;
|
||||
if (bl) {
|
||||
messageWriter.writeIndent();
|
||||
}
|
||||
messageWriter.write(125);
|
||||
}
|
||||
|
||||
public void readValue(MessageReader messageReader) throws IOException {
|
||||
messageReader.consume(123);
|
||||
messageReader.consume(10);
|
||||
int n;
|
||||
while ((n = messageReader.read()) != 125) {
|
||||
messageReader.pushBack(n);
|
||||
this.add(FoxTuple.read(messageReader));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public final FoxTuple get(String string) throws IOException {
|
||||
for (int i = 0; i < this.count; ++i) {
|
||||
if (string != this.tuples[i].name) continue;
|
||||
return this.tuples[i];
|
||||
}
|
||||
throw new IOException("Missing key \"" + string + "\"");
|
||||
}
|
||||
|
||||
public final FoxTuple[] list(String string) {
|
||||
Vector<FoxTuple> vector = new Vector<FoxTuple>();
|
||||
for (int i = 0; i < this.count; ++i) {
|
||||
if (string != this.tuples[i].name) continue;
|
||||
vector.addElement(this.tuples[i]);
|
||||
}
|
||||
Object[] objectArray = new FoxTuple[vector.size()];
|
||||
vector.copyInto(objectArray);
|
||||
return objectArray;
|
||||
}
|
||||
|
||||
public final String[] listStrings(String string) {
|
||||
Vector<String> vector = new Vector<String>();
|
||||
for (int i = 0; i < this.count; ++i) {
|
||||
if (string != this.tuples[i].name) continue;
|
||||
vector.addElement(((FoxString)this.tuples[i]).value);
|
||||
}
|
||||
Object[] objectArray = new String[vector.size()];
|
||||
vector.copyInto(objectArray);
|
||||
return objectArray;
|
||||
}
|
||||
|
||||
public final FoxTuple getOptional(String string) {
|
||||
for (int i = 0; i < this.count; ++i) {
|
||||
if (string != this.tuples[i].name) continue;
|
||||
return this.tuples[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public final FoxMessage getMessage(String string) throws IOException {
|
||||
return (FoxMessage)this.get(string);
|
||||
}
|
||||
|
||||
public final boolean getBoolean(String string) throws IOException {
|
||||
return ((FoxBoolean)this.get((String)string)).value;
|
||||
}
|
||||
|
||||
public final int getInt(String string) throws IOException {
|
||||
return ((FoxInteger)this.get((String)string)).value;
|
||||
}
|
||||
|
||||
public final double getFloat(String string) throws IOException {
|
||||
return ((FoxFloat)this.get((String)string)).value;
|
||||
}
|
||||
|
||||
public final String getString(String string) throws IOException {
|
||||
return ((FoxString)this.get((String)string)).value;
|
||||
}
|
||||
|
||||
public final long getTime(String string) throws IOException {
|
||||
return ((FoxTime)this.get((String)string)).millis;
|
||||
}
|
||||
|
||||
public final byte[] getBlob(String string) throws IOException {
|
||||
return ((FoxBlob)this.get((String)string)).data;
|
||||
}
|
||||
|
||||
public final boolean getBoolean(String string, boolean bl) {
|
||||
FoxBoolean foxBoolean = (FoxBoolean)this.getOptional(string);
|
||||
if (foxBoolean == null) {
|
||||
return bl;
|
||||
}
|
||||
return foxBoolean.value;
|
||||
}
|
||||
|
||||
public final int getInt(String string, int n) {
|
||||
FoxInteger foxInteger = (FoxInteger)this.getOptional(string);
|
||||
if (foxInteger == null) {
|
||||
return n;
|
||||
}
|
||||
return foxInteger.value;
|
||||
}
|
||||
|
||||
public final double getFloat(String string, double d) {
|
||||
FoxFloat foxFloat = (FoxFloat)this.getOptional(string);
|
||||
if (foxFloat == null) {
|
||||
return d;
|
||||
}
|
||||
return foxFloat.value;
|
||||
}
|
||||
|
||||
public final String getString(String string, String string2) {
|
||||
FoxString foxString = (FoxString)this.getOptional(string);
|
||||
if (foxString == null) {
|
||||
return string2;
|
||||
}
|
||||
return foxString.value;
|
||||
}
|
||||
|
||||
public final long getTime(String string, long l) {
|
||||
FoxTime foxTime = (FoxTime)this.getOptional(string);
|
||||
if (foxTime == null) {
|
||||
return l;
|
||||
}
|
||||
return foxTime.millis;
|
||||
}
|
||||
|
||||
public final byte[] getBlob(String string, byte[] byArray) {
|
||||
FoxBlob foxBlob = (FoxBlob)this.getOptional(string);
|
||||
if (foxBlob == null) {
|
||||
return byArray;
|
||||
}
|
||||
return foxBlob.data;
|
||||
}
|
||||
|
||||
public final void add(FoxTuple foxTuple) {
|
||||
if (this.count >= this.tuples.length) {
|
||||
if (this.count == 0) {
|
||||
this.tuples = new FoxTuple[8];
|
||||
} else {
|
||||
FoxTuple[] foxTupleArray = new FoxTuple[this.count * 2];
|
||||
System.arraycopy(this.tuples, 0, foxTupleArray, 0, this.count);
|
||||
this.tuples = foxTupleArray;
|
||||
}
|
||||
}
|
||||
this.tuples[this.count++] = foxTuple;
|
||||
}
|
||||
|
||||
public final void add(String string, boolean bl) {
|
||||
this.add(new FoxBoolean(string, bl));
|
||||
}
|
||||
|
||||
public final void add(String string, int n) {
|
||||
this.add(new FoxInteger(string, n));
|
||||
}
|
||||
|
||||
public final void add(String string, double d) {
|
||||
this.add(new FoxFloat(string, d));
|
||||
}
|
||||
|
||||
public final void add(String string, String string2) {
|
||||
this.add(new FoxString(string, string2));
|
||||
}
|
||||
|
||||
public final void add(String string, long l) {
|
||||
this.add(new FoxTime(string, l));
|
||||
}
|
||||
|
||||
public final void add(String string, byte[] byArray) {
|
||||
this.add(new FoxBlob(string, byArray));
|
||||
}
|
||||
|
||||
public final void add(String string, byte[] byArray, int n) {
|
||||
this.add(new FoxBlob(string, byArray, n));
|
||||
}
|
||||
|
||||
public final void add(String string, byte[] byArray, int n, int n2) {
|
||||
this.add(new FoxBlob(string, byArray, n, n2));
|
||||
}
|
||||
|
||||
public final void add(String string, String string2, byte[] byArray, int n) {
|
||||
this.add(new FoxObject(string, string2, byArray, n));
|
||||
}
|
||||
|
||||
public final FoxMessage add(String string, FoxMessage foxMessage) {
|
||||
foxMessage.name = string;
|
||||
this.add(foxMessage);
|
||||
return foxMessage;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.tridium.fox.message;
|
||||
|
||||
import com.tridium.fox.message.FoxTuple;
|
||||
import com.tridium.fox.message.MessageReader;
|
||||
import com.tridium.fox.message.MessageWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public class FoxObject
|
||||
extends FoxTuple {
|
||||
public String encoding;
|
||||
public byte[] data;
|
||||
public int length;
|
||||
|
||||
public FoxObject(String string, String string2, byte[] byArray, int n) {
|
||||
this.name = string;
|
||||
this.encoding = string2;
|
||||
this.data = byArray;
|
||||
this.length = n;
|
||||
}
|
||||
|
||||
public FoxObject() {
|
||||
}
|
||||
|
||||
public final int getType() {
|
||||
return 111;
|
||||
}
|
||||
|
||||
protected final void writeValue(MessageWriter messageWriter) throws IOException {
|
||||
messageWriter.writeName(this.encoding).write(32).writeInt(this.length).write(91).write(this.data, 0, this.length).write(93);
|
||||
}
|
||||
|
||||
protected void readValue(MessageReader messageReader) throws IOException {
|
||||
this.encoding = messageReader.readName();
|
||||
messageReader.consume(32);
|
||||
this.length = messageReader.readInt();
|
||||
messageReader.consume(91);
|
||||
this.data = new byte[this.length];
|
||||
messageReader.readFully(this.data, 0, this.length);
|
||||
messageReader.consume(93);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.tridium.fox.message;
|
||||
|
||||
import com.tridium.fox.message.FoxTuple;
|
||||
import com.tridium.fox.message.MessageReader;
|
||||
import com.tridium.fox.message.MessageWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class FoxString
|
||||
extends FoxTuple {
|
||||
public String value;
|
||||
|
||||
public FoxString(String string, String string2) {
|
||||
this.name = string;
|
||||
this.value = string2;
|
||||
}
|
||||
|
||||
public FoxString() {
|
||||
}
|
||||
|
||||
public final int getType() {
|
||||
return 115;
|
||||
}
|
||||
|
||||
protected final void writeValue(MessageWriter messageWriter) throws IOException {
|
||||
messageWriter.writeSafe(this.value);
|
||||
}
|
||||
|
||||
protected void readValue(MessageReader messageReader) throws IOException {
|
||||
this.value = messageReader.readSafe();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.tridium.fox.message;
|
||||
|
||||
import com.tridium.fox.message.FoxTuple;
|
||||
import com.tridium.fox.message.MessageReader;
|
||||
import com.tridium.fox.message.MessageWriter;
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public final class FoxTime
|
||||
extends FoxTuple {
|
||||
private DateFormat format = new SimpleDateFormat("HH:mm:ss dd-MMM-yy");
|
||||
public long millis;
|
||||
|
||||
public FoxTime(String string, long l) {
|
||||
this.name = string;
|
||||
this.millis = l;
|
||||
}
|
||||
|
||||
public FoxTime() {
|
||||
}
|
||||
|
||||
public final int getType() {
|
||||
return 116;
|
||||
}
|
||||
|
||||
protected final void writeValue(MessageWriter messageWriter) throws IOException {
|
||||
messageWriter.writeHexLong(this.millis);
|
||||
if (messageWriter.isDebug) {
|
||||
messageWriter.writeSafe(" // ").writeSafe(this.format.format(new Date(this.millis)));
|
||||
}
|
||||
}
|
||||
|
||||
protected void readValue(MessageReader messageReader) throws IOException {
|
||||
this.millis = messageReader.readHexLong();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.tridium.fox.message;
|
||||
|
||||
import com.tridium.fox.message.FoxBlob;
|
||||
import com.tridium.fox.message.FoxBoolean;
|
||||
import com.tridium.fox.message.FoxFloat;
|
||||
import com.tridium.fox.message.FoxInteger;
|
||||
import com.tridium.fox.message.FoxMessage;
|
||||
import com.tridium.fox.message.FoxObject;
|
||||
import com.tridium.fox.message.FoxString;
|
||||
import com.tridium.fox.message.FoxTime;
|
||||
import com.tridium.fox.message.MessageReader;
|
||||
import com.tridium.fox.message.MessageWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public abstract class FoxTuple {
|
||||
public String name;
|
||||
|
||||
public abstract int getType();
|
||||
|
||||
public final void write(MessageWriter messageWriter) throws IOException {
|
||||
messageWriter.writeName(this.name).write(61).write(this.getType()).write(58);
|
||||
this.writeValue(messageWriter);
|
||||
}
|
||||
|
||||
protected abstract void writeValue(MessageWriter var1) throws IOException;
|
||||
|
||||
public static FoxTuple read(MessageReader messageReader) throws IOException {
|
||||
String string = messageReader.readName();
|
||||
messageReader.consume(61);
|
||||
int n = messageReader.read();
|
||||
FoxTuple foxTuple = null;
|
||||
switch (n) {
|
||||
case 98: {
|
||||
foxTuple = new FoxBlob();
|
||||
break;
|
||||
}
|
||||
case 102: {
|
||||
foxTuple = new FoxFloat();
|
||||
break;
|
||||
}
|
||||
case 105: {
|
||||
foxTuple = new FoxInteger();
|
||||
break;
|
||||
}
|
||||
case 109: {
|
||||
foxTuple = new FoxMessage();
|
||||
break;
|
||||
}
|
||||
case 111: {
|
||||
foxTuple = new FoxObject();
|
||||
break;
|
||||
}
|
||||
case 115: {
|
||||
foxTuple = new FoxString();
|
||||
break;
|
||||
}
|
||||
case 116: {
|
||||
foxTuple = new FoxTime();
|
||||
break;
|
||||
}
|
||||
case 122: {
|
||||
foxTuple = new FoxBoolean();
|
||||
}
|
||||
}
|
||||
messageReader.consume(58);
|
||||
foxTuple.name = string.intern();
|
||||
foxTuple.readValue(messageReader);
|
||||
messageReader.consume(10);
|
||||
return foxTuple;
|
||||
}
|
||||
|
||||
protected void readValue(MessageReader messageReader) throws IOException {
|
||||
throw messageReader.error("not implemented");
|
||||
}
|
||||
|
||||
public void dump(OutputStream outputStream) {
|
||||
try {
|
||||
MessageWriter messageWriter = new MessageWriter(outputStream, true);
|
||||
this.write(messageWriter);
|
||||
messageWriter.flush();
|
||||
}
|
||||
catch (IOException iOException) {
|
||||
iOException.printStackTrace();
|
||||
throw new RuntimeException(iOException.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void dump() {
|
||||
this.dump(System.out);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,320 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.tridium.fox.message;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class MessageReader {
|
||||
private static final int CM_NAME = 1;
|
||||
private static final int CM_DIGIT = 2;
|
||||
private static final int CM_HEX = 4;
|
||||
private static byte[] charMap;
|
||||
private static final int HISTORY_SIZE = 160;
|
||||
private InputStream in;
|
||||
private int pushBack = -1;
|
||||
private byte[] history = new byte[160];
|
||||
private int historyIndex = -1;
|
||||
|
||||
public MessageReader(InputStream inputStream) {
|
||||
this.in = inputStream;
|
||||
}
|
||||
|
||||
public final int read() throws IOException {
|
||||
if (this.pushBack != -1) {
|
||||
int n = this.pushBack;
|
||||
this.pushBack = -1;
|
||||
return n;
|
||||
}
|
||||
int n = this.in.read();
|
||||
if (n < 0) {
|
||||
throw new EOFException("EOF");
|
||||
}
|
||||
this.historyIndex = (this.historyIndex + 1) % 160;
|
||||
this.history[this.historyIndex] = (byte)n;
|
||||
return n;
|
||||
}
|
||||
|
||||
public final void readFully(byte[] byArray, int n, int n2) throws IOException {
|
||||
int n3;
|
||||
for (int i = 0; i < n2; i += n3) {
|
||||
n3 = this.in.read(byArray, n + i, n2 - i);
|
||||
if (n3 >= 0) continue;
|
||||
throw this.error("EOF");
|
||||
}
|
||||
this.historyIndex = (this.historyIndex + 1) % 160;
|
||||
this.history[this.historyIndex] = 98;
|
||||
this.historyIndex = (this.historyIndex + 1) % 160;
|
||||
this.history[this.historyIndex] = 108;
|
||||
this.historyIndex = (this.historyIndex + 1) % 160;
|
||||
this.history[this.historyIndex] = 111;
|
||||
this.historyIndex = (this.historyIndex + 1) % 160;
|
||||
this.history[this.historyIndex] = 98;
|
||||
}
|
||||
|
||||
public final void pushBack(int n) {
|
||||
if (this.pushBack != -1) {
|
||||
throw new IllegalStateException("Double push back");
|
||||
}
|
||||
this.pushBack = n;
|
||||
}
|
||||
|
||||
public final String readName() throws IOException {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
while (true) {
|
||||
int n;
|
||||
if ((charMap[n = this.read()] & 1) == 0) {
|
||||
if (stringBuffer.length() == 0) {
|
||||
throw this.error("Expected name");
|
||||
}
|
||||
this.pushBack(n);
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
stringBuffer.append((char)n);
|
||||
}
|
||||
}
|
||||
|
||||
public final String readTo(char c) throws IOException {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
while (true) {
|
||||
int n;
|
||||
if ((n = this.read()) == c) {
|
||||
this.pushBack(n);
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
stringBuffer.append((char)n);
|
||||
}
|
||||
}
|
||||
|
||||
public final int readInt() throws IOException {
|
||||
int n = 0;
|
||||
boolean bl = false;
|
||||
int n2 = this.read();
|
||||
if ((charMap[n2] & 2) != 0) {
|
||||
n = n2 - 48;
|
||||
} else if (n2 == 45) {
|
||||
bl = true;
|
||||
} else {
|
||||
throw this.error("Expecting int");
|
||||
}
|
||||
while (true) {
|
||||
if ((charMap[n2 = this.read()] & 2) == 0) break;
|
||||
n = n * 10 + (n2 - 48);
|
||||
}
|
||||
this.pushBack(n2);
|
||||
if (bl) {
|
||||
n = -n;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
public final long readLong() throws IOException {
|
||||
long l = 0L;
|
||||
boolean bl = false;
|
||||
int n = this.read();
|
||||
if ((charMap[n] & 2) != 0) {
|
||||
l = n - 48;
|
||||
} else if (n == 45) {
|
||||
bl = true;
|
||||
} else {
|
||||
throw this.error("Expecting int");
|
||||
}
|
||||
while (true) {
|
||||
if ((charMap[n = this.read()] & 2) == 0) break;
|
||||
l = l * 10L + (long)(n - 48);
|
||||
}
|
||||
this.pushBack(n);
|
||||
if (bl) {
|
||||
l = -l;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
public final int readHex() throws IOException {
|
||||
int n;
|
||||
int n2 = 0;
|
||||
while (true) {
|
||||
if ((charMap[n = this.read()] & 4) == 0) break;
|
||||
if ((charMap[n] & 2) != 0) {
|
||||
n2 = (n2 << 4) + (n - 48);
|
||||
continue;
|
||||
}
|
||||
n2 = (n2 << 4) + 10 + (n - 97);
|
||||
}
|
||||
this.pushBack(n);
|
||||
return n2;
|
||||
}
|
||||
|
||||
public final long readHexLong() throws IOException {
|
||||
int n;
|
||||
long l = 0L;
|
||||
while (true) {
|
||||
if ((charMap[n = this.read()] & 4) == 0) break;
|
||||
if ((charMap[n] & 2) != 0) {
|
||||
l = (l << 4) + (long)(n - 48);
|
||||
continue;
|
||||
}
|
||||
l = (l << 4) + 10L + (long)(n - 97);
|
||||
}
|
||||
this.pushBack(n);
|
||||
return l;
|
||||
}
|
||||
|
||||
public final String readSafe() throws IOException {
|
||||
int n;
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
while (true) {
|
||||
if ((n = this.read()) < 32) break;
|
||||
if (n == 35) {
|
||||
int n2;
|
||||
if (stringBuffer.length() == 0) {
|
||||
n2 = this.read();
|
||||
if (n2 == 110) {
|
||||
this.consume(117);
|
||||
this.consume(108);
|
||||
this.consume(108);
|
||||
this.consume(59);
|
||||
return null;
|
||||
}
|
||||
this.pushBack(n2);
|
||||
}
|
||||
n2 = this.readHex();
|
||||
this.consume(59);
|
||||
stringBuffer.append((char)n2);
|
||||
continue;
|
||||
}
|
||||
stringBuffer.append((char)n);
|
||||
}
|
||||
this.pushBack(n);
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
public final void consume(String string) throws IOException {
|
||||
int n = string.length();
|
||||
for (int i = 0; i < n; ++i) {
|
||||
this.consume(string.charAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
public final void consume(int n) throws IOException {
|
||||
int n2 = this.read();
|
||||
if (n2 == -1) {
|
||||
throw new EOFException();
|
||||
}
|
||||
if (n2 != n) {
|
||||
throw this.error("Expected '" + this.toString(n) + "', got '" + this.toString(n2) + "'");
|
||||
}
|
||||
}
|
||||
|
||||
public final void close() throws IOException {
|
||||
this.in.close();
|
||||
}
|
||||
|
||||
public IOException error(String string) {
|
||||
System.out.println("ERROR: MessageReader: " + string);
|
||||
Thread.dumpStack();
|
||||
byte[] byArray = this.getHistory();
|
||||
System.out.println("--- History ---");
|
||||
MessageReader.hexDump(byArray);
|
||||
byte[] byArray2 = this.getFuture();
|
||||
if (byArray2.length > 0) {
|
||||
System.out.println("--- Future ---");
|
||||
MessageReader.hexDump(byArray2);
|
||||
}
|
||||
return new IOException(string);
|
||||
}
|
||||
|
||||
public static void hexDump(byte[] byArray) {
|
||||
for (int i = 0; i < byArray.length; i += 16) {
|
||||
StringBuffer stringBuffer = new StringBuffer(64);
|
||||
StringBuffer stringBuffer2 = new StringBuffer(64);
|
||||
for (int j = 0; j < 16 && i + j < byArray.length; ++j) {
|
||||
int n = byArray[i + j] & 0xFF;
|
||||
if (j % 4 == 0) {
|
||||
stringBuffer.append(' ');
|
||||
}
|
||||
if (n < 16) {
|
||||
stringBuffer.append('0');
|
||||
}
|
||||
stringBuffer.append(Integer.toHexString(n));
|
||||
if (n < 32 || n > 127) {
|
||||
stringBuffer2.append('.');
|
||||
continue;
|
||||
}
|
||||
stringBuffer2.append((char)n);
|
||||
}
|
||||
System.out.print(stringBuffer);
|
||||
System.out.print(" ");
|
||||
System.out.print(stringBuffer2);
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getHistory() {
|
||||
int n;
|
||||
byte[] byArray = new byte[160];
|
||||
int n2 = this.historyIndex + 1;
|
||||
int n3 = 160 - n2;
|
||||
for (n = 0; n < n3; ++n) {
|
||||
byArray[n] = this.history[n + n2];
|
||||
}
|
||||
for (n = 0; n < n2; ++n) {
|
||||
byArray[n + n3] = this.history[n];
|
||||
}
|
||||
return byArray;
|
||||
}
|
||||
|
||||
public byte[] getFuture() {
|
||||
try {
|
||||
int n = this.in.available();
|
||||
int n2 = Math.min(n, 160);
|
||||
if (n2 > 0) {
|
||||
byte[] byArray = new byte[n2];
|
||||
for (int i = 0; i < byArray.length; ++i) {
|
||||
byArray[i] = (byte)this.read();
|
||||
}
|
||||
return byArray;
|
||||
}
|
||||
}
|
||||
catch (IOException iOException) {
|
||||
// empty catch block
|
||||
}
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
public String toString(int n) {
|
||||
if (n == 10) {
|
||||
return "\\n";
|
||||
}
|
||||
if (n < 32 || n > 126) {
|
||||
return "0x" + Integer.toHexString(n);
|
||||
}
|
||||
return String.valueOf((char)n);
|
||||
}
|
||||
|
||||
static {
|
||||
int n;
|
||||
charMap = new byte[256];
|
||||
for (n = 97; n <= 122; ++n) {
|
||||
MessageReader.charMap[n] = 1;
|
||||
}
|
||||
for (n = 65; n <= 90; ++n) {
|
||||
MessageReader.charMap[n] = 1;
|
||||
}
|
||||
for (n = 48; n <= 57; ++n) {
|
||||
MessageReader.charMap[n] = 7;
|
||||
}
|
||||
n = 97;
|
||||
while (n <= 102) {
|
||||
int n2 = n++;
|
||||
charMap[n2] = (byte)(charMap[n2] | 4);
|
||||
}
|
||||
MessageReader.charMap[46] = 1;
|
||||
MessageReader.charMap[45] = 1;
|
||||
MessageReader.charMap[95] = 1;
|
||||
MessageReader.charMap[36] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.tridium.fox.message;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class MessageWriter {
|
||||
public int indent = 0;
|
||||
public boolean isDebug;
|
||||
private OutputStream out;
|
||||
|
||||
public MessageWriter(OutputStream outputStream, boolean bl) {
|
||||
this.out = outputStream;
|
||||
this.isDebug = bl;
|
||||
}
|
||||
|
||||
public MessageWriter(OutputStream outputStream) {
|
||||
this.out = outputStream;
|
||||
}
|
||||
|
||||
public final MessageWriter write(int n) throws IOException {
|
||||
this.out.write(n);
|
||||
return this;
|
||||
}
|
||||
|
||||
public final MessageWriter write(byte[] byArray, int n, int n2) throws IOException {
|
||||
if (this.isDebug) {
|
||||
this.writeDebug(byArray, n, n2);
|
||||
} else {
|
||||
this.out.write(byArray, n, n2);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public final MessageWriter write(byte[] byArray) throws IOException {
|
||||
if (this.isDebug) {
|
||||
this.writeDebug(byArray, 0, byArray.length);
|
||||
} else {
|
||||
this.out.write(byArray, 0, byArray.length);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private void writeDebug(byte[] byArray, int n, int n2) throws IOException {
|
||||
int n3 = Math.min(n2, 30);
|
||||
for (int i = 0; i < n3; ++i) {
|
||||
int n4 = byArray[i];
|
||||
if (n4 == 10) {
|
||||
this.write(92).write(110);
|
||||
continue;
|
||||
}
|
||||
if (n4 < 32 || n4 > 127) {
|
||||
n4 = 63;
|
||||
}
|
||||
this.write(n4);
|
||||
}
|
||||
if (n3 < n2) {
|
||||
this.write(46).write(46).write(46);
|
||||
}
|
||||
}
|
||||
|
||||
public final void writeIndent() throws IOException {
|
||||
for (int i = 0; i < this.indent; ++i) {
|
||||
this.out.write(32);
|
||||
}
|
||||
}
|
||||
|
||||
public final MessageWriter writeName(String string) throws IOException {
|
||||
try {
|
||||
int n = string.length();
|
||||
for (int i = 0; i < n; ++i) {
|
||||
this.out.write(string.charAt(i));
|
||||
}
|
||||
}
|
||||
catch (NullPointerException nullPointerException) {
|
||||
this.write(110).write(117).write(108).write(108);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public final MessageWriter writeInt(int n) throws IOException {
|
||||
return this.writeName(Integer.toString(n));
|
||||
}
|
||||
|
||||
public final MessageWriter writeLong(long l) throws IOException {
|
||||
return this.writeName(Long.toString(l));
|
||||
}
|
||||
|
||||
public final MessageWriter writeHex(int n) throws IOException {
|
||||
return this.writeName(Integer.toHexString(n));
|
||||
}
|
||||
|
||||
public final MessageWriter writeHexLong(long l) throws IOException {
|
||||
return this.writeName(Long.toHexString(l));
|
||||
}
|
||||
|
||||
public final MessageWriter writeSafe(String string) throws IOException {
|
||||
if (string == null) {
|
||||
this.writeName("#null;");
|
||||
return this;
|
||||
}
|
||||
int n = string.length();
|
||||
for (int i = 0; i < n; ++i) {
|
||||
char c = string.charAt(i);
|
||||
if (c < ' ' || c > '\u007f' || c == '#') {
|
||||
this.write(35).writeHex(c).write(59);
|
||||
continue;
|
||||
}
|
||||
this.write(c);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public final void flush() throws IOException {
|
||||
this.out.flush();
|
||||
}
|
||||
|
||||
public final void close() throws IOException {
|
||||
this.out.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user