Java InputStream Create asInputStream(String str)

Here you can find the source of asInputStream(String str)

Description

as Input Stream

License

LGPL

Declaration

public static InputStream asInputStream(String str) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.io.ByteArrayInputStream;

import java.io.InputStream;
import java.io.UnsupportedEncodingException;

public class Main {
    private static final String CHARSET = "UTF-8";

    public static InputStream asInputStream(String str) {
        try {//from   w  w w. jav  a 2s . c  o m
            return new ByteArrayInputStream(str.getBytes(CHARSET));
        } catch (UnsupportedEncodingException e) {
            // doesn't know UTF8? Why is this even a checked exception?
            assert false;
        }
        return null;
    }
}

Related

  1. asInputStream(byte[] bytes)
  2. asInputStream(File file)
  3. asInputStream(Object content)
  4. getInputStream(File f)
  5. getInputStream(File jarFile, String fileName)
  6. getInputStream(File tarFile)
  7. getInputStream(File tarFile)