Skip to content

Instantly share code, notes, and snippets.

@luben
Last active January 21, 2021 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luben/0b0e21feb8f359a0b36a74977f1b4f9a to your computer and use it in GitHub Desktop.
Save luben/0b0e21feb8f359a0b36a74977f1b4f9a to your computer and use it in GitHub Desktop.
Test Zstd leak
package com.github.luben.zstd;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.charset.Charset;
import java.util.Random;
public class TestLeak {
static byte[] copy_buf = new byte[8192];
static void copy(InputStream source, OutputStream target) throws IOException {
int length;
while ((length = source.read(copy_buf)) > 0) {
target.write(copy_buf, 0, length);
}
}
public static void main(String[] args) throws IOException {
byte[] array = new byte[100];
new Random().nextBytes(array);
Path tempPath = Files.createTempFile("test", "test");
for (int i = 0; i < 10000000; i++) {
try (ZstdOutputStream zstdOutput = new ZstdOutputStream(new FileOutputStream(tempPath.toFile()), RecyclingBufferPool.INSTANCE);
InputStream inputStream = new ByteArrayInputStream(array)) {
copy(inputStream, zstdOutput);
//System.out.println("TEST");
//zstdOutput.close();
//System.gc();
} finally {
Files.deleteIfExists(tempPath);
}
}
System.out.println("Done!!!!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment