compression speed improvements

This commit is contained in:
LAX1DUDE 2022-08-02 01:55:42 -07:00
parent a013bf69b1
commit 36d7d767dd
3 changed files with 15 additions and 2 deletions

View File

@ -16,7 +16,6 @@ public class EPKCompiler {
public EPKCompiler(String name) { public EPKCompiler(String name) {
try { try {
d = new Deflater(9);
os = new DataOutputStream(osb); os = new DataOutputStream(osb);
os.write("EAGPKG!!".getBytes(Charset.forName("UTF-8"))); os.write("EAGPKG!!".getBytes(Charset.forName("UTF-8")));
os.writeUTF("\n\n # eaglercraft package file - " + name + "\n # eagler eagler eagler eagler eagler eagler eagler\n\n"); os.writeUTF("\n\n # eaglercraft package file - " + name + "\n # eagler eagler eagler eagler eagler eagler eagler\n\n");

View File

@ -89,7 +89,7 @@ public class VFSChunkLoader implements IChunkLoader {
try { try {
NBTTagCompound chunkFileSave = new NBTTagCompound(); NBTTagCompound chunkFileSave = new NBTTagCompound();
chunkFileSave.setCompoundTag("Level", chunkFile); chunkFileSave.setCompoundTag("Level", chunkFile);
save = CompressedStreamTools.compress(chunkFileSave); save = CompressedStreamTools.compressChunk(chunkFileSave);
}catch(IOException e) { }catch(IOException e) {
System.err.println("Corrupted chunk could not be serialized: [" + var2.xPosition + ", " + var2.zPosition + "]"); System.err.println("Corrupted chunk could not be serialized: [" + var2.xPosition + ", " + var2.zPosition + "]");
return; return;

View File

@ -12,6 +12,7 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Collection; import java.util.Collection;
import com.jcraft.jzlib.Deflater;
import com.jcraft.jzlib.GZIPInputStream; import com.jcraft.jzlib.GZIPInputStream;
import com.jcraft.jzlib.GZIPOutputStream; import com.jcraft.jzlib.GZIPOutputStream;
@ -73,6 +74,19 @@ public class CompressedStreamTools {
return var1.toByteArray(); return var1.toByteArray();
} }
public static byte[] compressChunk(NBTTagCompound par0NBTTagCompound) throws IOException {
ByteArrayOutputStream var1 = new ByteArrayOutputStream();
DataOutputStream var2 = new DataOutputStream(new GZIPOutputStream(var1, new Deflater(2, 15+16), 2048, true));
try {
write(par0NBTTagCompound, var2);
} finally {
var2.close();
}
return var1.toByteArray();
}
/** /**
* Reads from a CompressedStream. * Reads from a CompressedStream.
*/ */