I have following method to zip some data as 'file' (practically this is byte array) in memory.
Result will be saved in database therefore i need this array (method returns byte[]).
How can i unzip - data saved as zipped file in memory? I expect exactly what i gave as param 'data' in zip method.
public static byte[] zip(String name, String data) {
ByteArrayOutputStream baos = null;
ZipOutputStream zos = null;
try {
baos = new ByteArrayOutputStream();
zos = new ZipOutputStream(baos);
ZipEntry zipEntry = new ZipEntry(name);
byte[] bytes = data.getBytes();
zipEntry.setSize(bytes.length);
zos.putNextEntry(zipEntry);
zos.write(bytes);
return baos.toByteArray();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (Objects.nonNull(zos)) {
try {
zos.closeEntry();
} catch (IOException e) {
e.printStackTrace();
}
try {
zos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (Objects.nonNull(baos)) {
try {
baos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
throw new RuntimeException();
}