public static InputStream createInputStream()

in src/java/org/apache/fulcrum/jce/crypto/StreamUtil.java [58:98]


    public static InputStream createInputStream( Object source )
        throws IOException
    {
        InputStream is;

        // create an InputStream

        if( source instanceof String )
        {
            byte[] content = ((String) source).getBytes("utf-8");
            is = new ByteArrayInputStream( content );
        }
        else if( source instanceof File )
        {
            is = new FileInputStream( (File) source );
        }
        else if( source instanceof byte[] )
        {
            is = new ByteArrayInputStream( (byte[]) source );
        }
        else if( source instanceof char[] )
        {
            byte[] content = new String((char[])source).getBytes("utf-8");
            is = new ByteArrayInputStream( content );
        }
        else if( source instanceof ByteArrayOutputStream )
        {
            byte[] content = ((ByteArrayOutputStream) source).toByteArray();
            is = new ByteArrayInputStream( content );
        }
        else if( source instanceof InputStream )
        {
            is = (InputStream) source;
        }
        else
        {
            throw new IllegalArgumentException("Don't know hot to handle " + source.getClass().getName());
        }

        return is;
    }