Java Utililty Methods InputStream Create

List of utility methods to do InputStream Create

Description

The list of methods to do InputStream Create are organized into topic(s).

Method

ImageInputStreamgetInputStream(final File file)
Retrieves an ImageInputStream for the provided input File .
final ImageInputStream inStream = ImageIO.createImageInputStream(file);
if (inStream == null)
    return null;
return inStream;
FileInputStreamgetInputStream(final File file)
get Input Stream
try {
    return new FileInputStream(file);
} catch (FileNotFoundException e) {
    return null;
InputStreamgetInputStream(final File file, final boolean createFile)
Gets the input stream from a File object.
InputStream is = null;
if (file.exists()) {
    is = file.toURI().toURL().openStream();
} else {
    if (createFile) {
        file.createNewFile();
        is = file.toURI().toURL().openStream();
    } else {
...
ByteArrayInputStreamgetInputStream(final Serializable obj)
get Input Stream
byte[] bin = getBytes(obj);
return new ByteArrayInputStream(bin);
InputStreamgetInputStream(final String fileName)
Get input stream for specified file name.
Thread curThread = Thread.currentThread();
ClassLoader loader = curThread.getContextClassLoader();
return loader.getResourceAsStream(fileName);
InputStreamgetInputStream(final String sourceFolder, final Class clazz)
get Input Stream
return clazz.getResourceAsStream("/" + clazz.getName().replace('.', '/') + ".java");
InputStreamgetInputStream(String content)
get Input Stream
try {
    return new ByteArrayInputStream(content.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
    throw new RuntimeException("Problem generating input stream");
InputStreamgetInputStream(String data)
returns an input stream that will give you back the specified string
final String theData = data;
return new InputStream() {
    final String data = theData;
    int position = 0;
    public int read() throws EOFException {
        if (position < data.length())
            return data.charAt(position++);
        return -1;
...
java.io.InputStreamgetInputStream(String filename)
get Input Stream
File file = null;
FileInputStream fin = null;
try {
    file = new File(filename);
    if (file != null && file.isFile()) {
        fin = new FileInputStream(file);
        return fin;
    return null;
} catch (IOException ex) {
    fin = null;
    throw new RuntimeException(ex);
InputStreamgetInputStream(String fileName)
get Input Stream
return new FileInputStream(fileName);