001    package railo.runtime.img.coder;
002    
003    import java.awt.image.BufferedImage;
004    import java.io.IOException;
005    
006    import railo.commons.io.res.Resource;
007    import railo.commons.lang.SystemOut;
008    public abstract class Coder {
009            
010            private static Coder instance;
011            
012            protected Coder(){}
013            
014            public static Coder getInstance(){
015                    
016                    if(instance==null){
017                            instance = new JRECoder();
018                            
019                            // try to load Sanselan, does not load when lib not exist
020                            try{
021                                    SanselanCoder sanselan = new SanselanCoder();
022                                    instance=new DoubleCoder(sanselan, instance);
023                                    SystemOut.printDate("use Sanselan and JRE Image Coder ");
024                            }
025                            catch(Throwable t){
026                                    SystemOut.printDate("use JRE Image Coder ");
027                            }
028                    } 
029                    return instance;
030            }
031            
032    
033            /**
034             * translate a file resource to a buffered image
035             * @param res
036             * @return
037             * @throws IOException
038             */
039            public abstract BufferedImage toBufferedImage(Resource res,String format) throws IOException;
040    
041            /**
042             * translate a binary array to a buffered image
043             * @param binary
044             * @return
045             * @throws IOException
046             */
047            public abstract BufferedImage toBufferedImage(byte[] bytes,String format) throws IOException;
048    
049            public abstract String[] getWriterFormatNames();
050            
051            public abstract String[] getReaderFormatNames();
052            
053    }