Initial commit
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package com.thoughtworks.xstream.io.binary;
|
||||
|
||||
import com.thoughtworks.xstream.io.AbstractDriver;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BinaryStreamDriver extends AbstractDriver {
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamDriver
|
||||
public HierarchicalStreamReader createReader(Reader reader) {
|
||||
throw new UnsupportedOperationException("The BinaryDriver cannot use character-oriented input streams.");
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamDriver
|
||||
public HierarchicalStreamWriter createWriter(Writer writer) {
|
||||
throw new UnsupportedOperationException("The BinaryDriver cannot use character-oriented output streams.");
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamDriver
|
||||
public HierarchicalStreamReader createReader(InputStream inputStream) {
|
||||
return new BinaryStreamReader(inputStream);
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamDriver
|
||||
public HierarchicalStreamWriter createWriter(OutputStream outputStream) {
|
||||
return new BinaryStreamWriter(outputStream);
|
||||
}
|
||||
}
|
@@ -0,0 +1,207 @@
|
||||
package com.thoughtworks.xstream.io.binary;
|
||||
|
||||
import com.thoughtworks.xstream.converters.ErrorWriter;
|
||||
import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamReader;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
|
||||
import com.thoughtworks.xstream.io.StreamException;
|
||||
import com.thoughtworks.xstream.io.binary.Token;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BinaryStreamReader implements ExtendedHierarchicalStreamReader {
|
||||
private final DataInputStream in;
|
||||
private Token pushback;
|
||||
private final ReaderDepthState depthState = new ReaderDepthState();
|
||||
private final IdRegistry idRegistry = new IdRegistry();
|
||||
private final Token.Formatter tokenFormatter = new Token.Formatter();
|
||||
|
||||
private static class IdRegistry {
|
||||
private Map map;
|
||||
|
||||
private IdRegistry() {
|
||||
this.map = new HashMap();
|
||||
}
|
||||
|
||||
public String get(long j) {
|
||||
String str = (String) this.map.get(new Long(j));
|
||||
if (str != null) {
|
||||
return str;
|
||||
}
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append("Unknown ID : ");
|
||||
stringBuffer.append(j);
|
||||
throw new StreamException(stringBuffer.toString());
|
||||
}
|
||||
|
||||
public void put(long j, String str) {
|
||||
this.map.put(new Long(j), str);
|
||||
}
|
||||
}
|
||||
|
||||
public BinaryStreamReader(InputStream inputStream) {
|
||||
this.in = new DataInputStream(inputStream);
|
||||
moveDown();
|
||||
}
|
||||
|
||||
private Token readToken() {
|
||||
Token token = this.pushback;
|
||||
if (token != null) {
|
||||
this.pushback = null;
|
||||
return token;
|
||||
}
|
||||
try {
|
||||
Token read = this.tokenFormatter.read(this.in);
|
||||
if (read.getType() != 2) {
|
||||
return read;
|
||||
}
|
||||
this.idRegistry.put(read.getId(), read.getValue());
|
||||
return readToken();
|
||||
} catch (IOException e) {
|
||||
throw new StreamException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamReader, com.thoughtworks.xstream.converters.ErrorReporter
|
||||
public void appendErrors(ErrorWriter errorWriter) {
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamReader
|
||||
public void close() {
|
||||
try {
|
||||
this.in.close();
|
||||
} catch (IOException e) {
|
||||
throw new StreamException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamReader
|
||||
public String getAttribute(String str) {
|
||||
return this.depthState.getAttribute(str);
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamReader
|
||||
public int getAttributeCount() {
|
||||
return this.depthState.getAttributeCount();
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamReader
|
||||
public String getAttributeName(int i) {
|
||||
return this.depthState.getAttributeName(i);
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamReader
|
||||
public Iterator getAttributeNames() {
|
||||
return this.depthState.getAttributeNames();
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamReader
|
||||
public String getNodeName() {
|
||||
return this.depthState.getName();
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamReader
|
||||
public String getValue() {
|
||||
return this.depthState.getValue();
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamReader
|
||||
public boolean hasMoreChildren() {
|
||||
return this.depthState.hasMoreChildren();
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamReader
|
||||
public void moveDown() {
|
||||
this.depthState.push();
|
||||
Token readToken = readToken();
|
||||
if (readToken.getType() != 3) {
|
||||
throw new StreamException("Expected StartNode");
|
||||
}
|
||||
this.depthState.setName(this.idRegistry.get(readToken.getId()));
|
||||
while (true) {
|
||||
Token readToken2 = readToken();
|
||||
byte type = readToken2.getType();
|
||||
if (type == 3) {
|
||||
this.depthState.setHasMoreChildren(true);
|
||||
pushBack(readToken2);
|
||||
return;
|
||||
}
|
||||
if (type == 4) {
|
||||
this.depthState.setHasMoreChildren(false);
|
||||
pushBack(readToken2);
|
||||
return;
|
||||
} else if (type == 5) {
|
||||
this.depthState.addAttribute(this.idRegistry.get(readToken2.getId()), readToken2.getValue());
|
||||
} else {
|
||||
if (type != 6) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append("Unexpected token ");
|
||||
stringBuffer.append(readToken2);
|
||||
throw new StreamException(stringBuffer.toString());
|
||||
}
|
||||
this.depthState.setValue(readToken2.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamReader
|
||||
public void moveUp() {
|
||||
this.depthState.pop();
|
||||
int i = 0;
|
||||
while (true) {
|
||||
byte type = readToken().getType();
|
||||
if (type == 3) {
|
||||
i++;
|
||||
} else if (type != 4) {
|
||||
continue;
|
||||
} else if (i == 0) {
|
||||
break;
|
||||
} else {
|
||||
i--;
|
||||
}
|
||||
}
|
||||
Token readToken = readToken();
|
||||
byte type2 = readToken.getType();
|
||||
if (type2 == 3) {
|
||||
this.depthState.setHasMoreChildren(true);
|
||||
} else {
|
||||
if (type2 != 4) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append("Unexpected token ");
|
||||
stringBuffer.append(readToken);
|
||||
throw new StreamException(stringBuffer.toString());
|
||||
}
|
||||
this.depthState.setHasMoreChildren(false);
|
||||
}
|
||||
pushBack(readToken);
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.ExtendedHierarchicalStreamReader
|
||||
public String peekNextChild() {
|
||||
if (this.depthState.hasMoreChildren()) {
|
||||
return this.idRegistry.get(this.pushback.getId());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void pushBack(Token token) {
|
||||
if (this.pushback != null) {
|
||||
throw new Error("Cannot push more than one token back");
|
||||
}
|
||||
this.pushback = token;
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamReader
|
||||
public HierarchicalStreamReader underlyingReader() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamReader
|
||||
public String getAttribute(int i) {
|
||||
return this.depthState.getAttribute(i);
|
||||
}
|
||||
}
|
@@ -0,0 +1,101 @@
|
||||
package com.thoughtworks.xstream.io.binary;
|
||||
|
||||
import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriter;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||
import com.thoughtworks.xstream.io.StreamException;
|
||||
import com.thoughtworks.xstream.io.binary.Token;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class BinaryStreamWriter implements ExtendedHierarchicalStreamWriter {
|
||||
private final DataOutputStream out;
|
||||
private final IdRegistry idRegistry = new IdRegistry();
|
||||
private final Token.Formatter tokenFormatter = new Token.Formatter();
|
||||
|
||||
private class IdRegistry {
|
||||
private Map ids;
|
||||
private long nextId;
|
||||
|
||||
private IdRegistry() {
|
||||
this.nextId = 0L;
|
||||
this.ids = new HashMap();
|
||||
}
|
||||
|
||||
public long getId(String str) {
|
||||
Long l = (Long) this.ids.get(str);
|
||||
if (l == null) {
|
||||
long j = this.nextId + 1;
|
||||
this.nextId = j;
|
||||
l = new Long(j);
|
||||
this.ids.put(str, l);
|
||||
BinaryStreamWriter.this.write(new Token.MapIdToValue(l.longValue(), str));
|
||||
}
|
||||
return l.longValue();
|
||||
}
|
||||
}
|
||||
|
||||
public BinaryStreamWriter(OutputStream outputStream) {
|
||||
this.out = new DataOutputStream(outputStream);
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public void write(Token token) {
|
||||
try {
|
||||
this.tokenFormatter.write(this.out, token);
|
||||
} catch (IOException e) {
|
||||
throw new StreamException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamWriter
|
||||
public void addAttribute(String str, String str2) {
|
||||
write(new Token.Attribute(this.idRegistry.getId(str), str2));
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamWriter
|
||||
public void close() {
|
||||
try {
|
||||
this.out.close();
|
||||
} catch (IOException e) {
|
||||
throw new StreamException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamWriter
|
||||
public void endNode() {
|
||||
write(new Token.EndNode());
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamWriter
|
||||
public void flush() {
|
||||
try {
|
||||
this.out.flush();
|
||||
} catch (IOException e) {
|
||||
throw new StreamException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamWriter
|
||||
public void setValue(String str) {
|
||||
write(new Token.Value(str));
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamWriter
|
||||
public void startNode(String str) {
|
||||
write(new Token.StartNode(this.idRegistry.getId(str)));
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.HierarchicalStreamWriter
|
||||
public HierarchicalStreamWriter underlyingWriter() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriter
|
||||
public void startNode(String str, Class cls) {
|
||||
startNode(str);
|
||||
}
|
||||
}
|
141
sources/com/thoughtworks/xstream/io/binary/ReaderDepthState.java
Normal file
141
sources/com/thoughtworks/xstream/io/binary/ReaderDepthState.java
Normal file
@@ -0,0 +1,141 @@
|
||||
package com.thoughtworks.xstream.io.binary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
class ReaderDepthState {
|
||||
private static final String EMPTY_STRING = "";
|
||||
private State current;
|
||||
|
||||
private static class Attribute {
|
||||
String name;
|
||||
String value;
|
||||
|
||||
private Attribute() {
|
||||
}
|
||||
}
|
||||
|
||||
private static class State {
|
||||
List attributes;
|
||||
boolean hasMoreChildren;
|
||||
String name;
|
||||
State parent;
|
||||
String value;
|
||||
|
||||
private State() {
|
||||
}
|
||||
}
|
||||
|
||||
ReaderDepthState() {
|
||||
}
|
||||
|
||||
public void addAttribute(String str, String str2) {
|
||||
Attribute attribute = new Attribute();
|
||||
attribute.name = str;
|
||||
attribute.value = str2;
|
||||
State state = this.current;
|
||||
if (state.attributes == null) {
|
||||
state.attributes = new ArrayList();
|
||||
}
|
||||
this.current.attributes.add(attribute);
|
||||
}
|
||||
|
||||
public String getAttribute(String str) {
|
||||
List<Attribute> list = this.current.attributes;
|
||||
if (list == null) {
|
||||
return null;
|
||||
}
|
||||
for (Attribute attribute : list) {
|
||||
if (attribute.name.equals(str)) {
|
||||
return attribute.value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getAttributeCount() {
|
||||
List list = this.current.attributes;
|
||||
if (list == null) {
|
||||
return 0;
|
||||
}
|
||||
return list.size();
|
||||
}
|
||||
|
||||
public String getAttributeName(int i) {
|
||||
List list = this.current.attributes;
|
||||
if (list == null) {
|
||||
return null;
|
||||
}
|
||||
return ((Attribute) list.get(i)).name;
|
||||
}
|
||||
|
||||
public Iterator getAttributeNames() {
|
||||
List list = this.current.attributes;
|
||||
if (list == null) {
|
||||
return Collections.EMPTY_SET.iterator();
|
||||
}
|
||||
final Iterator it = list.iterator();
|
||||
return new Iterator() { // from class: com.thoughtworks.xstream.io.binary.ReaderDepthState.1
|
||||
@Override // java.util.Iterator
|
||||
public boolean hasNext() {
|
||||
return it.hasNext();
|
||||
}
|
||||
|
||||
@Override // java.util.Iterator
|
||||
public Object next() {
|
||||
return ((Attribute) it.next()).name;
|
||||
}
|
||||
|
||||
@Override // java.util.Iterator
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.current.name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
String str = this.current.value;
|
||||
return str == null ? "" : str;
|
||||
}
|
||||
|
||||
public boolean hasMoreChildren() {
|
||||
return this.current.hasMoreChildren;
|
||||
}
|
||||
|
||||
public void pop() {
|
||||
this.current = this.current.parent;
|
||||
}
|
||||
|
||||
public void push() {
|
||||
State state = new State();
|
||||
state.parent = this.current;
|
||||
this.current = state;
|
||||
}
|
||||
|
||||
public void setHasMoreChildren(boolean z) {
|
||||
this.current.hasMoreChildren = z;
|
||||
}
|
||||
|
||||
public void setName(String str) {
|
||||
this.current.name = str;
|
||||
}
|
||||
|
||||
public void setValue(String str) {
|
||||
this.current.value = str;
|
||||
}
|
||||
|
||||
public String getAttribute(int i) {
|
||||
List list = this.current.attributes;
|
||||
if (list == null) {
|
||||
return null;
|
||||
}
|
||||
return ((Attribute) list.get(i)).value;
|
||||
}
|
||||
}
|
299
sources/com/thoughtworks/xstream/io/binary/Token.java
Normal file
299
sources/com/thoughtworks/xstream/io/binary/Token.java
Normal file
@@ -0,0 +1,299 @@
|
||||
package com.thoughtworks.xstream.io.binary;
|
||||
|
||||
import com.thoughtworks.xstream.io.StreamException;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public abstract class Token {
|
||||
private static final byte ID_EIGHT_BYTES = 32;
|
||||
private static final byte ID_FOUR_BYTES = 24;
|
||||
private static final byte ID_MASK = 56;
|
||||
private static final byte ID_ONE_BYTE = 8;
|
||||
private static final String ID_SPLITTED = "\u0000‡\u0000";
|
||||
private static final byte ID_TWO_BYTES = 16;
|
||||
private static final int MAX_UTF8_LENGTH = 65535;
|
||||
public static final byte TYPE_ATTRIBUTE = 5;
|
||||
public static final byte TYPE_END_NODE = 4;
|
||||
public static final byte TYPE_MAP_ID_TO_VALUE = 2;
|
||||
private static final byte TYPE_MASK = 7;
|
||||
public static final byte TYPE_START_NODE = 3;
|
||||
public static final byte TYPE_VALUE = 6;
|
||||
public static final byte TYPE_VERSION = 1;
|
||||
protected long id = -1;
|
||||
private final byte type;
|
||||
protected String value;
|
||||
|
||||
public static class EndNode extends Token {
|
||||
public EndNode() {
|
||||
super((byte) 4);
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.binary.Token
|
||||
public void readFrom(DataInput dataInput, byte b) {
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.binary.Token
|
||||
public void writeTo(DataOutput dataOutput, byte b) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Formatter {
|
||||
private Token contructToken(byte b) {
|
||||
if (b == 2) {
|
||||
return new MapIdToValue();
|
||||
}
|
||||
if (b == 3) {
|
||||
return new StartNode();
|
||||
}
|
||||
if (b == 4) {
|
||||
return new EndNode();
|
||||
}
|
||||
if (b == 5) {
|
||||
return new Attribute();
|
||||
}
|
||||
if (b == 6) {
|
||||
return new Value();
|
||||
}
|
||||
throw new StreamException("Unknown token type");
|
||||
}
|
||||
|
||||
public Token read(DataInput dataInput) throws IOException {
|
||||
byte readByte = dataInput.readByte();
|
||||
byte b = (byte) (readByte & Token.TYPE_MASK);
|
||||
byte b2 = (byte) (readByte & Token.ID_MASK);
|
||||
Token contructToken = contructToken(b);
|
||||
contructToken.readFrom(dataInput, b2);
|
||||
return contructToken;
|
||||
}
|
||||
|
||||
public void write(DataOutput dataOutput, Token token) throws IOException {
|
||||
long id = token.getId();
|
||||
byte b = id <= 255 ? Token.ID_ONE_BYTE : id <= 65535 ? Token.ID_TWO_BYTES : id <= 4294967295L ? Token.ID_FOUR_BYTES : Token.ID_EIGHT_BYTES;
|
||||
dataOutput.write(token.getType() + b);
|
||||
token.writeTo(dataOutput, b);
|
||||
}
|
||||
}
|
||||
|
||||
public Token(byte b) {
|
||||
this.type = b;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Token token = (Token) obj;
|
||||
if (this.id != token.id || this.type != token.type) {
|
||||
return false;
|
||||
}
|
||||
String str = this.value;
|
||||
String str2 = token.value;
|
||||
if (str != null) {
|
||||
if (str.equals(str2)) {
|
||||
return true;
|
||||
}
|
||||
} else if (str2 == null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public byte getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int i = this.type * 29;
|
||||
long j = this.id;
|
||||
int i2 = (i + ((int) (j ^ (j >>> 32)))) * 29;
|
||||
String str = this.value;
|
||||
return i2 + (str != null ? str.hashCode() : 0);
|
||||
}
|
||||
|
||||
public abstract void readFrom(DataInput dataInput, byte b) throws IOException;
|
||||
|
||||
protected long readId(DataInput dataInput, byte b) throws IOException {
|
||||
if (b == 8) {
|
||||
return dataInput.readByte() + 128;
|
||||
}
|
||||
if (b == 16) {
|
||||
return dataInput.readShort() - Short.MIN_VALUE;
|
||||
}
|
||||
if (b == 24) {
|
||||
return dataInput.readInt() - Integer.MIN_VALUE;
|
||||
}
|
||||
if (b == 32) {
|
||||
return dataInput.readLong() - Long.MIN_VALUE;
|
||||
}
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append("Unknown idType ");
|
||||
stringBuffer.append((int) b);
|
||||
throw new Error(stringBuffer.toString());
|
||||
}
|
||||
|
||||
protected String readString(DataInput dataInput) throws IOException {
|
||||
String readUTF = dataInput.readUTF();
|
||||
if (!ID_SPLITTED.equals(readUTF)) {
|
||||
return readUTF;
|
||||
}
|
||||
byte[] bArr = new byte[dataInput.readInt()];
|
||||
dataInput.readFully(bArr);
|
||||
return new String(bArr, "utf-8");
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append(getClass().getName());
|
||||
stringBuffer.append(" [id=");
|
||||
stringBuffer.append(this.id);
|
||||
stringBuffer.append(", value='");
|
||||
stringBuffer.append(this.value);
|
||||
stringBuffer.append("']");
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
protected void writeId(DataOutput dataOutput, long j, byte b) throws IOException {
|
||||
if (j < 0) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append("id must not be negative ");
|
||||
stringBuffer.append(j);
|
||||
throw new IOException(stringBuffer.toString());
|
||||
}
|
||||
if (b == 8) {
|
||||
dataOutput.writeByte(((byte) j) - 128);
|
||||
return;
|
||||
}
|
||||
if (b == 16) {
|
||||
dataOutput.writeShort(((short) j) - 32768);
|
||||
return;
|
||||
}
|
||||
if (b == 24) {
|
||||
dataOutput.writeInt(((int) j) - 2147483648);
|
||||
} else {
|
||||
if (b == 32) {
|
||||
dataOutput.writeLong(j - Long.MIN_VALUE);
|
||||
return;
|
||||
}
|
||||
StringBuffer stringBuffer2 = new StringBuffer();
|
||||
stringBuffer2.append("Unknown idType ");
|
||||
stringBuffer2.append((int) b);
|
||||
throw new Error(stringBuffer2.toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeString(DataOutput dataOutput, String str) throws IOException {
|
||||
byte[] bytes = str.length() > 16383 ? str.getBytes("utf-8") : new byte[0];
|
||||
if (bytes.length <= MAX_UTF8_LENGTH) {
|
||||
dataOutput.writeUTF(str);
|
||||
return;
|
||||
}
|
||||
dataOutput.writeUTF(ID_SPLITTED);
|
||||
dataOutput.writeInt(bytes.length);
|
||||
dataOutput.write(bytes);
|
||||
}
|
||||
|
||||
public abstract void writeTo(DataOutput dataOutput, byte b) throws IOException;
|
||||
|
||||
public static class StartNode extends Token {
|
||||
public StartNode(long j) {
|
||||
super((byte) 3);
|
||||
this.id = j;
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.binary.Token
|
||||
public void readFrom(DataInput dataInput, byte b) throws IOException {
|
||||
this.id = readId(dataInput, b);
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.binary.Token
|
||||
public void writeTo(DataOutput dataOutput, byte b) throws IOException {
|
||||
writeId(dataOutput, this.id, b);
|
||||
}
|
||||
|
||||
public StartNode() {
|
||||
super((byte) 3);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Value extends Token {
|
||||
public Value(String str) {
|
||||
super((byte) 6);
|
||||
this.value = str;
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.binary.Token
|
||||
public void readFrom(DataInput dataInput, byte b) throws IOException {
|
||||
this.value = readString(dataInput);
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.binary.Token
|
||||
public void writeTo(DataOutput dataOutput, byte b) throws IOException {
|
||||
writeString(dataOutput, this.value);
|
||||
}
|
||||
|
||||
public Value() {
|
||||
super((byte) 6);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Attribute extends Token {
|
||||
public Attribute(long j, String str) {
|
||||
super((byte) 5);
|
||||
this.id = j;
|
||||
this.value = str;
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.binary.Token
|
||||
public void readFrom(DataInput dataInput, byte b) throws IOException {
|
||||
this.id = readId(dataInput, b);
|
||||
this.value = readString(dataInput);
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.binary.Token
|
||||
public void writeTo(DataOutput dataOutput, byte b) throws IOException {
|
||||
writeId(dataOutput, this.id, b);
|
||||
writeString(dataOutput, this.value);
|
||||
}
|
||||
|
||||
public Attribute() {
|
||||
super((byte) 5);
|
||||
}
|
||||
}
|
||||
|
||||
public static class MapIdToValue extends Token {
|
||||
public MapIdToValue(long j, String str) {
|
||||
super((byte) 2);
|
||||
this.id = j;
|
||||
this.value = str;
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.binary.Token
|
||||
public void readFrom(DataInput dataInput, byte b) throws IOException {
|
||||
this.id = readId(dataInput, b);
|
||||
this.value = readString(dataInput);
|
||||
}
|
||||
|
||||
@Override // com.thoughtworks.xstream.io.binary.Token
|
||||
public void writeTo(DataOutput dataOutput, byte b) throws IOException {
|
||||
writeId(dataOutput, this.id, b);
|
||||
writeString(dataOutput, this.value);
|
||||
}
|
||||
|
||||
public MapIdToValue() {
|
||||
super((byte) 2);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user