I've got a small function that reads a zip file from an input stream and then stores the contents in an arraylist. I'm using GAE which is limited to files less than 1mb. I've converted the InputStream into a BlobstoreInputStream so I can now upload zip files that are > 1mb. However I can still only access < 1Mb of data from it or I get an error*. I think I need to chain together multiple <1mb reads of the BlogstoreInputStream but I don't know how to do this.
My code which works for any zip file < 1mb in size is below. No file within the zip file will ever be more than 1mb.
I'm not too clued up on inputstreams so if anyone can help me with this or point me in the right direction I will appreciate it.
private void setZipItems() throws IOException, Exception {
BlobstoreInputStream in = new BlobstoreInputStream(blobKey);
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(in));
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
ZipItem item = new ZipItem();
item.fileName = entry.getName();
ByteArrayOutputStream contents = new ByteArrayOutputStream();
int size;
byte[] buffer = new byte[1024];
while ((size = zis.read(buffer)) != -1) {
if (size != buffer.length) {
for (int i = 0 ; i < size; i ++)
contents.write(buffer[i]);
} else contents.write(buffer);
}
zis.closeEntry();
item.contents = contents.toByteArray();
zipItems.add(item);
}
zis.close();
in.close();
}
*BlobstoreInputStream BlobstoreIOException: "Blob Fetch Size too large" and occurs at
while ((entry = zis.getNextEntry()) != null).
On first run with blobstore entities larger than 1mb.