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:it.geosolutions.tools.io.file.MultiPropertyFile.java

private InputStream getIS() throws IOException {
    if (in != null)
        return in;
    else {/*  ww w.j a  va2 s  .  com*/
        return (FileUtils.openInputStream(file));
    }
}

From source file:edu.sabanciuniv.sentilab.sare.controllers.base.documentStore.NonDerivedStoreFactory.java

protected T createSpecific(T store, File input, String format) throws IOException {

    Validate.notNull(store, CannedMessages.NULL_ARGUMENT, "store");
    Validate.notNull(input, CannedMessages.NULL_ARGUMENT, "input");

    InputStream stream = FileUtils.openInputStream(input);
    this.createSpecific(store, stream, format);
    stream.close();/*  w  w  w. j a  va2s  .c  om*/
    return store;
}

From source file:architecture.ee.web.logo.dao.jdbc.JdbcLogoImageDao.java

public void updateLogoImage(LogoImage logoImage, File file) {

    try {/*from   www .j  a va2 s.  co m*/
        updateLogoImage(logoImage, file != null ? FileUtils.openInputStream(file) : null);
    } catch (IOException e1) {

    }

}

From source file:at.ac.tuwien.dsg.comot.m.common.Utils.java

public static InputStream loadFileFromSystem(String path) throws IOException {
    return FileUtils.openInputStream(new File(path));
}

From source file:architecture.ee.web.community.profile.dao.jdbc.JdbcProfileDao.java

public void addProfileImage(ProfileImage image, File file) {
    try {//from w w  w  . j a va  2  s  .  c  o m
        ProfileImage toUse = image;
        if (toUse.getProfileImageId() < 1L) {
            long imageId = getNextId(sequencerName);
            if (image instanceof DefaultProfileImage) {
                DefaultProfileImage impl = (DefaultProfileImage) toUse;
                impl.setProfileImageId(imageId);
            }
        } else {
            Date now = Calendar.getInstance().getTime();
            toUse.setModifiedDate(now);
        }

        if (toUse.getImageSize() == 0)
            toUse.setImageSize((int) FileUtils.sizeOf(file));
        getExtendedJdbcTemplate().update(
                getBoundSql("ARCHITECTURE_COMMUNITY.RESET_PROFILE_IMAGE_BY_USER").getSql(),
                new SqlParameterValue(Types.INTEGER, toUse.getUserId()));
        getExtendedJdbcTemplate().update(getBoundSql("ARCHITECTURE_COMMUNITY.INSERT_PROFILE_IMAGE").getSql(),
                new SqlParameterValue(Types.NUMERIC, toUse.getProfileImageId()),
                new SqlParameterValue(Types.INTEGER, toUse.getUserId()),
                new SqlParameterValue(Types.VARCHAR, toUse.getFilename()),
                new SqlParameterValue(Types.INTEGER, toUse.getImageSize()),
                new SqlParameterValue(Types.VARCHAR, toUse.getImageContentType()),
                new SqlParameterValue(Types.TIMESTAMP, toUse.getCreationDate()),
                new SqlParameterValue(Types.TIMESTAMP, toUse.getModifiedDate()));
        updateProfileImageImputStream(image, FileUtils.openInputStream(file));

    } catch (IOException e) {
    }
}

From source file:com.sqli.liferay.imex.util.xml.ZipUtils.java

private void zipEntries(ZipOutputStream out, File file, File inputDir) throws IOException {
    String name;//from   ww w . j  a v  a 2 s .  c  o  m
    if (file.equals(inputDir)) {
        name = "";
    } else {
        name = file.getPath().substring(inputDir.getPath().length() + 1);
    }
    if (File.separatorChar == '\\') {
        name = name.replace("\\", "/");
    }

    log.debug("Adding: " + name);

    if (file.isDirectory()) {
        for (File child : file.listFiles()) {
            zipEntries(out, child, inputDir);
        }
    } else {
        ZipEntry entry = new ZipEntry(name);
        out.putNextEntry(entry);
        IOUtils.copy(FileUtils.openInputStream(file), out);
    }
}

From source file:ddf.catalog.source.solr.SolrServerFactory.java

/**
 * Provides an already instantiated {@link SolrServer} object. If an instance has not already
 * been instantiated, then the single instance will be instantiated with the provided
 * configuration file. If an instance already exists, it cannot be overwritten with a new
 * configuration.//from   w ww.j a v  a 2  s .c  o  m
 * 
 * @param solrConfigXml
 *            the name of the solr configuration filename such as solrconfig.xml
 * @param schemaXml
 *            filename of the schema such as schema.xml
 * @param givenConfigFileProxy
 *            a ConfigurationFileProxy instance. If instance is <code>null</code>, a new
 *            {@link ConfigurationFileProxy} is used instead.
 * @return {@link SolrServer} instance
 */
public static EmbeddedSolrServer getEmbeddedSolrServer(String solrConfigXml, String schemaXml,
        ConfigurationFileProxy givenConfigFileProxy) {

    LOGGER.info("Retrieving embedded solr with the following properties: [" + solrConfigXml + "," + schemaXml
            + "," + givenConfigFileProxy + "]");

    String solrConfigFileName = DEFAULT_SOLRCONFIG_XML;

    String schemaFileName = DEFAULT_SCHEMA_XML;

    if (isNotBlank(solrConfigXml)) {
        solrConfigFileName = solrConfigXml;
    }

    if (isNotBlank(schemaXml)) {
        schemaFileName = schemaXml;
    }

    File solrConfigFile = null;
    File solrConfigHome = null;
    File solrSchemaFile = null;

    ConfigurationFileProxy configProxy = givenConfigFileProxy;

    if (givenConfigFileProxy == null) {
        configProxy = new ConfigurationFileProxy(null, ConfigurationStore.getInstance());
    }

    File configurationDir = new File(ConfigurationFileProxy.DEFAULT_SOLR_CONFIG_PARENT_DIR,
            ConfigurationFileProxy.SOLR_CONFIG_LOCATION_IN_BUNDLE);
    configProxy.writeBundleFilesTo(configurationDir);

    try {
        URL url = configProxy.getResource(solrConfigFileName);

        LOGGER.info("Solr config url: " + url);

        solrConfigFile = new File(new URI(url.toString()).getPath());

        solrConfigHome = new File(solrConfigFile.getParent());
    } catch (URISyntaxException e) {
        LOGGER.warn(e);
    }

    try {
        URL url = configProxy.getResource(schemaFileName);

        LOGGER.info("Solr schema url: " + url);

        solrSchemaFile = new File(new URI(url.toString()).getPath());

    } catch (URISyntaxException e) {
        LOGGER.warn(e);
    }

    SolrConfig solrConfig = null;
    IndexSchema indexSchema = null;
    ClassLoader tccl = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(SolrServerFactory.class.getClassLoader());

        // NamedSPILoader uses the thread context classloader to lookup
        // codecs, posting formats, and analyzers
        solrConfig = new SolrConfig(solrConfigHome.getParent(), solrConfigFileName,
                new InputSource(FileUtils.openInputStream(solrConfigFile)));
        indexSchema = new IndexSchema(solrConfig, schemaFileName,
                new InputSource(FileUtils.openInputStream(solrSchemaFile)));
    } catch (ParserConfigurationException e) {
        LOGGER.warn(e);
    } catch (IOException e) {
        LOGGER.warn(e);
    } catch (SAXException e) {
        LOGGER.warn(e);
    } finally {
        Thread.currentThread().setContextClassLoader(tccl);
    }

    CoreContainer container = new CoreContainer(solrConfigHome.getAbsolutePath());
    container.load();
    CoreDescriptor dcore = new CoreDescriptor(container, "core1",
            solrConfig.getResourceLoader().getInstanceDir());

    File dataDir = configProxy.getDataDirectory();
    LOGGER.info("Using data directory [" + dataDir + "]");
    SolrCore core = new SolrCore("core1", dataDir.getAbsolutePath(), solrConfig, indexSchema, dcore);
    container.register("core1", core, false);

    return new EmbeddedSolrServer(container, "core1");
}

From source file:com.adobe.acs.commons.dam.AbstractRenditionModifyingProcess.java

void saveImage(Asset asset, Rendition toReplace, Layer layer, String mimetype, double quality,
        WorkflowHelper workflowHelper) throws IOException {
    File tmpFile = File.createTempFile(getTempFileSpecifier(), "." + workflowHelper.getExtension(mimetype));
    OutputStream out = FileUtils.openOutputStream(tmpFile);
    InputStream is = null;/*w ww . ja  v  a2 s  . c o m*/
    try {
        layer.write(mimetype, quality, out);
        is = FileUtils.openInputStream(tmpFile);
        asset.addRendition(toReplace.getName(), is, mimetype);
    } finally {
        IOUtils.closeQuietly(out);
        IOUtils.closeQuietly(is);
        FileUtils.deleteQuietly(tmpFile);
    }
}

From source file:com.talis.platform.sequencing.zookeeper.ZooKeeperProvider.java

private String readEnsembleList() throws IOException {
    InputStream ensembleListStream = this.getClass().getResourceAsStream(DEFAULT_SERVER_LIST_LOCATION);
    String theFilename = System.getProperty(SERVER_LIST_LOCATION_PROPERTY);
    if (null == theFilename) {
        if (LOG.isInfoEnabled()) {
            LOG.info("No server list specified in system " + "property using default");
        }//  www  .  jav  a2s  . c  o m
    } else {
        if (LOG.isInfoEnabled()) {
            LOG.info(String.format("Initialising server list from file %s", theFilename));
        }
        ensembleListStream = FileUtils.openInputStream(new File(theFilename));
    }

    String list = ((String) IOUtils.readLines(ensembleListStream).get(0)).trim();
    if (LOG.isInfoEnabled()) {
        LOG.info(String.format("Read ensemble list => %s", list));
    }
    return list;
}

From source file:com.blackducksoftware.integration.hub.detect.detector.bitbake.BitbakeExtractor.java

public Extraction extract(final ExtractionId extractionId, final File buildEnvScript, final File sourcePath,
        String[] packageNames, File bash) {
    final File outputDirectory = directoryManager.getExtractionOutputDirectory(extractionId);
    final File bitbakeBuildDirectory = new File(outputDirectory, "build");

    final List<DetectCodeLocation> detectCodeLocations = new ArrayList<>();
    for (final String packageName : packageNames) {
        final File dependsFile = executeBitbakeForRecipeDependsFile(outputDirectory, bitbakeBuildDirectory,
                buildEnvScript, packageName, bash);
        final String targetArchitecture = executeBitbakeForTargetArchitecture(outputDirectory, buildEnvScript,
                packageName, bash);/* w w  w.  j a va  2 s .  c om*/

        try {
            if (dependsFile == null) {
                throw new IntegrationException(String.format(
                        "Failed to find %s. This may be due to this project being a version of The Yocto Project earlier than 2.3 (Pyro) which is the minimum version for Detect",
                        RECIPE_DEPENDS_FILE_NAME));
            }
            if (StringUtils.isBlank(targetArchitecture)) {
                throw new IntegrationException("Failed to find a target architecture");
            }

            logger.debug(FileUtils.readFileToString(dependsFile, Charset.defaultCharset()));
            final InputStream recipeDependsInputStream = FileUtils.openInputStream(dependsFile);
            final GraphParser graphParser = new GraphParser(recipeDependsInputStream);
            final DependencyGraph dependencyGraph = graphParserTransformer.transform(graphParser,
                    targetArchitecture);
            final ExternalId externalId = new ExternalId(Forge.YOCTO);
            final DetectCodeLocation detectCodeLocation = new DetectCodeLocation.Builder(
                    DetectCodeLocationType.BITBAKE, sourcePath.getCanonicalPath(), externalId, dependencyGraph)
                            .build();

            detectCodeLocations.add(detectCodeLocation);
        } catch (final IOException | IntegrationException | NullPointerException e) {
            logger.error(String.format(
                    "Failed to extract a Code Location while running Bitbake against package '%s'",
                    packageName));
            logger.debug(e.getMessage(), e);
        }
    }

    final Extraction extraction;

    if (detectCodeLocations.isEmpty()) {
        extraction = new Extraction.Builder().failure("No Code Locations were generated during extraction")
                .build();
    } else {
        extraction = new Extraction.Builder().success(detectCodeLocations).build();
    }

    return extraction;
}