Creating a zip of a particular rendition of assets in aem
I have a list if inputStream as below which contains the stream of a particular rendition of an asset. assetResourceList is a global list<beanclass> object.
private void createZipFile( ) throws IOException {
List<InputStream> inputStreamList = new ArrayList<InputStream>();
for(Resource assetResource:assetResourceList)
{
final Asset asset = DamUtil.resolveToAsset(assetResource);
InputStream in = asset.getRendition("cq5dam.thumbnail.48.48.png").getStream();
inputStreamList.add(in);
}
}
How can i convert this inputstream to a zip of images?
I used the below code for the same, but the zip is getting created with filetype and when i open the zip, it says file format not supported. Can someone help.
private void createZipFile() throws IOException {
List<InputStream> inputStreamList = new ArrayList<InputStream>();
for(Resource assetResource:assetResourceList)
{
final Asset asset = DamUtil.resolveToAsset(assetResource);
InputStream in = asset.getRendition(DAM_THUMBNAIL).getStream();
inputStreamList.add(in);
}
try (
ZipOutputStream zos = new ZipOutputStream(
new FileOutputStream("C:\\Project\\TestZip\\assets.zip"));
) {
int count =0;
for(InputStream in:inputStreamList){
ZipEntry ze = new ZipEntry("image"+count++);
zos.putNextEntry(ze);
byte[] tmp = new byte[4*1024];
int size = 0;
while((size = in.read(tmp)) != -1){
zos.write(tmp, 0, size);
}
zos.flush();
in.close();
}
// zos.close();
}
