hash = ParametredHttpServlet.computeHash(buffer); etag = ParametredHttpServlet.computeETag(buffer);
hash = ConfiguredHttpServlet.computeHash(buffer); etag = ConfiguredHttpServlet.computeETag(buffer);
    public void initialize(IImageLoader imageDownloader,            String externalContentType, RenderedImage renderedImage,            ImageWriter imageWriter, int destImageType) throws IOException {        if (LOG.isTraceEnabled()) {            LOG.trace("Initialize fileRenderedImage '" + imageName                    + "' imageType="                    + ((BufferedImage) renderedImage).getType() + ".");        }        this.contentType = externalContentType;        try {            file = File.createTempFile(TEMP_FILE_PREFIX, TEMP_FILE_SUFFIX);        } catch (IOException ex) {            LOG.error(                    "Can not create temp file for filtered image ! (imageName="                            + imageName + ")", ex);            throw ex;        }        if (LOG.isTraceEnabled()) {            LOG.trace("Temp file associated to url '" + imageName + "' is "                    + file.getAbsolutePath());        }        try {            file.deleteOnExit();        } catch (SecurityException ex) {            if (securityError == false) {                securityError = true;                LOG.error(ex);            }        }        int size = 8000;        long originalSize = imageDownloader.getContentLength();        if (originalSize > 0 && originalSize < 8000) {            size = (int) originalSize + 256;        }        ByteArrayOutputStream bous = new ByteArrayOutputStream(size);        ImageOutputStream out = ImageIO.createImageOutputStream(bous);        imageWriter.setOutput(out);        RenderedImage image = renderedImage;        if (destImageType == BufferedImage.TYPE_BYTE_INDEXED) {            if ((renderedImage.getColorModel() instanceof IndexColorModel) == false) {                if (LOG.isTraceEnabled()) {                    LOG.trace("Dither imageName '" + imageName + "' ...");                }                image = ditherImage(image);            }        } else if (destImageType != ((BufferedImage) renderedImage).getType()) {            if (LOG.isTraceEnabled()) {                LOG.trace("Convert imageName '" + imageName + "' from type "                        + ((BufferedImage) renderedImage).getType()                        + " to type " + destImageType);            }            BufferedImage bimage = new BufferedImage(image.getWidth(), image                    .getHeight(), destImageType);            Graphics2D g = bimage.createGraphics();            try {                g.drawImage((Image) image, 0, 0, null);            } finally {                g.dispose();            }            image = bimage;        }        try {            imageWriter.write(image);        } catch (IOException ex) {            LOG.error("Can not encode image into temp file ! (imageName="                    + imageName + ")", ex);            throw ex;        }        imageWriter.dispose();        out.close();        byte buffer[] = bous.toByteArray();        hash = ParametredHttpServlet.computeHash(buffer);        etag = ParametredHttpServlet.computeETag(buffer);        this.size = buffer.length;        FileOutputStream fileOutputStream = new FileOutputStream(file);        try {            fileOutputStream.write(buffer);        } catch (IOException ex) {            LOG.error(                    "Can not write temp file for filtered image ! (imageName="                            + imageName + ")", ex);            throw ex;        } finally {            fileOutputStream.close();        }        lastModified = imageDownloader.getLastModified();        LOG.debug("Store filtered image '" + imageName + "' into " + size                + " bytes. (disk location='" + file.getAbsolutePath() + "')");    }