Last active
January 21, 2021 23:06
-
-
Save luben/0b0e21feb8f359a0b36a74977f1b4f9a to your computer and use it in GitHub Desktop.
Test Zstd leak
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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