Java Code Examples for org.apache.commons.io.FileUtils.openInputStream()

The following are Jave code examples for showing how to use openInputStream() of the org.apache.commons.io.FileUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ExcelParser   File: Properties2Xml.java   View Source Code Vote up 9 votes
/**
 * Properties 转换 string.xml
 *
 * @param file      properties文件
 * @param xmlCn     中文string.xml
 * @param xmlEn     英文string.xml
 */
public static void properties2Xml(File file, File xmlCn, File xmlEn) {
    try (FileInputStream in = FileUtils.openInputStream(file)){
        List<String> lines = FileUtils.readLines(file);
        // PrintUtils.list(lines);
        // Properties 并不遵循文件原来的顺序,所以采取读行的方式处理
        List<String> xmlLinesCn = new ArrayList<>(lines.size());
        List<String> xmlLinesEn = new ArrayList<>(lines.size());
        addHeader(xmlLinesCn);
        addHeader(xmlLinesEn);
        for(String line : lines){
            xmlLinesCn.add(itemXmlCn(line));
            xmlLinesEn.add(itemXmlEn(line));
        }
        addFooter(xmlLinesCn);
        addFooter(xmlLinesEn);
        FileUtils.deleteQuietly(xmlCn);
        FileUtils.writeLines(xmlCn, "UTF-8", xmlLinesCn);
        FileUtils.writeLines(xmlEn, "UTF-8", xmlLinesEn);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 2
Project: Reer   File: GFileUtils.java   View Source Code Vote up 5 votes
public static FileInputStream openInputStream(File file) {
    try {
        return FileUtils.openInputStream(file);
    } catch (IOException e) {
        throw new RuntimeException("Problems opening file input stream for file: " + file, e);
    }
}
 
Example 3
Project: monarch   File: DtdResolver.java   View Source Code Vote up 5 votes
@Deprecated
public InputSource resolveEntity(String publicId, String systemId) throws IOException {
  if (!isHttpUrlOK(systemId)) {
    URL dtdURL = getClass().getResource(CacheXml.LATEST_DTD_LOCATION);
    File dtd = new File(DistributionConfig.GEMFIRE_PREFIX + "dtd");
    FileUtils.copyURLToFile(dtdURL, dtd);
    InputSource inputSource = new InputSource(FileUtils.openInputStream(dtd));
    FileUtils.deleteQuietly(dtd);
    return inputSource;
  } else {
    return null;
  }
}
 
Example 4
Project: jvm-sandbox   File: CoreConfigure.java   View Source Code Vote up 5 votes
private static Properties fetchProperties(final String propertiesFilePath) {
    final Properties properties = new Properties();
    InputStream is = null;
    try {
        is = FileUtils.openInputStream(new File(propertiesFilePath));
        properties.load(is);
    } catch (Throwable cause) {
        // cause.printStackTrace(System.err);
    } finally {
        IOUtils.closeQuietly(is);
    }
    return properties;
}
 
Example 5
Project: iab-spiders-and-robots-java-client   File: IabClient.java   View Source Code Vote up 5 votes
public IabClient(File ipFile,
                 File excludeUserAgentFile,
                 File includeUserAgentFile) throws IOException {
    try (InputStream ip = FileUtils.openInputStream(ipFile);
         InputStream excludeUserAgent = FileUtils.openInputStream(excludeUserAgentFile);
         InputStream includeUserAgent = FileUtils.openInputStream(includeUserAgentFile)) {
        init(ip, excludeUserAgent, includeUserAgent);
    }
}
 
Example 6
Project: bitcoin-bruteforce   File: BloomFilter.java   View Source Code Vote up 4 votes
private void fromFile(String bloomFilterFile) throws IOException {
    System.out.println("Loading bloom filter from file " + bloomFilterFile);
    FileInputStream is = FileUtils.openInputStream(new File(bloomFilterFile));
    filter = com.google.common.hash.BloomFilter.readFrom(is, Funnels.stringFunnel(Charset.forName("UTF-8")));
    System.out.println("Bloom filter with approximately " + filter.approximateElementCount() + " addresses loaded");
}
 
Example 7
Project: DHIS2-fhir-lab-app   File: MediatorMain.java   View Source Code Vote up 4 votes
private static MediatorConfig loadConfig(String configPath) throws IOException, RoutingTable.RouteAlreadyMappedException {
    MediatorConfig config = new MediatorConfig();
    //MediatorFhirConfig config=new MediatorFhirConfig();

    if (configPath!=null) {
        Properties props = new Properties();
        File conf = new File(configPath);
        InputStream in = FileUtils.openInputStream(conf);
        props.load(in);
        IOUtils.closeQuietly(in);

        config.setProperties(props);
    } else {
        config.setProperties("mediator.properties");
    }

    config.setName(config.getProperty("mediator.name"));
    config.setServerHost(config.getProperty("mediator.host"));
    config.setServerPort( Integer.parseInt(config.getProperty("mediator.port")) );
    config.setRootTimeout(Integer.parseInt(config.getProperty("mediator.timeout")));


    config.setCoreHost(config.getProperty("core.host"));
    config.setCoreAPIUsername(config.getProperty("core.api.user"));
    config.setCoreAPIPassword(config.getProperty("core.api.password"));
    if (config.getProperty("core.api.port") != null) {
        config.setCoreAPIPort(Integer.parseInt(config.getProperty("core.api.port")));
    }

    config.setRoutingTable(buildRoutingTable());
    config.setStartupActors(buildStartupActorsConfig());

    InputStream regInfo = MediatorMain.class.getClassLoader().getResourceAsStream("mediator-registration-info.json");
    RegistrationConfig regConfig = new RegistrationConfig(regInfo);
    config.setRegistrationConfig(regConfig);

    if (config.getProperty("mediator.heartbeats")!=null && "true".equalsIgnoreCase(config.getProperty("mediator.heartbeats"))) {
        config.setHeartbeatsEnabled(true);
    }

    return config;
}