001    package railo.commons.io;
002    
003    import java.nio.charset.Charset;
004    
005    import railo.runtime.exp.PageException;
006    import railo.runtime.op.Caster;
007    
008    public class CharsetUtil {
009            public static final Charset UTF8;
010            public static final Charset ISO88591;
011            
012            static {
013                    UTF8=toCharset("utf-8",null);
014                    ISO88591=toCharset("iso-8859-1",null);
015            }
016    
017            public static Charset toCharset(String charset) throws PageException {
018                    try{
019                            return Charset.forName(charset);
020                    }
021                    catch(Throwable t){
022                            throw Caster.toPageException(t);
023                    }
024            }
025    
026            public static Charset toCharset(String charset,Charset defaultValue) {
027                    try{
028                            return Charset.forName(charset);
029                    }
030                    catch(Throwable t){
031                            return defaultValue;
032                    }
033            }
034    
035    }