I have a 1-2GB zip file with records 500-1000k. I need to get files by name in a split second, without fully unpacking. If the file is stored on the hard drive, this works fine:
public class ZipMapper { private HashMap<String,ZipEntry> map; private ZipFile zf; public ZipMapper(File file) throws IOException { map = new HashMap<>(); zf = new ZipFile(file); Enumeration<? extends ZipEntry> en = zf.entries(); while(en.hasMoreElements()) { ZipEntry ze = en.nextElement(); map.put(ze.getName(), ze); } } public Node getNode(String key) throws IOException { return Node.loadFromStream(zf.getInputStream(map.get(key))); } }
But what should I do if the program downloaded a zip file from Amazon S3 and has its own InputStream (or an array of bytes)? When loading, 1 GB takes ~ 1 second, recording to the hard drive may take some time, and it is a little more difficult to process several files, since we do not have a garbage collector on the hard drive.
ZipInputStream does not allow random access to records.
It would be nice to create a virtual file in memory by byte array, but I could not find a way.
user1766873
source share