@Test public void testSaveSnappedImage() throws IOException { String deviceId = "000000000001"; MockHttpSession session = new MockHttpSession(); MockHttpServletResponse response = new MockHttpServletResponse(); UniqueIndexedCache<BufferedImage> imgCache = ClientCache .getClientCache(session).getImgCache(); String imageId = imgCache.storeItem(PC_IMG); VideoSnap videoSnap = new VideoSnap(); videoSnap.saveSnappedImage(imageId, deviceId, response, session); String header = response.getHeader("Content-Disposition"); Assert.assertTrue(header.contains("attachment"),"Response header does not indicates attachment"); Assert.assertTrue(header.contains(".jpg"),"Attached file is not in jpg format"); ByteArrayOutputStream bao = new ByteArrayOutputStream(); ImageIO.write(PC_IMG, "jpg", bao); Assert.assertEquals(response.getContentAsByteArray(), bao.toByteArray(), "Saved image size is not matching with expected size"); }
public void saveSnappedImage(String imgId, String deviceId, HttpServletResponse response, HttpSession session) throws IOException { String suffixName = getCurrentDateAndTime(); String fileName = deviceId.toUpperCase() + "_" + suffixName + "." + IMG_FORMAT; response.setHeader("Content-Disposition", "attachment;filename=" + fileName); UniqueIndexedCache<BufferedImage> imgCache = getClientCache(session) .getImgCache(); BufferedImage img = imgCache.getItem(imgId); if (img != null) { OutputStream stream = response.getOutputStream(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ImageIO.write(img, IMG_FORMAT, byteArrayOutputStream); byteArrayOutputStream.flush(); byte[] bytes = byteArrayOutputStream.toByteArray(); stream.write(bytes); response.flushBuffer(); } else { LOGGER.error("Could not retrieve the captured image!!!"); } }
VideoSnap { public void saveSnappedImage(String imgId, String deviceId, HttpServletResponse response, HttpSession session) throws IOException { String suffixName = getCurrentDateAndTime(); String fileName = deviceId.toUpperCase() + "_" + suffixName + "." + IMG_FORMAT; response.setHeader("Content-Disposition", "attachment;filename=" + fileName); UniqueIndexedCache<BufferedImage> imgCache = getClientCache(session) .getImgCache(); BufferedImage img = imgCache.getItem(imgId); if (img != null) { OutputStream stream = response.getOutputStream(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ImageIO.write(img, IMG_FORMAT, byteArrayOutputStream); byteArrayOutputStream.flush(); byte[] bytes = byteArrayOutputStream.toByteArray(); stream.write(bytes); response.flushBuffer(); } else { LOGGER.error("Could not retrieve the captured image!!!"); } } }
VideoSnap { public void saveSnappedImage(String imgId, String deviceId, HttpServletResponse response, HttpSession session) throws IOException { String suffixName = getCurrentDateAndTime(); String fileName = deviceId.toUpperCase() + "_" + suffixName + "." + IMG_FORMAT; response.setHeader("Content-Disposition", "attachment;filename=" + fileName); UniqueIndexedCache<BufferedImage> imgCache = getClientCache(session) .getImgCache(); BufferedImage img = imgCache.getItem(imgId); if (img != null) { OutputStream stream = response.getOutputStream(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ImageIO.write(img, IMG_FORMAT, byteArrayOutputStream); byteArrayOutputStream.flush(); byte[] bytes = byteArrayOutputStream.toByteArray(); stream.write(bytes); response.flushBuffer(); } else { LOGGER.error("Could not retrieve the captured image!!!"); } }  }
VideoSnap { public void saveSnappedImage(String imgId, String deviceId, HttpServletResponse response, HttpSession session) throws IOException { String suffixName = getCurrentDateAndTime(); String fileName = deviceId.toUpperCase() + "_" + suffixName + "." + IMG_FORMAT; response.setHeader("Content-Disposition", "attachment;filename=" + fileName); UniqueIndexedCache<BufferedImage> imgCache = getClientCache(session) .getImgCache(); BufferedImage img = imgCache.getItem(imgId); if (img != null) { OutputStream stream = response.getOutputStream(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ImageIO.write(img, IMG_FORMAT, byteArrayOutputStream); byteArrayOutputStream.flush(); byte[] bytes = byteArrayOutputStream.toByteArray(); stream.write(bytes); response.flushBuffer(); } else { LOGGER.error("Could not retrieve the captured image!!!"); } }  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 saveSnappedImage(String imgId, String deviceId, HttpServletResponse response, HttpSession session) throws IOException { String suffixName = getCurrentDateAndTime(); String fileName = deviceId.toUpperCase() + "_" + suffixName + "." + IMG_FORMAT; response.setHeader("Content-Disposition", "attachment;filename=" + fileName); UniqueIndexedCache<BufferedImage> imgCache = getClientCache(session) .getImgCache(); BufferedImage img = imgCache.getItem(imgId); if (img != null) { OutputStream stream = response.getOutputStream(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ImageIO.write(img, IMG_FORMAT, byteArrayOutputStream); byteArrayOutputStream.flush(); byte[] bytes = byteArrayOutputStream.toByteArray(); stream.write(bytes); response.flushBuffer(); } else { LOGGER.error("Could not retrieve the captured image!!!"); } }  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);  }