use of org.mifos.framework.image.service.ClientPhotoService in project head by mifos.
the class PictureFormFile method retrievePicture.
@TransactionDemarcate(joinToken = true)
public ActionForward retrievePicture(ActionMapping mapping, @SuppressWarnings("unused") ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
ClientBO clientBO = getClientFromSession(request);
ClientPhotoService cps = ApplicationContextProvider.getBean(ClientPhotoService.class);
ClientPhoto cp = cps.read(clientBO.getCustomerId().longValue());
InputStream in = null;
if (cp != null) {
in = new ByteArrayInputStream(cps.getData(cp));
response.setContentType(cp.getImageInfo().getContentType());
} else {
in = ClientPhotoService.class.getResourceAsStream("/org/mifos/image/nopicture.png");
response.setContentType("image/png");
}
in.mark(0);
BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
// 4K buffer buf, 0, buf.length
byte[] by = new byte[1024 * 4];
int index = in.read(by, 0, 1024 * 4);
while (index != -1) {
out.write(by, 0, index);
index = in.read(by, 0, 1024 * 4);
}
out.flush();
out.close();
in.reset();
String forward = ClientConstants.CUSTOMER_PICTURE_PAGE;
return mapping.findForward(forward);
}
Aggregations