use of com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicWriter in project FastAsyncWorldEdit by IntellectualSites.
the class FaweDelegateSchematicHandler method save.
public boolean save(CompoundTag tag, String path) {
if (tag == null) {
LOGGER.warn("Cannot save empty tag");
return false;
}
try {
File tmp = FileUtils.getFile(PlotSquared.platform().getDirectory(), path);
tmp.getParentFile().mkdirs();
if (tag instanceof CompressedCompoundTag) {
CompressedCompoundTag cTag = (CompressedCompoundTag) tag;
if (cTag instanceof CompressedSchematicTag) {
Clipboard clipboard = (Clipboard) cTag.getSource();
try (OutputStream stream = new FileOutputStream(tmp);
NBTOutputStream output = new NBTOutputStream(new BufferedOutputStream(new ParallelGZIPOutputStream(stream)))) {
new FastSchematicWriter(output).write(clipboard);
}
} else {
try (OutputStream stream = new FileOutputStream(tmp);
BufferedOutputStream output = new BufferedOutputStream(new ParallelGZIPOutputStream(stream))) {
LZ4BlockInputStream is = cTag.adapt(cTag.getSource());
IOUtil.copy(is, output);
}
}
} else {
try (OutputStream stream = new FileOutputStream(tmp);
NBTOutputStream output = new NBTOutputStream(new ParallelGZIPOutputStream(stream))) {
Map<String, Tag> map = tag.getValue();
output.writeNamedTag("Schematic", map.getOrDefault("Schematic", tag));
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
use of com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicWriter in project FastAsyncWorldEdit by IntellectualSites.
the class CompressedSchematicTag method adapt.
@Override
public LZ4BlockInputStream adapt(Clipboard src) throws IOException {
FastByteArrayOutputStream blocksOut = new FastByteArrayOutputStream();
try (LZ4BlockOutputStream lz4out = new LZ4BlockOutputStream(blocksOut)) {
NBTOutputStream nbtOut = new NBTOutputStream(lz4out);
new FastSchematicWriter(nbtOut).write(getSource());
} catch (IOException e) {
throw new RuntimeException(e);
}
FastByteArraysInputStream in = new FastByteArraysInputStream(blocksOut.toByteArrays());
return new LZ4BlockInputStream(in);
}
Aggregations