📄 xmlexporter.java
字号:
final void exportRef(int oid) throws IOException {
writer.write("<ref id=\"" + oid + "\"/>");
if (oid != 0 && (exportedBitmap[oid >> 5] & (1 << (oid & 31))) == 0) {
markedBitmap[oid >> 5] |= 1 << (oid & 31);
}
}
final int exportObject(ClassDescriptor desc, byte[] body, int offs, int indent) throws IOException {
ClassDescriptor.FieldDescriptor[] all = desc.allFields;
for (int i = 0, n = all.length; i < n; i++) {
ClassDescriptor.FieldDescriptor fd = all[i];
indentation(indent);
String fieldName = exportIdentifier(fd.fieldName);
writer.write("<" + fieldName + ">");
switch (fd.type) {
case ClassDescriptor.tpBoolean:
writer.write(body[offs++] != 0 ? "1" : "0");
break;
case ClassDescriptor.tpByte:
writer.write(Integer.toString(body[offs++]));
break;
case ClassDescriptor.tpChar:
writer.write(Integer.toString((char)Bytes.unpack2(body, offs)));
offs += 2;
break;
case ClassDescriptor.tpShort:
writer.write(Integer.toString(Bytes.unpack2(body, offs)));
offs += 2;
break;
case ClassDescriptor.tpInt:
writer.write(Integer.toString(Bytes.unpack4(body, offs)));
offs += 4;
break;
case ClassDescriptor.tpLong:
writer.write(Long.toString(Bytes.unpack8(body, offs)));
offs += 8;
break;
case ClassDescriptor.tpFloat:
writer.write(Float.toString(Float.intBitsToFloat(Bytes.unpack4(body, offs))));
offs += 4;
break;
case ClassDescriptor.tpDouble:
writer.write(Double.toString(Double.longBitsToDouble(Bytes.unpack8(body, offs))));
offs += 8;
break;
case ClassDescriptor.tpEnum:
{
int ordinal = Bytes.unpack4(body, offs);
if (ordinal < 0) {
writer.write("null");
} else {
writer.write("\"" + ((Enum)fd.field.getType().getEnumConstants()[ordinal]).name() + "\"");
}
offs += 4;
break;
}
case ClassDescriptor.tpString:
offs = exportString(body, offs);
break;
case ClassDescriptor.tpDate:
{
long msec = Bytes.unpack8(body, offs);
offs += 8;
if (msec >= 0) {
writer.write("\"" + XMLImporter.httpFormatter.format(new Date(msec)) + "\"");
} else {
writer.write("null");
}
break;
}
case ClassDescriptor.tpObject:
exportRef(Bytes.unpack4(body, offs));
offs += 4;
break;
case ClassDescriptor.tpValue:
writer.write('\n');
offs = exportObject(fd.valueDesc, body, offs, indent+1);
indentation(indent);
break;
case ClassDescriptor.tpRaw:
case ClassDescriptor.tpArrayOfByte:
offs = exportBinary(body, offs);
break;
case ClassDescriptor.tpCustom:
{
ByteArrayInputStream in = new ByteArrayInputStream(body, offs, body.length - offs);
CustomSerializable obj = storage.serializer.unpack(in);
String str = obj.toString();
writer.write("\"");
for (int j = 0, len = str.length(); j < len; j++) {
exportChar(str.charAt(j));
}
writer.write("\"");
offs = body.length - in.available();
break;
}
case ClassDescriptor.tpArrayOfBoolean:
{
int len = Bytes.unpack4(body, offs);
offs += 4;
if (len < 0) {
writer.write("null");
} else {
writer.write('\n');
while (--len >= 0) {
indentation(indent+1);
writer.write("<element>" + (body[offs++] != 0 ? "1" : "0") + "</element>\n");
}
indentation(indent);
}
break;
}
case ClassDescriptor.tpArrayOfChar:
{
int len = Bytes.unpack4(body, offs);
offs += 4;
if (len < 0) {
writer.write("null");
} else {
writer.write('\n');
while (--len >= 0) {
indentation(indent+1);
writer.write("<element>" + (Bytes.unpack2(body, offs) & 0xFFFF) + "</element>\n");
offs += 2;
}
indentation(indent);
}
break;
}
case ClassDescriptor.tpArrayOfShort:
{
int len = Bytes.unpack4(body, offs);
offs += 4;
if (len < 0) {
writer.write("null");
} else {
writer.write('\n');
while (--len >= 0) {
indentation(indent+1);
writer.write("<element>" + Bytes.unpack2(body, offs) + "</element>\n");
offs += 2;
}
indentation(indent);
}
break;
}
case ClassDescriptor.tpArrayOfInt:
{
int len = Bytes.unpack4(body, offs);
offs += 4;
if (len < 0) {
writer.write("null");
} else {
writer.write('\n');
Enum[] enumConstants = (Enum[])fd.field.getType().getEnumConstants();
while (--len >= 0) {
indentation(indent+1);
int ordinal = Bytes.unpack4(body, offs);
if (ordinal < 0) {
writer.write("null");
} else {
writer.write("<element>\"" + enumConstants[ordinal].name() + "\"</element>\n");
}
offs += 4;
}
indentation(indent);
}
break;
}
case ClassDescriptor.tpArrayOfLong:
{
int len = Bytes.unpack4(body, offs);
offs += 4;
if (len < 0) {
writer.write("null");
} else {
writer.write('\n');
while (--len >= 0) {
indentation(indent+1);
writer.write("<element>" + Bytes.unpack8(body, offs) + "</element>\n");
offs += 8;
}
indentation(indent);
}
break;
}
case ClassDescriptor.tpArrayOfFloat:
{
int len = Bytes.unpack4(body, offs);
offs += 4;
if (len < 0) {
writer.write("null");
} else {
writer.write('\n');
while (--len >= 0) {
indentation(indent+1);
writer.write("<element>"
+ Float.intBitsToFloat(Bytes.unpack4(body, offs))
+ "</element>\n");
offs += 4;
}
indentation(indent);
}
break;
}
case ClassDescriptor.tpArrayOfDouble:
{
int len = Bytes.unpack4(body, offs);
offs += 4;
if (len < 0) {
writer.write("null");
} else {
writer.write('\n');
while (--len >= 0) {
indentation(indent+1);
writer.write("<element>"
+ Double.longBitsToDouble(Bytes.unpack8(body, offs))
+ "</element>\n");
offs += 8;
}
indentation(indent);
}
break;
}
case ClassDescriptor.tpArrayOfDate:
{
int len = Bytes.unpack4(body, offs);
offs += 4;
if (len < 0) {
writer.write("null");
} else {
writer.write('\n');
while (--len >= 0) {
indentation(indent+1);
long msec = Bytes.unpack8(body, offs);
offs += 8;
if (msec >= 0) {
writer.write("<element>\"");
writer.write(XMLImporter.httpFormatter.format(new Date(msec)));
writer.write("\"</element>\n");
} else {
writer.write("<element>null</element>\n");
}
}
}
break;
}
case ClassDescriptor.tpArrayOfString:
{
int len = Bytes.unpack4(body, offs);
offs += 4;
if (len < 0) {
writer.write("null");
} else {
writer.write('\n');
while (--len >= 0) {
indentation(indent+1);
writer.write("<element>");
offs = exportString(body, offs);
writer.write("</element>\n");
}
indentation(indent);
}
break;
}
case ClassDescriptor.tpLink:
case ClassDescriptor.tpArrayOfObject:
{
int len = Bytes.unpack4(body, offs);
offs += 4;
if (len < 0) {
writer.write("null");
} else {
writer.write('\n');
while (--len >= 0) {
indentation(indent+1);
int oid = Bytes.unpack4(body, offs);
if (oid != 0 && (exportedBitmap[oid >> 5] & (1 << (oid & 31))) == 0) {
markedBitmap[oid >> 5] |= 1 << (oid & 31);
}
writer.write("<element><ref id=\"" + oid + "\"/></element>\n");
offs += 4;
}
indentation(indent);
}
break;
}
case ClassDescriptor.tpArrayOfValue:
{
int len = Bytes.unpack4(body, offs);
offs += 4;
if (len < 0) {
writer.write("null");
} else {
writer.write('\n');
while (--len >= 0) {
indentation(indent+1);
writer.write("<element>\n");
offs = exportObject(fd.valueDesc, body, offs, indent+2);
indentation(indent+1);
writer.write("</element>\n");
}
indentation(indent);
}
break;
}
case ClassDescriptor.tpArrayOfRaw:
{
int len = Bytes.unpack4(body, offs);
offs += 4;
if (len < 0) {
writer.write("null");
} else {
writer.write('\n');
while (--len >= 0) {
indentation(indent+1);
writer.write("<element>");
offs = exportBinary(body, offs);
writer.write("</element>\n");
}
indentation(indent);
}
break;
}
}
writer.write("</" + fieldName + ">\n");
}
return offs;
}
private StorageImpl storage;
private Writer writer;
private int[] markedBitmap;
private int[] exportedBitmap;
private int[] compoundKeyTypes;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -