Search in sources :

Example 1 with FastSchematicWriter

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;
}
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)

Example 2 with FastSchematicWriter

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);
}
Also used : LZ4BlockOutputStream(net.jpountz.lz4.LZ4BlockOutputStream) FastSchematicWriter(com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicWriter) FastByteArrayOutputStream(com.fastasyncworldedit.core.internal.io.FastByteArrayOutputStream) FastByteArraysInputStream(com.fastasyncworldedit.core.internal.io.FastByteArraysInputStream) IOException(java.io.IOException) NBTOutputStream(com.sk89q.jnbt.NBTOutputStream) LZ4BlockInputStream(net.jpountz.lz4.LZ4BlockInputStream)

Aggregations

FastSchematicWriter (com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicWriter)2 NBTOutputStream (com.sk89q.jnbt.NBTOutputStream)2 IOException (java.io.IOException)2 LZ4BlockInputStream (net.jpountz.lz4.LZ4BlockInputStream)2 FastByteArrayOutputStream (com.fastasyncworldedit.core.internal.io.FastByteArrayOutputStream)1 FastByteArraysInputStream (com.fastasyncworldedit.core.internal.io.FastByteArraysInputStream)1 CompressedCompoundTag (com.fastasyncworldedit.core.jnbt.CompressedCompoundTag)1 CompressedSchematicTag (com.fastasyncworldedit.core.jnbt.CompressedSchematicTag)1 CompoundTag (com.sk89q.jnbt.CompoundTag)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 OutputStream (java.io.OutputStream)1 LZ4BlockOutputStream (net.jpountz.lz4.LZ4BlockOutputStream)1 ParallelGZIPOutputStream (org.anarres.parallelgzip.ParallelGZIPOutputStream)1