Example usage for javax.imageio.stream ImageOutputStream length

List of usage examples for javax.imageio.stream ImageOutputStream length

Introduction

In this page you can find the example usage for javax.imageio.stream ImageOutputStream length.

Prototype

long length() throws IOException;

Source Link

Document

Returns the total length of the stream, if known.

Usage

From source file:org.mrgeo.services.ServletUtils.java

/**
 * Writes an image to a servlet response
 * @param response servlet response/*w  w  w .ja v a  2  s.c o  m*/
 * @param image image bytes
 * @throws IOException
 */
public static void writeImageToResponse(HttpServletResponse response, byte[] image) throws IOException {
    try {
        ImageOutputStream imageStream = new MemoryCacheImageOutputStream(response.getOutputStream());
        imageStream.write(image, 0, image.length);
        response.setContentLength((int) imageStream.length());
        imageStream.close();
    }
    // TODO: remove these catches - This is to prevent seeing the broken pipes exception
    // over and over again in the trace...leave catch in until issue is fixed (#1122)
    catch (IIOException e) {
    } catch (IndexOutOfBoundsException e) {
    }
}