java.lang.OutOfMemoryError:在Google App Engine中创建ZIP存档时出现Java堆空间

时间:2019-05-17 13:35:11

标签: java 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>

在生产服务器上压缩许多文件时,我会遇到此问题,
那么我该怎么做才能解决它?在GAE中有什么可以帮助的吗?或者我可以将包含一个文件的zip文件保存到存储中,然后打开
进行编辑? (以减少内存使用量)     
    

    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(); </pre>

0 个答案:

没有答案