Ejemplo n.º 1
0
  protected Image getImage(InputStream is, byte[] bytes) throws PortalException, SystemException {

    try {
      if (is != null) {
        bytes = FileUtil.getBytes(is);
      }

      ImageBag imageBag = ImageProcessorUtil.read(bytes);

      RenderedImage renderedImage = imageBag.getRenderedImage();
      String type = imageBag.getType();

      if (renderedImage == null) {
        throw new ImageTypeException();
      }

      int height = renderedImage.getHeight();
      int width = renderedImage.getWidth();
      int size = bytes.length;

      Image image = new ImageImpl();

      image.setTextObj(bytes);
      image.setType(type);
      image.setHeight(height);
      image.setWidth(width);
      image.setSize(size);

      return image;
    } catch (IOException ioe) {
      throw new SystemException(ioe);
    } finally {
      if (is != null) {
        try {
          is.close();
        } catch (IOException ioe) {
          if (_log.isWarnEnabled()) {
            _log.warn(ioe);
          }
        }
      }
    }
  }