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 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 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);
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 ); }