use of org.anarres.parallelgzip.ParallelGZIPOutputStream 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 org.anarres.parallelgzip.ParallelGZIPOutputStream in project FastAsyncWorldEdit by IntellectualSites.
the class FaweDelegateSchematicHandler method upload.
public void upload(final CompoundTag tag, final UUID uuid, final String file, final RunnableVal<URL> whenDone) {
if (tag == null) {
LOGGER.warn("Cannot save empty tag");
if (whenDone != null) {
TaskManager.runTask(whenDone);
}
return;
}
final CompoundTag weTag = (CompoundTag) FaweCache.INSTANCE.asTag(tag);
SchematicHandler.upload(uuid, file, "schem", new RunnableVal<>() {
@Override
public void run(OutputStream output) {
if (weTag instanceof CompressedSchematicTag) {
Clipboard clipboard = ((CompressedSchematicTag) weTag).getSource();
BuiltInClipboardFormat.FAST.write(output, clipboard);
}
try {
try (ParallelGZIPOutputStream gzip = new ParallelGZIPOutputStream(output)) {
try (NBTOutputStream nos = new NBTOutputStream(gzip)) {
Map<String, Tag> map = weTag.getValue();
nos.writeNamedTag("Schematic", map.getOrDefault("Schematic", weTag));
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}, whenDone);
}
use of org.anarres.parallelgzip.ParallelGZIPOutputStream in project FastAsyncWorldEdit by IntellectualSites.
the class BrushCommands method saveBrush.
@Command(name = "savebrush", aliases = { "save" }, desc = "Save your current brush")
@CommandPermissions("worldedit.brush.save")
public void saveBrush(Player player, LocalSession session, @Arg(desc = "String name") String name, @Switch(name = 'g', desc = "Save the brush globally") boolean root) throws WorldEditException, IOException {
BrushTool tool = session.getBrushTool(player);
if (tool != null) {
root |= name.startsWith("../");
name = FileSystems.getDefault().getPath(name).getFileName().toString();
File folder = MainUtil.getFile(Fawe.platform().getDirectory(), "brushes");
name = name.endsWith(".jsgz") ? name : name + ".jsgz";
File file;
if (root && player.hasPermission("worldedit.brush.save.other")) {
file = new File(folder, name);
} else {
file = new File(folder, player.getUniqueId() + File.separator + name);
}
File parent = file.getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}
file.createNewFile();
try (DataOutputStream out = new DataOutputStream(new ParallelGZIPOutputStream(new FileOutputStream(file)))) {
out.writeUTF(tool.toString());
} catch (Throwable e) {
e.printStackTrace();
}
player.print(Caption.of("fawe.worldedit.schematic.schematic.saved", name));
} else {
player.print(Caption.of("fawe.worldedit.brush.brush.none"));
}
}
Aggregations