Ejemplo n.º 1
0
  /**
   * The write class selects the encoding parameter considering the image format requested. Then,
   * the correct writer will encode the img given by the render into the servlet output stream
   *
   * @param wmsResponse The object used later to build the HTTP response.
   * @param output The output stream
   * @param format desired image format
   * @param img The output image.
   * @param pixelSize be provided by the server
   * @throws IOException If a problem has been encountered while handling the output stream.
   */
  public static void write(
      WMSResponse wmsResponse,
      OutputStream output,
      String format,
      BufferedImage img,
      double pixelSize)
      throws IOException {

    if (format.equalsIgnoreCase(ImageFormats.JPEG.toString())) {
      writeJPEG(wmsResponse, output, img);
      wmsResponse.setResponseCode(200);
      LOGGER.debug("JPEG written to the output stream.");
    } else if (format.equalsIgnoreCase(ImageFormats.PNG.toString())) {
      writePNG(wmsResponse, output, img, pixelSize);
      wmsResponse.setResponseCode(200);
      LOGGER.debug("PNG written to the output stream.");
    } else if (format.equalsIgnoreCase(ImageFormats.TIFF.toString())) {
      writeTIFF(wmsResponse, output, img, pixelSize);
      LOGGER.debug("TIFF written to the output stream.");
      wmsResponse.setResponseCode(200);
    } else {
      WMS.exceptionDescription(
          wmsResponse,
          output,
          "The format requested is invalid. "
              + "Please check the server capabilities to ask for a supported format.");
    }
  }
Ejemplo n.º 2
0
  /**
   * This method permits to write the result image from the wms request in a png format
   *
   * @param wmsResponse The object used later to build the HTTP response.
   * @param output The output stream
   * @param img The output image
   * @param pixelSize The size of the pixels.
   * @throws IOException
   */
  private static void writePNG(
      WMSResponse wmsResponse, OutputStream output, BufferedImage img, double pixelSize)
      throws IOException {
    wmsResponse.setContentType(ImageFormats.PNG.toString());

    int dpm = (int) (1000 / pixelSize + 1);
    PNGEncodeParam pEnc = PNGEncodeParam.getDefaultEncodeParam(img);
    pEnc.setPhysicalDimension(dpm, dpm, 1);
    JAI.create("Encode", img, output, "PNG", pEnc);

    output.close();
  }