Example usage for org.apache.commons.io FileUtils openInputStream

List of usage examples for org.apache.commons.io FileUtils openInputStream

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils openInputStream.

Prototype

public static FileInputStream openInputStream(File file) throws IOException 

Source Link

Document

Opens a FileInputStream for the specified file, providing better error messages than simply calling new FileInputStream(file).

Usage

From source file:bookstore.BookUnmarshaller.java

public static Book[] BooksFromCsv(File file) {
    InputStream in = null;/* w  w  w  . j a v  a2 s . c  o  m*/
    Book[] books;
    try {
        in = FileUtils.openInputStream(file);
        books = BooksFromString(IOUtils.toString(in, Charset.forName("utf-8")));
    } catch (IOException | ParseException | NumberFormatException e) {
        return null;
    } finally {
        IOUtils.closeQuietly(in);
    }
    return books;
}

From source file:com.textocat.textokit.morph.opencorpora.resource.GramModelDeserializer.java

public static GramModel from(File file) throws Exception {
    return from(FileUtils.openInputStream(file), file.toString());
}

From source file:javacommon.excel.ReaderFactory.java

/**
 * ?Excel??//from   w  ww  . ja  v a 2 s .  c  om
 * @see ExcelConstants
 * @param type Excel2003??xlx,2007??xlsx
 * @param file excel
 * @return Excel??
 * @throws IOException
 */
public static Reader getReader(File file) throws IOException {
    return new ExcelReader(
            getWorkBook(ExcelUtils.getVersionByFileName(file.getName()), FileUtils.openInputStream(file)));
}

From source file:com.tascape.qa.th.android.model.UIA.java

public static WindowHierarchy parseHierarchy(File file, UiAutomatorDevice device)
        throws IOException, SAXException, ParserConfigurationException {
    try (InputStream in = FileUtils.openInputStream(file)) {
        return parseHierarchy(in, device);
    }//from  w  w  w.  ja va2s .  co m
}

From source file:com.splunk.shuttl.archiver.filesystem.hadoop.HdfsProperties.java

private static Properties loadProperties(File hdfsProperties) {
    try {/*from  ww  w. j  a  v  a  2  s.  com*/
        Properties properties = new Properties();
        properties.load(FileUtils.openInputStream(hdfsProperties));
        return properties;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.mycompany.osgiwebfelix.BundleInstaller.java

public Bundle installBundleFromFile(File savedBundleFile, boolean startBundle, boolean updateExistingBundle)
        throws IOException, BundleException {
    InputStream bundleInputStream = null;
    BundleContext bundleContext = (BundleContext) sc.getAttribute(BundleContext.class.getName());
    try {//from   w  w  w  . j  av a  2  s .  c  om
        bundleInputStream = FileUtils.openInputStream(savedBundleFile);

        final String bundleFileLocationAsURL = savedBundleFile.toURI().toURL().toExternalForm();
        Bundle bundle = bundleContext.installBundle(bundleFileLocationAsURL, bundleInputStream);
        bundle.start();
        return bundle;
    } finally {
        IOUtils.closeQuietly(bundleInputStream);
    }
}

From source file:com.textocat.textokit.morph.opencorpora.resource.MorphDictionaryImplTest.java

@Before
public void setUp() throws Exception {
    FileInputStream fis = FileUtils.openInputStream(new File("test-data/dict.opcorpora.test.xml"));
    try {/*from  w ww. j a va  2s . co m*/
        dict = XmlDictionaryParser.parse(fis);
        gm = dict.getGramModel();
    } finally {
        IOUtils.closeQuietly(fis);
    }
    dict.setWfPredictor(new DummyWordformPredictor(dict));
}

From source file:is.iclt.icenlp.core.formald.tagsets.CustomTagset.java

public static Tagset newInstance(String inputFile) {
    try {// w ww.j  a  v a 2  s.com
        return new CustomTagset(FileUtils.openInputStream(new File(inputFile)));
    } catch (IOException ex) {
        System.out.println("Could not open tagset file '" + inputFile + "'!");
        ex.printStackTrace();
    }
    return null;
}

From source file:gov.nih.nci.cacis.cdw.BaseCDWLoaderTest.java

@Before
public void before() throws URISyntaxException, IOException, RepositoryConfigException, RepositoryException {
    sampleMessageIS = FileUtils.openInputStream(
            new File(getClass().getClassLoader().getResource("caCISRequestSample3.xml").toURI()));
}

From source file:io.dfox.junit.http.example.NoteRepository.java

public synchronized Optional<InputStream> getNote(final String name) throws IOException {
    File note = new File(dir, name);
    if (note.exists()) {
        return Optional.of(IOUtils.toBufferedInputStream(FileUtils.openInputStream(note)));
    } else {//from www  . j a v  a  2s.  c  om
        return Optional.empty();
    }
}