0

I have understood how to read/parse a ZIP file from FILE.ZIP in java. I have a base64 String of a zipfile. So It is not needed to save the file on disk. Just handle in memory

BUT It is needed to receive from web request a container.zip in Json/String whatever format, open and parse it and send back to client also as container.zip

The question is, what is a better way to read/parse/unzip String in memory without saving it on PC? And how to Zip The Json/String back to arhchive.zip, but not as FiLE, but as Object or String to send it back?

Daniel
  • 23
  • 1
  • 2
  • 6
  • What are you using for zipping/unzipping? The Old `ZipInputStream` and `ZipOuputStream` classes work with standard streams, no need for a file!? – xander Apr 09 '18 at 13:19
  • Zipfile.zip can be an inputStream. How to handle the zipping/unzipping in memory without a saving a file? – Daniel Apr 09 '18 at 13:23
  • I don't know what code you have, but if you have basic Java IO Stream knowledge you should be able to figure it out. Just don't use a `FileInputStream`. There also is a `ByteArrayInputStream` so you can simply use a string or whatever format your data is in and read it through an `InputStream`. – xander Apr 09 '18 at 13:27
  • Like this: `new ZipInputStream(new ByteArrayInputStream(yourDataString.getBytes(StandardCharsets.UTF_8)));` – xander Apr 09 '18 at 13:31
  • Hello and welcome to StackOverflow. Please take some time to read the help page, especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). And more importantly, please read [the Stack Overflow question checklist](http://meta.stackexchange.com/q/156810/204922). You might also want to learn about [Minimal, Complete, and Verifiable Examples](http://stackoverflow.com/help/mcve). – lexicore Apr 09 '18 at 13:50
  • You can zip to/unzip from a byte array (`byte[]`), just use `ByteArrayOutputStream` or `ByteArrayInputStream` as target or source. – lexicore Apr 09 '18 at 13:51

0 Answers0