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:com.haulmont.yarg.structure.impl.ReportTemplateImpl.java

public ReportTemplateImpl(String code, String documentName, String documentPath,
        ReportOutputType reportOutputType) throws IOException {
    this(code, documentName, documentPath, FileUtils.openInputStream(new File(documentPath)), reportOutputType);

    validate();//w  ww .  j  av a2  s . c  o m
}

From source file:net.mindengine.blogix.config.BlogixConfig.java

private BlogixConfig() {
    try {/*from ww w  .  j a  v a2 s  .co m*/
        properties.load(FileUtils.openInputStream(BlogixFileUtils.findFile("conf/properties")));
        userCustomProperties = loadUserCustomProperties();
    } catch (Exception e) {
        throw new RuntimeException("Cannot load blogix properties", e);
    }
}

From source file:gov.nih.nci.cacis.sa.mirthconnect.SemanticAdapterChannelIntegrationTest.java

/**
 * This test calls out acceptSource(..) operation on SematicAdapter WS.
 * The SemanticAdapter WS is the source connector to SemanticAdapterChannel in Mirth.
 * @throws Exception exception// w ww .ja v  a  2s .  c o  m
 */
@Test
public void invokeSemanticAdapterWS() throws Exception { //NOPMD
    final JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setServiceClass(AcceptSourcePortType.class);
    factory.setAddress(ADDRESS);
    final AcceptSourcePortType client = (AcceptSourcePortType) factory.create();

    final InputStream sampleMessageIS = FileUtils
            .openInputStream(new File(getClass().getClassLoader().getResource("SARequestSample.xml").toURI()));

    final JAXBContext jc = JAXBContext.newInstance(CaCISRequest.class);
    final Unmarshaller unm = jc.createUnmarshaller();

    final CaCISRequest request = (CaCISRequest) unm.unmarshal(sampleMessageIS);

    final Marshaller m = jc.createMarshaller();
    final StringWriter sw = new StringWriter();
    final PrintWriter pw = new PrintWriter(sw);
    m.marshal(request, pw);
    final String reqStr = sw.toString();

    final CaCISResponse response = client.acceptSource(request);
    assertTrue(response.getStatus() == ResponseStatusType.SUCCESS);

}

From source file:com.haulmont.cuba.desktop.sys.LoginProperties.java

protected void loadProperties() {
    File propertiesFile = new File(dataDir, FILE_NAME);
    try {/*from w  ww .jav  a2s . com*/
        if (propertiesFile.exists()) {
            FileInputStream stream = FileUtils.openInputStream(propertiesFile);
            try {
                properties.load(stream);
            } finally {
                IOUtils.closeQuietly(stream);
            }
        }
    } catch (IOException e) {
        log.error("Error loading login properties", e);
    }
}

From source file:net.nicholaswilliams.java.teamcity.plugin.linux.AbstractLinuxPropertiesLocator.java

private void determinePluginVersion(File pluginRoot, Map<String, String> properties) {
    File versionFile = new File(pluginRoot, "version.properties");
    if (versionFile.exists()) {
        if (versionFile.canRead()) {
            Properties versionProperties = new Properties();
            FileInputStream stream = null;
            try {
                stream = FileUtils.openInputStream(versionFile);
                versionProperties.load(stream);
                if (versionProperties.getProperty(LinuxPropertiesLocator.PLUGIN_VERSION_KEY) != null) {
                    properties.put(LinuxPropertiesLocator.PLUGIN_VERSION_KEY,
                            versionProperties.getProperty(LinuxPropertiesLocator.PLUGIN_VERSION_KEY));
                }//from   w  w  w.ja  v  a2  s .  com
            } catch (IOException e) {
                AbstractLinuxPropertiesLocator.logger
                        .error("linux-system-properties plugin version file could not be read.", e);
            } finally {
                try {
                    if (stream != null)
                        stream.close();
                } catch (IOException e) {
                    AbstractLinuxPropertiesLocator.logger.warn("Unable to close version file after reading.",
                            e);
                }
            }
        } else {
            AbstractLinuxPropertiesLocator.logger
                    .warn("linux-system-properties plugin version file not readable.");
        }
    } else {
        AbstractLinuxPropertiesLocator.logger.warn("linux-system-properties plugin version file not found.");
    }
}

From source file:com.github.vbehar.ibot.Configuration.java

/**
 * Instantiate a new {@link Configuration} object, with the data from the given file
 * /*ww w  . j  ava 2s .c  om*/
 * @param configurationFilePath path of the configuration file (should be in the java-properties format)
 * @throws IOException in case of error while reading the file
 */
public Configuration(String configurationFilePath) throws IOException {
    super();
    configuration = new Properties();
    File configurationFile = new File(configurationFilePath);
    FileInputStream configurationStream = null;
    try {
        configurationStream = FileUtils.openInputStream(configurationFile);
        configuration.load(configurationStream);
    } finally {
        IOUtils.closeQuietly(configurationStream);
    }
}

From source file:ddf.catalog.transformer.input.tika.TikaInputTransformerTest.java

private static void transform(String filename) throws Exception {
    LOGGER.info("--------  File:  " + filename + "  -------------\n");

    File file = new File(filename);
    FileInputStream fis = FileUtils.openInputStream(file);
    TikaInputTransformer tikaInputTransformer = new TikaInputTransformer();
    Metacard metacard = tikaInputTransformer.transform(fis);

    LOGGER.info("-------------------------------------------------\n\n");

    assertNotNull(metacard);/*from ww w .j av a  2 s .  c  o  m*/
    assertNotNull(metacard.getCreatedDate());
    assertNotNull(metacard.getModifiedDate());
}

From source file:com.github.nullstress.asm.SourceSetScanner.java

public Set<String> analyze(URI uri) {
    Set<String> dependencies = new HashSet<String>();
    try {//from  ww  w . jav  a2s  . co m
        File startDir = new File(uri);
        if (!startDir.isDirectory()) {
            return dependencies;
        }
        Collection<File> files = FileUtils.listFiles(startDir, new String[] { "class" }, true);
        for (File file : files) {
            dependencies.addAll(scanFile(FileUtils.openInputStream(file)));
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return dependencies;
}

From source file:com.cts.ptms.tracking.UPSTracking.java

/**
 * Constructor for instantiating required objects.
 *//*from  w  w w .  ja v a2 s.com*/
public UPSTracking() {

    try {
        File initialFile = new File(ShippingConstants.buildPropertiesPath);
        InputStream inputStream = FileUtils.openInputStream(initialFile);

        properties.load(inputStream);

    } catch (Exception e) {
        System.out.println("Exception occured while loading the UPS properties file.");
    }
}

From source file:it.marcoberri.mbfasturl.helper.ConfigurationHelper.java

private ConfigurationHelper() {
    try {//from  w  w w.  j  a v a  2s. c om
        final URL main = getClass().getProtectionDomain().getCodeSource().getLocation();
        final String path = URLDecoder.decode(main.getPath(), "utf-8");
        final String webInfFolderPosition = new File(path).getPath();
        final String webInfFolder = webInfFolderPosition.substring(0, webInfFolderPosition.indexOf("classes"));
        prop = new Properties();
        prop.load(FileUtils.openInputStream(new File(webInfFolder + File.separator + "config.properties")));

        final JSONParser parser = new JSONParser();

        final Object obj = parser.parse(new FileReader(webInfFolder + File.separator + "cron.json"));
        final JSONObject jsonObject = (JSONObject) obj;
        ConfigurationHelper.cron = (JSONArray) jsonObject.get("cron");

    } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (ParseException ex) {
        throw new RuntimeException(ex.getMessage(), ex);
    }
}