Example usage for javax.imageio.stream ImageOutputStream write

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

Introduction

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

Prototype

void write(byte[] b, int off, int len) throws IOException;

Source Link

Document

Writes a sequence of bytes to the stream at the current position.

Usage

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

/**
 * Writes an image to a servlet response
 * @param response servlet response/*from  w ww .  j  a  v a2s  .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) {
    }
}