Java BufferedInputStream Create getInputStream(final String path)

Here you can find the source of getInputStream(final String path)

Description

get Input Stream

License

Apache License

Declaration

public static InputStream getInputStream(final String path) 

Method Source Code


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

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

public class Main {
    private static File testDataDir;

    public static InputStream getInputStream(final String path) {
        final File file = new File(getTestDataDir(), path);
        if (!file.isFile()) {
            throw new RuntimeException("File not found: " + file.getAbsolutePath());
        }/*from   ww  w .java2s .  c  o  m*/
        try {
            return new BufferedInputStream(new FileInputStream(file));
        } catch (final FileNotFoundException e) {
            throw new RuntimeException("File not found: " + file.getAbsolutePath());
        }
    }

    public static File getTestDataDir() {
        if (testDataDir == null) {
            testDataDir = new File("src/test/resources/test-data");
            if (!testDataDir.isDirectory()) {
                throw new RuntimeException("Test data directory not found: " + testDataDir.getAbsolutePath());
            }
        }

        return testDataDir;
    }
}

Related

  1. getInputStream(byte[] data)
  2. getInputStream(byte[] signature)
  3. getInputStream(byte[]... data)
  4. getInputStream(File file)
  5. getInputStream(InputStream in)
  6. getInputStream(String path)
  7. getInputStream(String resource)
  8. getInputStream(String string)