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

InputStreamgetInputStream(String[] args)
Searches the command line args for -f path_to_file.
for (int i = 0; i < args.length - 1; i++) {
    if ("-f".equals(args[i])) {
        File f = new File(args[i + 1]);
        if (f.exists() && f.isFile())
            try {
                return new FileInputStream(f);
            } catch (FileNotFoundException e) {
                System.err.println("Something went horribly wrong!");
...
InputStreaminputStream(final File file)
input Stream
return file.getName().endsWith(".gz") ? new GZIPInputStream(new FileInputStream(file))
        : new FileInputStream(file);
InputStreaminputStream(final String in)
Makes an input stream from a String.
return new InputStream() {
    int charindex = 0;
    public synchronized int read() throws IOException {
        if (charindex < in.length()) {
            return (int) in.charAt(charindex++);
        } else
            return -1;
};
FileInputStreaminputStream(String fileName)
input Stream
FileInputStream stream = null;
try {
    stream = new FileInputStream(new File(fileName));
} catch (FileNotFoundException e) {
    e.printStackTrace();
return stream;
InputStreaminputStream(String path)
input Stream
return new BufferedInputStream(new FileInputStream(path));
InputStreaminputStreamFromPath(String path)
input Stream From Path
try {
    return new BufferedInputStream(new FileInputStream(new File(path)));
} catch (FileNotFoundException e) {
    throw new RuntimeException(e);
InputStreamInputStreamFromString(String str)
Input Stream From String
byte[] bytes = null;
ByteArrayInputStream thisInputStream = null;
try {
    bytes = str.getBytes(ENCODING);
    thisInputStream = new ByteArrayInputStream(bytes);
} catch (Exception e) {
return thisInputStream;
...
InputStreamnewInputStream(Class clazz, String filename)
new Input Stream
String resource = clazz.getPackage().getName().replace(".", "/") + "/" + filename;
return clazz.getClassLoader().getResourceAsStream(resource);
InputStreamReadernewInputStreamReader(InputStream is)
new Input Stream Reader
try {
    return new InputStreamReader(is, strCode);
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
return null;
InputStreamtoInputStream(byte[] bytes)
Converts an array of bytes into an Input Stream
return new ByteArrayInputStream(bytes);