Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use unsynchronized buffered OutputStream for history #2127

Merged
merged 3 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ public OutputStream getParent() {
return parent;
}

// overwritten to un-synchronized
@Override
public void write(final int b) throws IOException {
out.write(b);
written++;
}

public void write(int b, int amount) throws IOException {
for (int i = 0; i < amount; i++) {
write(b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.formatting.text.Component;
import it.unimi.dsi.fastutil.io.FastBufferedInputStream;
import it.unimi.dsi.fastutil.io.FastBufferedOutputStream;
import net.jpountz.lz4.LZ4BlockInputStream;
import net.jpountz.lz4.LZ4BlockOutputStream;
import net.jpountz.lz4.LZ4Compressor;
Expand All @@ -40,7 +41,6 @@
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -273,9 +273,12 @@ public static byte[] decompress(byte[] bytes, byte[] buffer, int length, int lev
return buffer;
}

/**
* Note: The returned stream is not thread safe.
*/
public static FaweOutputStream getCompressedOS(OutputStream os, int amount, int buffer) throws IOException {
os.write((byte) 10 + amount);
os = new BufferedOutputStream(os, buffer);
os = new FastBufferedOutputStream(os, buffer);
if (amount == 0) {
return new FaweOutputStream(os);
}
Expand All @@ -296,7 +299,7 @@ public static FaweOutputStream getCompressedOS(OutputStream os, int amount, int
os = new LZ4BlockOutputStream(os, buffer, factory.highCompressor());
}
}
os = new BufferedOutputStream(os, buffer);
os = new FastBufferedOutputStream(os, buffer);
return new FaweOutputStream(os);
}

Expand Down