Search in sources :

Example 1 with ClientPhotoService

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);
}
Also used : ClientPhoto(org.mifos.framework.image.domain.ClientPhoto) ClientPhotoService(org.mifos.framework.image.service.ClientPhotoService) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ClientBO(org.mifos.customers.client.business.ClientBO) BufferedOutputStream(java.io.BufferedOutputStream) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ClientBO (org.mifos.customers.client.business.ClientBO)1 ClientPhoto (org.mifos.framework.image.domain.ClientPhoto)1 ClientPhotoService (org.mifos.framework.image.service.ClientPhotoService)1 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)1