use of gnu.trove.list.array.TByteArrayList in project BuildCraft by BuildCraft.
the class NbtSquishMapWriter method write.
private void write(DataOutput to) throws IOException {
profiler.startSection("write");
profiler.startSection("flags");
WrittenType type = map.getWrittenType();
type.writeType(to);
TByteArrayList bytes = map.bytes;
TShortArrayList shorts = map.shorts;
TIntArrayList ints = map.ints;
TLongArrayList longs = map.longs;
TFloatArrayList floats = map.floats;
TDoubleArrayList doubles = map.doubles;
List<TByteArrayList> byteArrays = map.byteArrays;
List<TIntArrayList> intArrays = map.intArrays;
List<String> strings = map.strings;
List<NBTBase> complex = map.complex;
int flags = 0;
if (!bytes.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_BYTES;
if (!shorts.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_SHORTS;
if (!ints.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_INTS;
if (!longs.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_LONGS;
if (!floats.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_FLOATS;
if (!doubles.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_DOUBLES;
if (!byteArrays.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_BYTE_ARRAYS;
if (!intArrays.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_INT_ARRAYS;
if (!strings.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_STRINGS;
if (!complex.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_COMPLEX;
if (debug)
log("\nUsed flags = " + Integer.toBinaryString(flags));
to.writeInt(flags);
profiler.endStartSection("bytes");
if (!bytes.isEmpty()) {
if (debug)
log("\nByte dictionary size = " + bytes.size());
if (sort)
bytes.sort();
writeVarInt(to, bytes.size());
for (byte b : bytes.toArray()) {
to.writeByte(b);
}
}
profiler.endStartSection("shorts");
if (!shorts.isEmpty()) {
if (debug)
log("\nShort dictionary size = " + shorts.size());
if (sort)
shorts.sort();
writeVarInt(to, shorts.size());
for (short s : shorts.toArray()) {
to.writeShort(s);
}
}
profiler.endStartSection("integers");
if (!ints.isEmpty()) {
if (debug)
log("\nInt dictionary size = " + ints.size());
if (sort)
ints.sort();
writeVarInt(to, ints.size());
for (int i : ints.toArray()) {
to.writeInt(i);
}
}
profiler.endStartSection("longs");
if (!longs.isEmpty()) {
if (debug)
log("\nLong dictionary size = " + longs.size());
if (sort)
longs.sort();
writeVarInt(to, longs.size());
for (long l : longs.toArray()) {
to.writeLong(l);
}
}
profiler.endStartSection("floats");
if (!floats.isEmpty()) {
if (debug)
log("\nFloat dictionary size = " + floats.size());
if (sort)
floats.sort();
writeVarInt(to, floats.size());
for (float f : floats.toArray()) {
to.writeFloat(f);
}
}
profiler.endStartSection("doubles");
if (!doubles.isEmpty()) {
if (debug)
log("\nDouble dictionary size = " + doubles.size());
if (sort)
doubles.sort();
writeVarInt(to, doubles.size());
for (double d : doubles.toArray()) {
to.writeDouble(d);
}
}
profiler.endStartSection("byte_arrays");
if (!byteArrays.isEmpty()) {
if (debug)
log("\nByte Array dictionary size = " + byteArrays.size());
writeVarInt(to, byteArrays.size());
for (TByteArrayList ba : byteArrays) {
to.writeShort(ba.size());
for (byte b : ba.toArray()) {
to.writeByte(b);
}
}
}
profiler.endStartSection("int_arrays");
if (!intArrays.isEmpty()) {
if (debug)
log("\nInt Array dictionary size = " + intArrays.size());
writeVarInt(to, intArrays.size());
for (TIntArrayList ia : intArrays) {
to.writeShort(ia.size());
for (int i : ia.toArray()) {
to.writeInt(i);
}
}
}
profiler.endStartSection("strings");
if (!strings.isEmpty()) {
if (debug)
log("\nString dictionary size = " + strings.size());
if (sort)
Collections.sort(strings);
writeVarInt(to, strings.size());
for (int i = 0; i < strings.size(); i++) {
String s = strings.get(i);
if (debug)
log("\n String " + i + " = " + s);
byte[] stringBytes = s.getBytes(StandardCharsets.UTF_8);
to.writeShort(stringBytes.length);
to.write(stringBytes);
}
}
profiler.endStartSection("complex");
if (!complex.isEmpty()) {
if (debug)
log("\nComplex dictionary size = " + complex.size());
writeVarInt(to, complex.size());
for (NBTBase nbt : complex) {
if (nbt instanceof NBTTagList) {
NBTTagList list = (NBTTagList) nbt;
writeList(type, list, to);
} else {
NBTTagCompound compound = (NBTTagCompound) nbt;
writeCompound(type, compound, to);
}
}
}
profiler.endSection();
profiler.endSection();
}
Aggregations