Fix downloaded schems + mcedit

This commit is contained in:
Jesse Boyd 2016-09-14 10:12:09 +10:00
parent 6dfea0364a
commit 911e7e7751
3 changed files with 51 additions and 5 deletions

View File

@ -11,12 +11,14 @@ import com.boydti.fawe.object.PseudoRandom;
import com.boydti.fawe.object.RegionWrapper; import com.boydti.fawe.object.RegionWrapper;
import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.object.changeset.DiskStorageHistory; import com.boydti.fawe.object.changeset.DiskStorageHistory;
import com.boydti.fawe.object.io.FastByteArrayOutputStream;
import com.boydti.fawe.object.schematic.Schematic; import com.boydti.fawe.object.schematic.Schematic;
import com.boydti.fawe.regions.FaweMaskManager; import com.boydti.fawe.regions.FaweMaskManager;
import com.boydti.fawe.util.EditSessionBuilder; import com.boydti.fawe.util.EditSessionBuilder;
import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.MemUtil; import com.boydti.fawe.util.MemUtil;
import com.boydti.fawe.util.SetQueue; import com.boydti.fawe.util.SetQueue;
import com.boydti.fawe.util.StringMan;
import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.TaskManager;
import com.boydti.fawe.util.WEManager; import com.boydti.fawe.util.WEManager;
import com.boydti.fawe.wrappers.WorldWrapper; import com.boydti.fawe.wrappers.WorldWrapper;
@ -44,6 +46,7 @@ import java.io.OutputStream;
import java.net.URL; import java.net.URL;
import java.nio.channels.Channels; import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel; import java.nio.channels.ReadableByteChannel;
import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -142,10 +145,11 @@ public class FaweAPI {
@Override @Override
public void run(OutputStream value) { public void run(OutputStream value) {
try { try {
GZIPOutputStream gzip = new GZIPOutputStream(value, true); try (GZIPOutputStream gzip = new GZIPOutputStream(value, true)) {
ClipboardWriter writer = format.getWriter(gzip); try (ClipboardWriter writer = format.getWriter(gzip)) {
writer.write(clipboard, null); writer.write(clipboard, null);
gzip.flush(); }
}
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -0,0 +1,37 @@
package com.boydti.fawe.object.io;
import java.io.IOException;
import java.io.OutputStream;
public class AbstractDelegateOutputStream extends OutputStream {
private final OutputStream parent;
@Override
public void write(int b) throws IOException {
parent.write(b);
}
@Override
public void write(byte[] b) throws IOException {
parent.write(b);
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
parent.write(b, off, len);
}
@Override
public void flush() throws IOException {
parent.flush();
}
@Override
public void close() throws IOException {
parent.close();
}
public AbstractDelegateOutputStream(OutputStream os) {
this.parent = os;
}
}

View File

@ -11,6 +11,7 @@ import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.object.RunnableVal2; import com.boydti.fawe.object.RunnableVal2;
import com.boydti.fawe.object.changeset.CPUOptimizedChangeSet; import com.boydti.fawe.object.changeset.CPUOptimizedChangeSet;
import com.boydti.fawe.object.changeset.FaweStreamChangeSet; import com.boydti.fawe.object.changeset.FaweStreamChangeSet;
import com.boydti.fawe.object.io.AbstractDelegateOutputStream;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.DoubleTag; import com.sk89q.jnbt.DoubleTag;
import com.sk89q.jnbt.EndTag; import com.sk89q.jnbt.EndTag;
@ -281,7 +282,11 @@ public class MainUtil {
writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(filename)).append(CRLF); writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(filename)).append(CRLF);
writer.append("Content-Transfer-Encoding: binary").append(CRLF); writer.append("Content-Transfer-Encoding: binary").append(CRLF);
writer.append(CRLF).flush(); writer.append(CRLF).flush();
writeTask.value = output; OutputStream nonClosable = new AbstractDelegateOutputStream(output) {
@Override
public void close() throws IOException { } // Don't close
};
writeTask.value = nonClosable;
writeTask.run(); writeTask.run();
output.flush(); output.flush();
writer.append(CRLF).flush(); writer.append(CRLF).flush();