use of info.ata4.io.DataWriter in project disunity by ata4.
the class BundleWriter method write.
public void write(Bundle bundle, Progress progress) throws IOException {
this.bundle = bundle;
// add offset placeholders
levelOffsetMap.clear();
bundle.entries().stream().filter(entry -> {
if (bundle.entries().size() == 1) {
return true;
}
String name = entry.name();
return name.equals("mainData") || name.startsWith("level");
}).forEach(entry -> levelOffsetMap.put(entry, new MutablePair<>(0L, 0L)));
BundleHeader header = bundle.header();
header.levelByteEnd().clear();
header.levelByteEnd().addAll(levelOffsetMap.values());
header.numberOfLevelsToDownload(levelOffsetMap.size());
// write header
out.writeStruct(header);
header.headerSize((int) out.position());
// write bundle data
if (header.compressed()) {
// write data to temporary file
try (DataWriter outData = DataWriters.forFile(dataFile, CREATE, WRITE, TRUNCATE_EXISTING)) {
writeData(outData, progress);
}
// configure LZMA encoder
LzmaEncoderProps props = new LzmaEncoderProps();
// 8 MiB
props.setDictionarySize(1 << 23);
// maximum
props.setNumFastBytes(273);
props.setUncompressedSize(Files.size(dataFile));
props.setEndMarkerMode(true);
// stream the temporary bundle data compressed into the bundle file
try (OutputStream os = new LzmaOutputStream(new BufferedOutputStream(out.stream()), props)) {
Files.copy(dataFile, os);
}
for (MutablePair<Long, Long> levelOffset : levelOffsetMap.values()) {
levelOffset.setLeft(out.size());
}
} else {
// write data directly to file
writeData(out, progress);
}
// update header
int fileSize = (int) out.size();
header.completeFileSize(fileSize);
header.minimumStreamedBytes(fileSize);
out.position(0);
out.writeStruct(header);
}
use of info.ata4.io.DataWriter in project disunity by ata4.
the class SerializedFileWriter method writeMetadata.
private void writeMetadata(DataWriter out) throws IOException {
SerializedFileMetadata metadata = serialized.metadata();
SerializedFileHeader header = serialized.header();
DataBlock metadataBlock = serialized.metadataBlock();
metadataBlock.markBegin(out);
metadata.version(header.version());
out.writeStruct(metadata);
metadataBlock.markEnd(out);
L.log(Level.FINER, "metadataBlock: {0}", metadataBlock);
}
use of info.ata4.io.DataWriter in project disunity by ata4.
the class SerializedFileWriter method writeObjects.
private void writeObjects(DataWriter out) throws IOException {
long ofsMin = Long.MAX_VALUE;
long ofsMax = Long.MIN_VALUE;
for (SerializedObjectData data : serialized.objectData()) {
ByteBuffer bb = data.buffer();
bb.rewind();
out.align(8);
ofsMin = Math.min(ofsMin, out.position());
ofsMax = Math.max(ofsMax, out.position() + bb.remaining());
ObjectInfo info = data.info();
info.offset(out.position() - serialized.header().dataOffset());
info.length(bb.remaining());
out.writeBuffer(bb);
}
DataBlock objectDataBlock = serialized.objectDataBlock();
objectDataBlock.offset(ofsMin);
objectDataBlock.endOffset(ofsMax);
L.log(Level.FINER, "objectDataBlock: {0}", objectDataBlock);
}
use of info.ata4.io.DataWriter in project disunity by ata4.
the class SerializedFileWriter method writeHeader.
private void writeHeader(DataWriter out) throws IOException {
DataBlock headerBlock = serialized.headerBlock();
headerBlock.markBegin(out);
out.writeStruct(serialized.header());
headerBlock.markEnd(out);
L.log(Level.FINER, "headerBlock: {0}", headerBlock);
}
use of info.ata4.io.DataWriter in project disunity by ata4.
the class TypeTreeV1 method writeNode.
private void writeNode(DataWriter out, Node<T> node) throws IOException {
T type = node.data();
out.writeStruct(type);
int numChildren = node.size();
out.writeInt(numChildren);
for (Node child : node) {
writeNode(out, child);
}
}
Aggregations