java.lang.OutOfMemoryError: Java heap space while creating ZIP archives in Google App Engine

196 views
Skip to first unread message

Ibrahim Ali

unread,
May 17, 2019, 12:47:56 PM5/17/19
to Google App Engine
Creating ZIP archives in Google App Engine (Java) <br />
I am got this error in the gae cloud logs:  <br>

java.lang.OutOfMemoryError: Java heap space <br>
at java.util.Arrays.copyOf(Arrays.java:2271)
at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:113) 
at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)
at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:140)
<br><br>

I face this problem when zipping many files on the production server, 
so what should I do to fix it ? is there something can help in GAE 
or can I save zip file containing one file on the storage then open 
and edit it ? ( to min memory usage) 

    ByteArrayOutputStream zipBaos = new ByteArrayOutputStream();
    ZipOutputStream zipOut = new ZipOutputStream(zipBaos);
    byte[] tmpBuf = new byte[1024];

while end of files{ byte[] fileContents = getFileContent(); // it is OK zipOut.putNextEntry(new ZipEntry(fileNameStr)); ByteArrayInputStream in = new ByteArrayInputStream(fileContents); int len; while ((len = in.read(tmpBuf)) > 0) { out.write(tmpBuf, 0, len); } zipOut.closeEntry(); } zipOut.close();
Reply all
Reply to author
Forward
0 new messages