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:net.pms.io.OutputConsumer.java

@Deprecated
public void destroy() {
    IOUtils.closeQuietly(inputStream);
}

From source file:com.hs.mail.sieve.Sieve.java

public static boolean runSieve(MailetContext context, Recipient recipient, SmtpMessage msg) {
    File script = getScript(context, recipient);
    if (script != null) {
        InputStream is = null;//www.  j a v  a 2  s.co m
        try {
            SieveMailAdapter adapter = new SieveMailAdapter(context, recipient.getMailbox(), recipient.getID());
            adapter.setMessage(msg);
            is = new BufferedInputStream(new FileInputStream(script));
            factory.interpret(adapter, is);
            return true;
        } catch (Exception e) {
            logger.error(e.getMessage());
        } finally {
            IOUtils.closeQuietly(is);
        }
    }
    return false;
}

From source file:de.tudarmstadt.ukp.dkpro.lexsemresource.core.util.FileUtils.java

/**
 * Makes the given stream available as a file. The created file is temporary
 * and deleted upon normal termination of the JVM. Still the file should be
 * deleted as soon as possible if it is no longer required. In case the JVM
 * crashes the file would not be deleted. The source stream is closed by
 * this operation in all cases.//from  w  w  w  . ja v  a 2s  .  co m
 *
 * @param is
 *            the source.
 * @return the file.
 * @throws IOException
 *             in case of read or write problems.
 */
public static File getStreamAsFile(final InputStream is) throws IOException {
    OutputStream os = null;
    try {
        final File f = File.createTempFile("dkpro_stream", "tmp");
        f.deleteOnExit();
        os = new FileOutputStream(f);
        IOUtils.copy(is, os);
        return f;
    } finally {
        IOUtils.closeQuietly(os);
        IOUtils.closeQuietly(is);
    }
}

From source file:eu.europa.esig.dss.pdf.DSSPDFUtils.java

/**
 * This method returns the temporary {@code File} with the provided contents.
 *
 * @param pdfData {@code InputStream} representing the contents of the returned {@code File}
 * @return {@code File} with the given contents
 * @throws DSSException in case of any {@code IOException}
 *//*from   www.  j  av  a2  s  .  c  o m*/
public static File getFileFromPdfData(final InputStream pdfData) throws DSSException {

    FileOutputStream fileOutputStream = null;
    try {

        final File file = File.createTempFile("sd-dss-", ".pdf");
        fileOutputStream = new FileOutputStream(file);
        IOUtils.copy(pdfData, fileOutputStream);
        return file;
    } catch (IOException e) {
        throw new DSSException("The process has no rights to write or to access 'java.io.tmpdir': "
                + System.getProperty("java.io.tmpdir"), e);
    } finally {
        IOUtils.closeQuietly(pdfData);
        IOUtils.closeQuietly(fileOutputStream);
    }
}

From source file:de.bmarwell.j9kwsolver.util.HttpConnectorFactory.java

/**
 * Shuts down the connector instance, if open.
 * @return true if connection could be closed.
 *///from w  w w. j a  va 2s  . c  o  m
public static boolean shutdownConnector() {
    IOUtils.closeQuietly(httpClient);

    return true;
}

From source file:com.igormaznitsa.jhexed.swing.editor.filecontainer.FileContainer.java

public FileContainer(final File file) throws IOException {
    FileInputStream in = null;/* w  w w  . j a v  a  2  s. c o m*/
    try {
        in = new FileInputStream(file);
        this.sections = loadFromStream(in);
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:com.groupon.jenkins.util.ResourceUtils.java

private static String readFile(Class<?> resourceClass, String ymlResource) {
    InputStream base = null;/*from www.java  2  s .c  o m*/
    try {
        base = resourceClass.getResourceAsStream(ymlResource);
        return IOUtils.toString(base);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        IOUtils.closeQuietly(base);
    }
}

From source file:edu.cornell.med.icb.goby.algorithmic.data.HeptamerInfo.java

/**
 * Load heptamer info from disk./*from  w  w w .java  2 s  .c o  m*/
 *
 * @param filename
 * @return
 * @throws IOException
 * @throws ClassNotFoundException
 */
public static HeptamerInfo load(final String filename) throws IOException, ClassNotFoundException {
    GZIPInputStream inputStream = null;
    try {
        inputStream = new GZIPInputStream(new FileInputStream(filename));
        return (HeptamerInfo) BinIO.loadObject(inputStream);
    } finally {
        if (inputStream != null) {
            IOUtils.closeQuietly(inputStream);

        }
    }
}

From source file:c3.ops.priam.compress.SnappyCompression.java

@Override
public void decompressAndClose(InputStream input, OutputStream output) throws IOException {
    try {//from   ww  w .  j  av a 2 s.c om
        decompress(input, output);
    } finally {
        IOUtils.closeQuietly(input);
        IOUtils.closeQuietly(output);
    }
}

From source file:info.dolezel.fatrat.plugins.util.FileUtils.java

/**
 * Reads the whole file and returns it as a String.
 * The UTF-8 encoding is assumed.//w ww.  j  a v  a2s.co  m
 * @param file The file path.
 * @return The file contents or <code>null</code> if the operation failed.
 */
public static String fileReadAll(String file) {
    FileInputStream fis = null;

    try {
        fis = new FileInputStream(file);

        return IOUtils.toString(fis, "UTF-8");
    } catch (IOException ex) {
        return null;
    } finally {
        IOUtils.closeQuietly(fis);
    }
}