1 16 17 package org.apache.taglibs.standard.examples.util; 18 19 import java.io.*; 20 import javax.servlet.jsp.*; 21 22 28 public class Util { 29 30 public static Writer castToWriter(Object obj) throws JspException { 31 if (obj instanceof OutputStream) { 32 return new OutputStreamWriter((OutputStream)obj); 33 } else if (obj instanceof Writer) { 34 return (Writer)obj; 35 39 } 40 throw new JspException("Invalid type '" + obj.getClass().getName() + 41 "' for castToWriter()"); 42 } 43 44 public static Reader castToReader(Object obj) throws JspException { 45 if (obj instanceof InputStream) { 46 return new InputStreamReader((InputStream)obj); 47 } else if (obj instanceof Reader) { 48 return (Reader)obj; 49 } else if (obj instanceof String ) { 50 return new StringReader((String )obj); 51 } 52 throw new JspException("Invalid type '" + obj.getClass().getName() + 53 "' for castToReader()"); 54 } 55 } 56 57 | Popular Tags |