SteamWar/SpigotCore
Archiviert
13
0

Do not buffer schematic content in RAM during writing #123

Geschlossen
Lixfel möchte 1 Commits von ramLessSchemStorage nach schematic-node mergen
3 geänderte Dateien mit 52 neuen und 26 gelöschten Zeilen

Datei anzeigen

@ -29,10 +29,9 @@ import com.sk89q.worldedit.world.registry.LegacyMapper;
import de.steamwar.sql.NoClipboardException;
import org.bukkit.entity.Player;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.util.*;
import java.util.logging.Level;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull;
@ -43,7 +42,7 @@ public class WorldEditWrapper14 implements WorldEditWrapper.IWorldEditWrapper {
private static final ClipboardFormat SCHEM = BuiltInClipboardFormat.SPONGE_SCHEMATIC;
@Override
public byte[] getPlayerClipboard(Player player, boolean schemFormat) {
public InputStream getPlayerClipboard(Player player, boolean schemFormat) {
ClipboardHolder clipboardHolder;
try {
clipboardHolder = WorldEditWrapper.getWorldEditPlugin().getSession(player).getClipboard();
@ -55,21 +54,34 @@ public class WorldEditWrapper14 implements WorldEditWrapper.IWorldEditWrapper {
if(clipboard == null)
throw new NoClipboardException();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try{
if(schemFormat){
ClipboardWriter writer = SCHEM.getWriter(outputStream);
writer.write(clipboard);
writer.close();
}else{
SCHEMATIC.getWriter(outputStream).write(clipboard);
}
}catch(NullPointerException e){
throw new RuntimeException(e.getMessage(), new IOException(e));
PipedOutputStream outputStream = new PipedOutputStream();
PipedInputStream inputStream;
try {
inputStream = new PipedInputStream(outputStream, 4096);
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
throw new SecurityException("Could not init piped input stream", e);
}
return outputStream.toByteArray();
new Thread(() -> {
try{
if(schemFormat){
ClipboardWriter writer = SCHEM.getWriter(outputStream);
writer.write(clipboard);
writer.close();
}else{
SCHEMATIC.getWriter(outputStream).write(clipboard);
}
}catch(NullPointerException | IOException e) {
Core.getInstance().getLogger().log(Level.SEVERE, "Could not write schematic", e);
}
try {
outputStream.close();
} catch (IOException e) {
Core.getInstance().getLogger().log(Level.SEVERE, "Could not close schem writer", e);
}
}, "SchemWriter").start();
return inputStream;
}
@Override

Datei anzeigen

@ -19,19 +19,18 @@ import com.sk89q.worldedit.world.registry.WorldData;
import de.steamwar.sql.NoClipboardException;
import org.bukkit.entity.Player;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.stream.Collectors;
public class WorldEditWrapper8 implements WorldEditWrapper.IWorldEditWrapper {
@Override
public byte[] getPlayerClipboard(Player player, boolean schemFormat) {
public InputStream getPlayerClipboard(Player player, boolean schemFormat) {
ClipboardHolder clipboardHolder;
try {
clipboardHolder = WorldEditWrapper.getWorldEditPlugin().getSession(player).getClipboard();
@ -43,13 +42,28 @@ public class WorldEditWrapper8 implements WorldEditWrapper.IWorldEditWrapper {
if(clipboard == null)
throw new NoClipboardException();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PipedOutputStream outputStream = new PipedOutputStream();
PipedInputStream inputStream;
try {
ClipboardFormat.SCHEMATIC.getWriter(outputStream).write(clipboard, clipboardHolder.getWorldData());
inputStream = new PipedInputStream(outputStream, 4096);
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
throw new SecurityException("Could not init piped input stream", e);
}
return outputStream.toByteArray();
new Thread(() -> {
try {
ClipboardFormat.SCHEMATIC.getWriter(outputStream).write(clipboard, clipboardHolder.getWorldData());
} catch (IOException e) {
Core.getInstance().getLogger().log(Level.SEVERE, "Could not write schematic", e);
}
try {
outputStream.close();
} catch (IOException e) {
Core.getInstance().getLogger().log(Level.SEVERE, "Could not close schem writer", e);
}
}, "SchemWriter").start();
return inputStream;
}
@Override

Datei anzeigen

@ -14,7 +14,7 @@ public class WorldEditWrapper {
public static final IWorldEditWrapper impl = VersionDependent.getVersionImpl(Core.getInstance());
public interface IWorldEditWrapper {
byte[] getPlayerClipboard(Player player, boolean schemFormat);
InputStream getPlayerClipboard(Player player, boolean schemFormat);
void setPlayerClipboard(Player player, InputStream is, boolean schemFormat);
Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException;