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.htmlhifive.tools.codeassist.core.proposal.wrapper.ProposalWrapperUtils.java

/**
 * ?CSS??.// www .  j a v a  2 s .  c om
 * 
 * @return CSS.
 */
public static String getCSSStyles() {

    Bundle bundle = Platform.getBundle(JavaScriptPlugin.getPluginId());
    URL url = bundle.getEntry("/JavadocHoverStyleSheet.css"); //$NON-NLS-1$
    if (url != null) {
        BufferedReader reader = null;
        try {
            url = FileLocator.toFileURL(url);
            return IOUtils.toString(url.openStream());
        } catch (IOException ex) {
            JavaScriptPlugin.log(ex);
        } finally {
            IOUtils.closeQuietly(reader);
        }
    }
    return null;
}

From source file:ch.cyberduck.core.io.DisabledChecksumCompute.java

@Override
public Checksum compute(final InputStream in, final TransferStatus status) throws ChecksumException {
    IOUtils.closeQuietly(in);
    return Checksum.NONE;
}

From source file:fitnesse.slim.SlimClient.java

public void close() throws IOException {
    reader.close();
    IOUtils.closeQuietly(writer);
    client.close();
}

From source file:com.opoopress.maven.plugins.plugin.zip.ZipUtils.java

public static void unzipFileToDirectory(File file, File destDir, boolean keepTimestamp) throws IOException {
    // create output directory if it doesn't exist
    if (!destDir.exists())
        destDir.mkdirs();// w  ww . jav  a  2 s.com

    ZipFile zipFile = new ZipFile(file);
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        if (entry.isDirectory()) {
            new File(destDir, entry.getName()).mkdirs();
            continue;
        }

        InputStream inputStream = zipFile.getInputStream(entry);
        File destFile = new File(destDir, entry.getName());

        System.out.println("Unzipping to " + destFile.getAbsolutePath());
        FileUtils.copyInputStreamToFile(inputStream, destFile);
        IOUtils.closeQuietly(inputStream);

        if (keepTimestamp) {
            long time = entry.getTime();
            if (time > 0) {
                destFile.setLastModified(time);
            }
        }
    }

    zipFile.close();
}

From source file:jp.co.tis.gsp.tools.dba.util.ProcessUtil.java

public static void exec(Map<String, String> environment, String... args)
        throws IOException, InterruptedException {

    Process process = null;// w w w  .  j a  v a2 s. com
    InputStream stdout = null;
    BufferedReader br = null;

    try {
        ProcessBuilder pb = new ProcessBuilder(args);
        pb.redirectErrorStream(true);
        if (environment != null) {
            pb.environment().putAll(environment);
        }

        process = pb.start();
        stdout = process.getInputStream();
        br = new BufferedReader(new InputStreamReader(stdout));
        String line;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }
    } catch (IOException e) {
        throw e;
    } finally {
        IOUtils.closeQuietly(br);
        IOUtils.closeQuietly(stdout);

        if (process != null) {
            process.destroy();
        }
    }
}

From source file:net.sf.dsig.helpers.UserHomeSettingsParser.java

public static Properties parse() {
    try {/* ww w . j  av a  2 s .c  om*/
        String userHome = System.getProperty("user.home");
        File dsigFolder = new File(userHome, ".dsig");
        if (!dsigFolder.exists() && !dsigFolder.mkdir()) {
            throw new IOException("Could not create .dsig folder in user home directory");
        }

        File settingsFile = new File(dsigFolder, "settings.properties");
        if (!settingsFile.exists()) {
            InputStream is = UserHomeSettingsParser.class.getResourceAsStream("/defaultSettings.properties");
            if (is != null) {
                IOUtils.copy(is, new FileOutputStream(settingsFile));
            }
        }

        if (settingsFile.exists()) {
            Properties p = new Properties();
            FileInputStream fis = new FileInputStream(settingsFile);
            p.load(fis);
            IOUtils.closeQuietly(fis);
            return p;
        }
    } catch (IOException e) {
        logger.warn("Error while initialize settings", e);
    }

    return null;
}

From source file:com.geewhiz.pacify.utils.FileUtils.java

public static List<String> getFileAsLines(URL fileURL, String encoding) {
    InputStream is = null;//  w  ww .ja  v a  2  s.  c o m
    try {
        is = fileURL.openStream();
        return IOUtils.readLines(is, Charsets.toCharset(encoding));
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:eu.europa.esig.dss.applet.util.FileTypeDetectorUtils.java

/**
 * @param file/*from  w  ww  .  j av  a2 s .c om*/
 * @return
 * @throws IOException
 */
private static String extractPreambleString(final File file) throws IOException {

    FileInputStream inputStream = null;

    try {
        inputStream = new FileInputStream(file);

        final byte[] preamble = new byte[5];
        final int read = inputStream.read(preamble);
        if (read < 5) {
            throw new RuntimeException();
        }

        return new String(preamble);
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
}

From source file:com.mirth.connect.model.converters.DICOMConverter.java

public static DicomObject byteArrayToDicomObject(byte[] bytes, boolean decodeBase64) throws IOException {
    DicomObject basicDicomObject = new BasicDicomObject();
    DicomInputStream dis = null;//from  ww w .ja  v  a 2  s. com

    try {
        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
        InputStream inputStream;
        if (decodeBase64) {
            inputStream = new BufferedInputStream(new Base64InputStream(bais));
        } else {
            inputStream = bais;
        }
        dis = new DicomInputStream(inputStream);
        /*
         * This parameter was added in dcm4che 2.0.28. We use it to retain the memory allocation
         * behavior from 2.0.25.
         * http://www.mirthcorp.com/community/issues/browse/MIRTH-2166
         * http://www.dcm4che.org/jira/browse/DCM-554
         */
        dis.setAllocateLimit(-1);
        dis.readDicomObject(basicDicomObject, -1);
    } catch (IOException e) {
        throw e;
    } finally {
        IOUtils.closeQuietly(dis);
    }

    return basicDicomObject;
}

From source file:com.jdom.util.properties.PropertiesUtil.java

public static Properties readPropertiesFile(final File file) throws IllegalArgumentException {
    InputStream is = null;//from w  w w  . j a v a 2  s  .  c  o  m
    try {
        is = new FileInputStream(file);
        return readPropertiesFile(is);
    } catch (FileNotFoundException e) {
        throw new IllegalArgumentException(e);
    } finally {
        IOUtils.closeQuietly(is);
    }
}