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.sloshydog.timely.HtmlReportGenerator.java

public void createReportFor(MavenSession mavenSession, List<EventRecorder.TimedEvent> timedEvents) {
    Writer writer = null;/*from   w w  w.j av  a2  s .  co m*/
    try {
        writer = getReportWriterFactory().createWriter(mavenSession);
        writer.write(getHtmlFactory().build(timedEvents));
    } catch (IOException e) {
        throw new RuntimeException("Unable to generate report for Timely.", e);

    } finally {
        IOUtils.closeQuietly(writer);
    }
}

From source file:com.arrow.acs.ManifestUtils.java

public static Manifest readManifest(Class<?> clazz) {
    String method = "readManifest";
    String jarFile = null;/*w  w  w.ja v a  2  s.  com*/
    String path = clazz.getProtectionDomain().getCodeSource().getLocation().toString();
    for (String token : path.split("/")) {
        token = token.replace("!", "").toLowerCase().trim();
        if (token.endsWith(".jar")) {
            jarFile = token;
            break;
        }
    }
    LOGGER.logInfo(method, "className: %s, path: %s, jarFile: %s", clazz.getName(), path, jarFile);
    InputStream is = null;
    try {
        if (!StringUtils.isEmpty(jarFile)) {
            Enumeration<URL> enumeration = Thread.currentThread().getContextClassLoader()
                    .getResources(JarFile.MANIFEST_NAME);
            while (enumeration.hasMoreElements()) {
                URL url = enumeration.nextElement();
                for (String token : url.toString().split("/")) {
                    token = token.replace("!", "").toLowerCase();
                    if (token.equals(jarFile)) {
                        LOGGER.logInfo(method, "loading manifest from: %s", url.toString());
                        return new Manifest(is = url.openStream());
                    }
                }
            }
        } else {
            URL url = new URL(path + "/META-INF/MANIFEST.MF");
            LOGGER.logInfo(method, "loading manifest from: %s", url.toString());
            return new Manifest(is = url.openStream());
        }
    } catch (IOException e) {
    } finally {
        IOUtils.closeQuietly(is);
    }
    LOGGER.logError(method, "manifest file not found for: %s", clazz.getName());
    return null;
}

From source file:net.padaf.preflight.util.ByteArrayDataSource.java

public ByteArrayDataSource(InputStream is) throws IOException {
    data = new ByteArrayOutputStream();
    IOUtils.copyLarge(is, data);
    IOUtils.closeQuietly(is);
}

From source file:com.jayway.maven.plugins.android.asm.AndroidTestFinder.java

public static boolean containsAndroidTests(File classesBaseDirectory) throws MojoExecutionException {

    if (classesBaseDirectory == null || !classesBaseDirectory.isDirectory()) {
        throw new IllegalArgumentException("classesBaseDirectory must be a valid directory!");
    }// w  w  w .  j  a  v  a 2 s.  c om

    final List<File> classFiles = findEligebleClassFiles(classesBaseDirectory);
    final DescendantFinder descendantFinder = new DescendantFinder(TEST_PACKAGES);

    for (File classFile : classFiles) {
        ClassReader classReader;
        FileInputStream inputStream = null;
        try {
            inputStream = new FileInputStream(classFile);
            classReader = new ClassReader(inputStream);

            classReader.accept(descendantFinder,
                    ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES | ClassReader.SKIP_CODE);
        } catch (IOException e) {
            throw new MojoExecutionException("Error reading " + classFile + ".\nCould not determine whether it "
                    + "contains tests. Please specify with plugin config parameter "
                    + "<enableIntegrationTest>true|false</enableIntegrationTest>.", e);
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
    }

    return descendantFinder.isDescendantFound();
}

From source file:gov.nih.nci.caintegrator.application.analysis.ClassificationsToClsConverterTest.java

private void checkFile(File clsFile) throws IOException {
    assertTrue(clsFile.exists());//from   w w  w.  java  2 s  . co  m
    CSVReader reader = new CSVReader(new FileReader(clsFile), ' ');
    checkLine(reader.readNext(), "3", "2", "1");
    checkLine(reader.readNext(), "#", "class1", "class2");
    checkLine(reader.readNext(), "0", "1", "0");
    IOUtils.closeQuietly(reader);
}

From source file:eionet.cr.harvest.util.MediaTypeToDcmiTypeConverter.java

/**
 * Loads the mimetypes from the file and puts them into mimeToRdfMap.
 *//*ww w. j  a  va 2  s  . c om*/
private static void initialize() {

    mappings = new LinkedHashMap<String, String>();

    InputStream inputStream = null;
    Properties properties = new Properties();
    try {
        inputStream = MediaTypeToDcmiTypeConverter.class.getClassLoader()
                .getResourceAsStream(MAPPINGS_FILENAME);
        properties.loadFromXML(inputStream);
    } catch (IOException e) {
        LOGGER.error("Failed to load XML-formatted properties from " + MAPPINGS_FILENAME, e);
    } finally {
        if (inputStream != null) {
            IOUtils.closeQuietly(inputStream);
        }
    }

    if (!properties.isEmpty()) {

        for (Map.Entry entry : properties.entrySet()) {

            String rdfType = entry.getKey().toString();
            String[] mediaTypes = entry.getValue().toString().split("\\s+");

            if (!StringUtils.isBlank(rdfType) && mediaTypes != null && mediaTypes.length > 0) {

                for (int i = 0; i < mediaTypes.length; i++) {

                    if (!StringUtils.isBlank(mediaTypes[i])) {

                        mappings.put(mediaTypes[i].trim(), rdfType.trim());
                    }
                }
            }
        }
    }
}

From source file:com.ngcomp.cloud.broker.util.PropUtils.java

/**
 * /*from   ww  w. j  a va  2s . c om*/
 * @throws IOException
 */
private PropUtils(String configFilePath) throws IOException {
    Properties p = new Properties();
    FileInputStream in = null;
    try {
        in = new FileInputStream(configFilePath);
        p.load(in);
    } finally {
        IOUtils.closeQuietly(in);
    }
    this.props = p;
}

From source file:com.oprisnik.semdroid.plugin.weka.WekaDataClassifier.java

public void loadClassificationModel(InputStream modelPath) throws BadConfigException {
    try {/*from w ww  .  ja  v a  2 s .  c o  m*/
        mClassifier = (Classifier) SerializationHelper.read(modelPath);
    } catch (Exception e) {
        throw new BadConfigException(e.getMessage());
    } finally {
        IOUtils.closeQuietly(modelPath);
    }
}

From source file:com.asakusafw.bulkloader.transfer.StreamFileListProvider.java

@Override
public FileList.Reader openReader() throws IOException {
    InputStream stream = getInputStream();
    boolean succeed = false;
    try {/*from   ww  w.j  av a 2 s .c  o  m*/
        FileList.Reader channel = FileList.createReader(stream);
        succeed = true;
        return channel;
    } finally {
        if (succeed == false) {
            IOUtils.closeQuietly(stream);
        }
    }
}

From source file:com.theatlantic.highcharts.export.HighchartsExporter.java

public void export(String chartOptions, String globalOptions, OutputStream out) {
    try {/*from w  w w.ja va 2s. c  o  m*/
        render(chartOptions, globalOptions, out);
    } catch (RhinoException e) {
        throw e;
    } catch (Exception e) {
        e.printStackTrace();
        throw (new RuntimeException(e));
    } finally {
        if (out != null) {
            IOUtils.closeQuietly(out);
        }
    }

}