Reputation: 365
I have a simple method that creates a tar file with a collection of compressed files inside:
private byte[] gzipCompress() throws IOException {
File source = super.getPath();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (GZIPOutputStream gos = new GZIPOutputStream(baos)) {
Files.copy(source.toPath(), gos);
}
return baos.toByteArray();
}
When the file is large (not sure of exact size 1GB maybe) - this method causes an error:
Caused by: java.lang.OutOfMemoryError: Java heap space
Seems similar to this question - java nio Files.copy thowing Java heap space out of memory, but is there some other alternative to the IOUtils.copyLarge
solution.
Upvotes: 0
Views: 677