Search in sources :

Example 1 with CompressedCompoundTag

use of com.fastasyncworldedit.core.jnbt.CompressedCompoundTag 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;
}
Also used : FastSchematicWriter(com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicWriter) CompressedSchematicTag(com.fastasyncworldedit.core.jnbt.CompressedSchematicTag) NBTOutputStream(com.sk89q.jnbt.NBTOutputStream) ParallelGZIPOutputStream(org.anarres.parallelgzip.ParallelGZIPOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) NBTOutputStream(com.sk89q.jnbt.NBTOutputStream) LZ4BlockInputStream(net.jpountz.lz4.LZ4BlockInputStream) CompressedCompoundTag(com.fastasyncworldedit.core.jnbt.CompressedCompoundTag) ParallelGZIPOutputStream(org.anarres.parallelgzip.ParallelGZIPOutputStream) FileOutputStream(java.io.FileOutputStream) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) CompressedSchematicTag(com.fastasyncworldedit.core.jnbt.CompressedSchematicTag) CompressedCompoundTag(com.fastasyncworldedit.core.jnbt.CompressedCompoundTag) CompoundTag(com.sk89q.jnbt.CompoundTag) Tag(com.sk89q.jnbt.Tag) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

FastSchematicWriter (com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicWriter)1 CompressedCompoundTag (com.fastasyncworldedit.core.jnbt.CompressedCompoundTag)1 CompressedSchematicTag (com.fastasyncworldedit.core.jnbt.CompressedSchematicTag)1 CompoundTag (com.sk89q.jnbt.CompoundTag)1 NBTOutputStream (com.sk89q.jnbt.NBTOutputStream)1 Tag (com.sk89q.jnbt.Tag)1 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 LZ4BlockInputStream (net.jpountz.lz4.LZ4BlockInputStream)1 ParallelGZIPOutputStream (org.anarres.parallelgzip.ParallelGZIPOutputStream)1