public static synchronized ImageEncoderRegistry getInstance() { if ( instance == null ) { instance = new ImageEncoderRegistry(); instance.registerDefaults(); } return instance; }
public static void encodeImage( final OutputStream outputStream, final Image image, final String mimeType, final float quality, final boolean alpha ) throws UnsupportedEncoderException, IOException { final WaitingImageObserver obs = new WaitingImageObserver( image ); obs.waitImageLoaded(); final ImageEncoder imageEncoder = ImageEncoderRegistry.getInstance().createEncoder( mimeType ); if ( imageEncoder == null ) { throw new UnsupportedEncoderException( "The encoder for mime-type '" + mimeType + "' is not available" ); } imageEncoder.encodeImage( image, outputStream, quality, alpha ); }
public static String getEncoderType( final ReportAttributeMap attributes ) { final Object attribute = attributes.getAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.IMAGE_ENCODING_TYPE ); if ( attribute == null ) { return ImageEncoderRegistry.IMAGE_PNG; } final String encoder = String.valueOf( attribute ); if ( ImageEncoderRegistry.getInstance().isEncoderAvailable( encoder ) ) { return encoder; } return ImageEncoderRegistry.IMAGE_PNG; }
public ImageEncoder createEncoder( final String mimeType ) throws UnsupportedEncoderException { final Object o = encoders.get( mimeType ); if ( o == null ) { throw new UnsupportedEncoderException( "No encoder for mime-type " + mimeType ); } final ImageEncoder imageEncoder = ObjectUtilities.loadAndInstantiate( (String) o, ImageEncoderRegistry.class, ImageEncoder.class ); if ( imageEncoder == null ) { throw new UnsupportedEncoderException( "No encoder for mime-type " + mimeType ); } return imageEncoder; } }
final ContentItem contentItem = contentLocation.createItem( nameGenerator.generateName( null, mimeType ) ); final BufferedImage image = interceptor.getImage(); final ImageEncoder imageEncoder = ImageEncoderRegistry.getInstance().createEncoder( mimeType ); final OutputStream outputStream = contentItem.getOutputStream(); imageEncoder.encodeImage( image, outputStream, quality, alphaChannel ); outputStream.close(); } catch ( Throwable e ) {
private void registerDefaults() { encoders.put( IMAGE_PNG, PngEncoder.class.getName() ); if ( JpegImageEncoder.isJpegEncodingAvailable() ) { encoders.put( IMAGE_JPEG, JpegImageEncoder.class.getName() ); encoders.put( "image/jpg", JpegImageEncoder.class.getName() ); } }
return null; } catch ( UnsupportedEncoderException e ) { logger.warn( "Failed to write the URL: Reason given was: " + e.getMessage() ); return null;
public ImageEncoder createEncoder(final String mimeType) throws UnsupportedEncoderException { final Object o = encoders.get(mimeType); if (o == null) { throw new UnsupportedEncoderException("No encoder for mime-type " + mimeType); } final ImageEncoder imageEncoder = ObjectUtilities.loadAndInstantiate((String) o, ImageEncoderRegistry.class, ImageEncoder.class); if (imageEncoder == null) { throw new UnsupportedEncoderException("No encoder for mime-type " + mimeType); } return imageEncoder; } }
public static synchronized ImageEncoderRegistry getInstance() { if (instance == null) { instance = new ImageEncoderRegistry(); instance.registerDefaults(); } return instance; }
private void registerDefaults() { encoders.put(IMAGE_PNG, PngEncoder.class.getName()); if (JpegImageEncoder.isJpegEncodingAvailable()) { encoders.put(IMAGE_JPEG, JpegImageEncoder.class.getName()); encoders.put("image/jpg", JpegImageEncoder.class.getName()); } }
public void encodeImage( final Image image, final OutputStream outputStream ) throws IOException, UnsupportedEncoderException { try { final ClassLoader loader = ObjectUtilities.getClassLoader( JpegImageEncoder.class ); final Class codecClass = Class.forName( ENCODER_CLASS, false, loader ); final Method createEncoderMethod = codecClass.getMethod( "createJPEGEncoder", new Class[] { OutputStream.class } ); final Object encoder = createEncoderMethod.invoke( null, new Object[] { outputStream } ); final Class encoderClass = encoder.getClass(); final Method encodeMethod = encoderClass.getMethod( "encode", new Class[] { Image.class } ); encodeMethod.invoke( encoder, new Object[] { image } ); } catch ( InvocationTargetException ie ) { final Throwable throwable = ie.getTargetException(); if ( throwable instanceof IOException ) { // Yeah, it is ugly, but the use of reflection hides the exception.. throw (IOException) throwable; } // ignore the throwable .. throw new UnsupportedEncoderException( "Failed to run the encoder", throwable ); } catch ( Throwable t ) { // ignore the throwable .. throw new UnsupportedEncoderException( "Failed to run the encoder", t ); } }
public void encodeImage(final Image image, final OutputStream outputStream) throws IOException, UnsupportedEncoderException { try { final ClassLoader loader = ObjectUtilities.getClassLoader(JpegImageEncoder.class); final Class codecClass = Class.forName(ENCODER_CLASS, false, loader); final Method createEncoderMethod = codecClass.getMethod("createJPEGEncoder", new Class[]{OutputStream.class}); final Object encoder = createEncoderMethod.invoke(null, new Object[]{outputStream}); final Class encoderClass = encoder.getClass(); final Method encodeMethod = encoderClass.getMethod("encode", new Class[]{Image.class}); encodeMethod.invoke(encoder, new Object[]{image}); } catch (InvocationTargetException ie) { final Throwable throwable = ie.getTargetException(); if (throwable instanceof IOException) { // Yeah, it is ugly, but the use of reflection hides the exception.. throw (IOException) throwable; } // ignore the throwable .. throw new UnsupportedEncoderException("Failed to run the encoder", throwable); } catch (Throwable t) { // ignore the throwable .. throw new UnsupportedEncoderException("Failed to run the encoder", t); } }
throw new UnsupportedEncoderException( "Failed to run the encoder", throwable ); } catch ( Throwable t ) { throw new UnsupportedEncoderException( "Failed to run the encoder", t );
throw new UnsupportedEncoderException("Failed to run the encoder", throwable); throw new UnsupportedEncoderException("Failed to run the encoder", t);