Our external application sends the zip file name and content as two strings in the response to an API call. I converted the string to bytearray and used zipinputstream to read the bytearray. If the zip file contains only one file, I am able to read the string and extract the zipped file contents into a separate string. Below is the code snippet I used to extract the file content.
If the zipped file contains more than one file and the entire zipped content is sent as a single string, how do I extract individual file contents into separate strings? How to identify the end of each file in the string?
byte[] data = Base64Util.decodeToByteArray(ZipString);
ByteArrayInputStream bais = new ByteArrayInputStream(data);
ZipInputStream zin = new ZipInputStream(new BufferedInputStream(bais));
ZipEntry ze = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] b = new byte[4096];
String ZippedFileName = new String();
String ZippedFileData = new String();
try
{
while((ze = zin.getNextEntry()) != null)
{
ZippedFileName = ze.getName();
while((zin.read(b,0,4096))!= -1)
{
baos.write(b,0,4096);
}
}
byte[] out = baos.toByteArray();
ZippedFileData = Base64Util.encodeToString(out);
zin.close();
bais.close();
baos.close();
}
catch(Exception Ex)
{
Ex.toString();
}