Example usage for org.apache.commons.io IOUtils closeQuietly

List of usage examples for org.apache.commons.io IOUtils closeQuietly

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils closeQuietly.

Prototype

public static void closeQuietly(OutputStream output) 

Source Link

Document

Unconditionally close an OutputStream.

Usage

From source file:com.norconex.importer.TestUtil.java

public static Importer getTestConfigImporter() {
    InputStream is = TestUtil.class.getResourceAsStream("test-config.xml");
    Reader r = new InputStreamReader(is);
    ImporterConfig config = ImporterConfigLoader.loadImporterConfig(r);
    IOUtils.closeQuietly(r);
    return new Importer(config);
}

From source file:com.jdy.ddj.common.utils.PropertiesLoader.java

/**
 * , Spring Resource?.// w w w  .jav  a 2  s.com
 */
public static Properties loadProperties(String... resourcesPaths) throws IOException {
    Properties props = new Properties();

    for (String location : resourcesPaths) {

        logger.debug("Loading properties file from:" + location);

        InputStream is = null;
        try {
            Resource resource = resourceLoader.getResource(location);
            is = resource.getInputStream();
            props.load(is);
        } catch (IOException ex) {
            logger.info("Could not load properties from path:" + location + ", " + ex.getMessage());
        } finally {
            IOUtils.closeQuietly(is);
        }
    }
    return props;
}

From source file:com.igormaznitsa.jcp.it.maven.ITPreprocessorMojo.java

private static void assertMainClass(final String jarFile, final String mainClass) throws Exception {
    JarInputStream jarStream = null;
    try {/*from   w w  w . j av a 2  s .com*/
        jarStream = new JarInputStream(new FileInputStream(jarFile));
        final Manifest manifest = jarStream.getManifest();
        final Attributes attrs = manifest.getMainAttributes();
        assertEquals("Maven plugin must also provide and main class in manifest", mainClass,
                attrs.getValue("Main-Class"));
    } finally {
        IOUtils.closeQuietly(jarStream);
    }
}

From source file:com.yattatech.dbtc.util.DbUtil.java

/**
 * Copies the application database to given folder, it' very useful
 * for debugging purpose only.//ww  w  .  j a  v  a 2s  .  c om
 * 
 * @param path
 * 
 */
public static void copyDatabase(String path) {
    final File folder = new File(path);
    final Context context = DBTCApplication.sApplicationContext;
    if (!folder.exists()) {
        folder.exists();
    }
    for (String database : context.databaseList()) {
        final File dbFile = context.getDatabasePath(database);
        InputStream in = null;
        OutputStream out = null;
        try {
            in = new FileInputStream(dbFile);
            out = new FileOutputStream(new File(folder, database));
            IOUtils.copy(in, out);
        } catch (IOException ioe) {
            Debug.d(TAG, "Failed:", ioe);
        } finally {
            IOUtils.closeQuietly(in);
            IOUtils.closeQuietly(out);
        }
    }
}

From source file:com.github.jankrause.javadoctools.connectors.DbConnector.java

private static ResourceBundle createResourceBundle() {
    InputStream resourcesFileAsStream = null;

    try {/*from   w ww .ja va  2 s . c  om*/
        resourcesFileAsStream = new FileInputStream(DB_PROPERTY_FILE);
        return new PropertyResourceBundle(resourcesFileAsStream);
    } catch (IOException ioEx) {
        throw new RuntimeException("Could not read the expected resource-file " + DB_PROPERTY_FILE, ioEx);
    } finally {
        IOUtils.closeQuietly(resourcesFileAsStream);
    }
}

From source file:ca.uhn.fhir.util.VersionUtil.java

private static void initialize() {
    InputStream is = null;/* w  ww .ja  v  a  2 s.com*/
    try {
        is = VersionUtil.class.getResourceAsStream("/ca/uhn/fhir/hapi-version.properties");
        Properties p = new Properties();
        p.load(is);
        ourVersion = p.getProperty("version");
        ourLog.info("HAPI FHIR version is: " + ourVersion);
    } catch (Exception e) {
        ourLog.warn("Unable to determine HAPI version information", e);
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:cd.education.data.collector.android.utilities.ZipUtils.java

public static void unzip(File[] zipFiles) {
    for (File zipFile : zipFiles) {
        ZipInputStream zipInputStream = null;
        try {/*from ww w  .  j  av  a2s.c  om*/
            zipInputStream = new ZipInputStream(new FileInputStream(zipFile));
            ZipEntry zipEntry;
            while ((zipEntry = zipInputStream.getNextEntry()) != null) {
                doExtractInTheSameFolder(zipFile, zipInputStream, zipEntry);
            }
        } catch (Exception e) {
            Log.e(t, e.getMessage(), e);
        } finally {
            IOUtils.closeQuietly(zipInputStream);
        }
    }
}

From source file:com.ignorelist.kassandra.steam.scraper.LibraryScanner.java

public static Set<Long> findGames(Path path) throws IOException {
    Set<Long> gameIds = new HashSet<>();
    DirectoryStream<Path> directoryStream = null;
    try {/*from w w w .ja  v a 2s.c om*/
        directoryStream = Files.newDirectoryStream(path, new DirectoryStream.Filter<Path>() {

            @Override
            public boolean accept(Path entry) throws IOException {
                return Files.isRegularFile(entry);
            }
        });
        for (Path f : directoryStream) {
            final String fileName = f.getFileName().toString();
            Matcher matcher = PATTERN.matcher(fileName);
            if (matcher.matches()) {
                gameIds.add(Long.parseLong(matcher.group(1)));
            }
        }
        return gameIds;
    } finally {
        IOUtils.closeQuietly(directoryStream);
    }
}

From source file:eu.planets_project.ifr.core.common.conf.PlanetsServerConfig.java

/**
 * Static property loader.//w w w . j a  va2s. c  om
 * @return The Properties array:
 */
private static Properties loadProps() {
    Properties props = new Properties();
    InputStream stream = null;
    try {
        stream = PlanetsServerConfig.class.getResourceAsStream(
                "/eu/planets_project/ifr/core/common/conf/planets-server-config.properties");
        props.load(stream);
    } catch (IOException e) {
        log.severe("Server properties failed to load! :: " + e);
        IOUtils.closeQuietly(stream);
    }
    return props;
}

From source file:ca.uhn.fhir.rest.client.exceptions.NonFhirResponseException.java

public static NonFhirResponseException newInstance(int theStatusCode, String theContentType, Reader theReader) {
    String responseBody = "";
    try {//w ww.j av  a 2  s.  co  m
        responseBody = IOUtils.toString(theReader);
    } catch (IOException e) {
        IOUtils.closeQuietly(theReader);
    }

    NonFhirResponseException retVal;
    if (isBlank(theContentType)) {
        retVal = new NonFhirResponseException(theStatusCode, "Response contains no Content-Type");
    } else if (theContentType.contains("text")) {
        retVal = new NonFhirResponseException(theStatusCode,
                "Response contains non FHIR Content-Type '" + theContentType + "' : " + responseBody);
    } else {
        retVal = new NonFhirResponseException(theStatusCode,
                "Response contains non FHIR Content-Type '" + theContentType + "'");
    }

    retVal.setResponseBody(responseBody);
    return retVal;
}