@Test public void testAddImagesToZipFile() throws IOException { String imageIds[] = { "", "", "" }; MockHttpSession session = new MockHttpSession(); MockHttpServletResponse response = new MockHttpServletResponse(); UniqueIndexedCache<BufferedImage> imgCache = ClientCache .getClientCache(session).getImgCache(); imageIds[0] = imgCache.storeItem(PC_IMG); imageIds[1] = imgCache.storeItem(PC_IMG); imageIds[2] = null; String deviceIds[] = { "000000000001", "000000000002", "000000000003" }; int expectedZipSizeInBytes = 28954; VideoSnap videoSnap = new VideoSnap(); videoSnap.addImagesToZipFile(imageIds, deviceIds, response, session); Assert.assertEquals(response.getContentType(), "application/zip", "Content type is not in zip format"); String header = response.getHeader("Content-Disposition"); Assert.assertTrue(header.contains("attachment"), "Response header does not indicates attachment"); Assert.assertTrue(header.contains(".zip"), "Attached file is not in zip format"); Assert.assertEquals(response.getContentAsByteArray().length, expectedZipSizeInBytes, "Zip file size in http response is not matching with expected zip size."); }
public void addImagesToZipFile(String[] capturedImageIds, String[] deviceMacs, HttpServletResponse response, HttpSession session) { UniqueIndexedCache<BufferedImage> imgCache = getClientCache(session) .getImgCache(); response.setHeader("Content-Disposition", "attachment; filename=\"" + "Images_" + getCurrentDateAndTime() + ".zip\""); response.setContentType("application/zip"); ServletOutputStream serveletOutputStream = null; ZipOutputStream zipOutputStream = null; try { serveletOutputStream = response.getOutputStream(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); zipOutputStream = new ZipOutputStream(byteArrayOutputStream); BufferedImage image; ZipEntry zipEntry; ByteArrayOutputStream imgByteArrayOutputStream = null; for (int i = 0; i < deviceMacs.length; i++) { if (!StringUtils.isEmpty(capturedImageIds[i])) { image = imgCache.getItem(capturedImageIds[i]); zipEntry = new ZipEntry(deviceMacs[i].toUpperCase() + "." + IMG_FORMAT); zipOutputStream.putNextEntry(zipEntry); imgByteArrayOutputStream = new ByteArrayOutputStream(); ImageIO.write(image, IMG_FORMAT, imgByteArrayOutputStream); imgByteArrayOutputStream.flush(); zipOutputStream.write(imgByteArrayOutputStream.toByteArray()); zipOutputStream.closeEntry(); } } zipOutputStream.flush(); zipOutputStream.close(); serveletOutputStream.write(byteArrayOutputStream.toByteArray()); } catch (IOException ioe) { LOGGER.error("Image zipping failed !!!", ioe); } finally { IOUtils.closeQuietly(zipOutputStream); } }
VideoSnap { public void addImagesToZipFile(String[] capturedImageIds, String[] deviceMacs, HttpServletResponse response, HttpSession session) { UniqueIndexedCache<BufferedImage> imgCache = getClientCache(session) .getImgCache(); response.setHeader("Content-Disposition", "attachment; filename=\"" + "Images_" + getCurrentDateAndTime() + ".zip\""); response.setContentType("application/zip"); ServletOutputStream serveletOutputStream = null; ZipOutputStream zipOutputStream = null; try { serveletOutputStream = response.getOutputStream(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); zipOutputStream = new ZipOutputStream(byteArrayOutputStream); BufferedImage image; ZipEntry zipEntry; ByteArrayOutputStream imgByteArrayOutputStream = null; for (int i = 0; i < deviceMacs.length; i++) { if (!StringUtils.isEmpty(capturedImageIds[i])) { image = imgCache.getItem(capturedImageIds[i]); zipEntry = new ZipEntry(deviceMacs[i].toUpperCase() + "." + IMG_FORMAT); zipOutputStream.putNextEntry(zipEntry); imgByteArrayOutputStream = new ByteArrayOutputStream(); ImageIO.write(image, IMG_FORMAT, imgByteArrayOutputStream); imgByteArrayOutputStream.flush(); zipOutputStream.write(imgByteArrayOutputStream.toByteArray()); zipOutputStream.closeEntry(); } } zipOutputStream.flush(); zipOutputStream.close(); serveletOutputStream.write(byteArrayOutputStream.toByteArray()); } catch (IOException ioe) { LOGGER.error("Image zipping failed !!!", ioe); } finally { IOUtils.closeQuietly(zipOutputStream); } } }
VideoSnap { public void addImagesToZipFile(String[] capturedImageIds, String[] deviceMacs, HttpServletResponse response, HttpSession session) { UniqueIndexedCache<BufferedImage> imgCache = getClientCache(session) .getImgCache(); response.setHeader("Content-Disposition", "attachment; filename=\"" + "Images_" + getCurrentDateAndTime() + ".zip\""); response.setContentType("application/zip"); ServletOutputStream serveletOutputStream = null; ZipOutputStream zipOutputStream = null; try { serveletOutputStream = response.getOutputStream(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); zipOutputStream = new ZipOutputStream(byteArrayOutputStream); BufferedImage image; ZipEntry zipEntry; ByteArrayOutputStream imgByteArrayOutputStream = null; for (int i = 0; i < deviceMacs.length; i++) { if (!StringUtils.isEmpty(capturedImageIds[i])) { image = imgCache.getItem(capturedImageIds[i]); zipEntry = new ZipEntry(deviceMacs[i].toUpperCase() + "." + IMG_FORMAT); zipOutputStream.putNextEntry(zipEntry); imgByteArrayOutputStream = new ByteArrayOutputStream(); ImageIO.write(image, IMG_FORMAT, imgByteArrayOutputStream); imgByteArrayOutputStream.flush(); zipOutputStream.write(imgByteArrayOutputStream.toByteArray()); zipOutputStream.closeEntry(); } } zipOutputStream.flush(); zipOutputStream.close(); serveletOutputStream.write(byteArrayOutputStream.toByteArray()); } catch (IOException ioe) { LOGGER.error("Image zipping failed !!!", ioe); } finally { IOUtils.closeQuietly(zipOutputStream); } }  }
VideoSnap { public void addImagesToZipFile(String[] capturedImageIds, String[] deviceMacs, HttpServletResponse response, HttpSession session) { UniqueIndexedCache<BufferedImage> imgCache = getClientCache(session) .getImgCache(); response.setHeader("Content-Disposition", "attachment; filename=\"" + "Images_" + getCurrentDateAndTime() + ".zip\""); response.setContentType("application/zip"); ServletOutputStream serveletOutputStream = null; ZipOutputStream zipOutputStream = null; try { serveletOutputStream = response.getOutputStream(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); zipOutputStream = new ZipOutputStream(byteArrayOutputStream); BufferedImage image; ZipEntry zipEntry; ByteArrayOutputStream imgByteArrayOutputStream = null; for (int i = 0; i < deviceMacs.length; i++) { if (!StringUtils.isEmpty(capturedImageIds[i])) { image = imgCache.getItem(capturedImageIds[i]); zipEntry = new ZipEntry(deviceMacs[i].toUpperCase() + "." + IMG_FORMAT); zipOutputStream.putNextEntry(zipEntry); imgByteArrayOutputStream = new ByteArrayOutputStream(); ImageIO.write(image, IMG_FORMAT, imgByteArrayOutputStream); imgByteArrayOutputStream.flush(); zipOutputStream.write(imgByteArrayOutputStream.toByteArray()); zipOutputStream.closeEntry(); } } zipOutputStream.flush(); zipOutputStream.close(); serveletOutputStream.write(byteArrayOutputStream.toByteArray()); } catch (IOException ioe) { LOGGER.error("Image zipping failed !!!", ioe); } finally { IOUtils.closeQuietly(zipOutputStream); } }  void addImagesToZipFile(String[] capturedImageIds, String[] deviceMacs, HttpServletResponse response, HttpSession session); void saveSnappedImage(String imgId, String deviceId,
            HttpServletResponse response, HttpSession session); String captureImage(String deviceId, HttpSession session,
            MetaStbCache metaStbCache); Map<String, String> getCaptureImageIds(String[] deviceIds, HttpSession session, MetaStbCache metaStbCache); }
VideoSnap { public void addImagesToZipFile(String[] capturedImageIds, String[] deviceMacs, HttpServletResponse response, HttpSession session) { UniqueIndexedCache<BufferedImage> imgCache = getClientCache(session) .getImgCache(); response.setHeader("Content-Disposition", "attachment; filename=\"" + "Images_" + getCurrentDateAndTime() + ".zip\""); response.setContentType("application/zip"); ServletOutputStream serveletOutputStream = null; ZipOutputStream zipOutputStream = null; try { serveletOutputStream = response.getOutputStream(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); zipOutputStream = new ZipOutputStream(byteArrayOutputStream); BufferedImage image; ZipEntry zipEntry; ByteArrayOutputStream imgByteArrayOutputStream = null; for (int i = 0; i < deviceMacs.length; i++) { if (!StringUtils.isEmpty(capturedImageIds[i])) { image = imgCache.getItem(capturedImageIds[i]); zipEntry = new ZipEntry(deviceMacs[i].toUpperCase() + "." + IMG_FORMAT); zipOutputStream.putNextEntry(zipEntry); imgByteArrayOutputStream = new ByteArrayOutputStream(); ImageIO.write(image, IMG_FORMAT, imgByteArrayOutputStream); imgByteArrayOutputStream.flush(); zipOutputStream.write(imgByteArrayOutputStream.toByteArray()); zipOutputStream.closeEntry(); } } zipOutputStream.flush(); zipOutputStream.close(); serveletOutputStream.write(byteArrayOutputStream.toByteArray()); } catch (IOException ioe) { LOGGER.error("Image zipping failed !!!", ioe); } finally { IOUtils.closeQuietly(zipOutputStream); } }  void addImagesToZipFile(String[] capturedImageIds, String[] deviceMacs, HttpServletResponse response, HttpSession session); void saveSnappedImage(String imgId, String deviceId,
            HttpServletResponse response, HttpSession session); String captureImage(String deviceId, HttpSession session,
            MetaStbCache metaStbCache); Map<String, String> getCaptureImageIds(String[] deviceIds, HttpSession session, MetaStbCache metaStbCache);  }