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.thoughtworks.go.util.validators.ZipValidator.java

protected void unzip(ZipInputStream zipInputStream, File destDir) throws IOException {
    destDir.mkdirs();//from  w  w w .j av a2 s.co m
    try {
        ZipEntry zipEntry = zipInputStream.getNextEntry();
        while (zipEntry != null) {
            extractTo(zipEntry, zipInputStream, destDir);
            zipEntry = zipInputStream.getNextEntry();
        }
    } finally {
        IOUtils.closeQuietly(zipInputStream);
    }
}

From source file:com.yattatech.io.ShalomFileReader.java

public Seminary read(String path) {

    Seminary seminary = null;//from w w w. java2  s.co m
    DataInputStream input = null;
    try {
        input = new DataInputStream(new FileInputStream(path));
        long checksum = input.readLong();
        input.readUTF(); // skip /n character
        String json = input.readUTF();
        long checksum2 = ChecksumCalculator.calculateChecksum(json);
        if (checksum == checksum2) {
            seminary = new Gson().fromJson(json, Seminary.class);
        }
    } catch (IOException ioe) {
        LOGGER.log(Level.SEVERE, ioe.getMessage());
    } finally {
        IOUtils.closeQuietly(input);
        return seminary;
    }
}

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

public static Properties readPropertiesFile(final InputStream is) throws IllegalArgumentException {

    Properties properties = new Properties();

    try {//from  www  .  j ava 2 s . c  o m
        properties.load(is);
    } catch (IOException e) {
        throw new IllegalArgumentException("Unable to read the properties file!", e);
    } finally {
        IOUtils.closeQuietly(is);
    }

    return properties;
}

From source file:net.bpelunit.framework.model.test.wire.IncomingMessage.java

public void setMessage(InputStream in) {
    try {/* w  w w  .  j av  a  2 s.  com*/
        message = MessageFactory.newInstance().createMessage(null, in);
    } catch (IOException e) {
        message = null;
    } catch (SOAPException e) {
        message = null;
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:com.sap.prd.mobile.ios.mios.AbstractProjectModifier.java

protected Model getModel(File pom) throws IOException, XmlPullParserException {

    InputStream is = null;/* ww  w  .  jav a2  s .  c  o m*/

    try {
        is = new FileInputStream(pom);
        return new MavenXpp3Reader().read(is);
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:com.glaf.core.security.DigestUtil.java

public static void digestFile(String filename, String algorithm) {
    byte[] b = new byte[65536];
    int read = 0;
    FileInputStream fis = null;/* w w  w  .  j a  v  a 2s .c o m*/
    FileOutputStream fos = null;
    OutputStream encodedStream = null;
    try {
        MessageDigest md = MessageDigest.getInstance(algorithm);
        fis = new FileInputStream(filename);
        while (fis.available() > 0) {
            read = fis.read(b);
            md.update(b, 0, read);
        }
        byte[] digest = md.digest();
        StringBuffer fileNameBuffer = new StringBuffer(256).append(filename).append('.').append(algorithm);
        fos = new FileOutputStream(fileNameBuffer.toString());
        encodedStream = MimeUtility.encode(fos, "base64");
        encodedStream.write(digest);
        fos.flush();
    } catch (Exception ex) {
        throw new RuntimeException("Error computing Digest: " + ex);
    } finally {
        IOUtils.closeQuietly(fis);
        IOUtils.closeQuietly(fos);
        IOUtils.closeQuietly(encodedStream);
    }
}

From source file:com.googlecode.dex2jar.reader.ZipExtractor.java

public byte[] extract(byte[] data, String name) throws IOException {
    ZipInputStream zis = null;/*  www. j av a 2s.  c om*/
    try {
        zis = new ZipInputStreamHack(new ByteArrayInputStream(data));
        for (ZipEntry entry = zis.getNextEntry(); entry != null; entry = zis.getNextEntry()) {
            if (entry.getName().equals(name)) {
                data = IOUtils.toByteArray(zis);
                zis.close();
                return data;
            }
        }
    } finally {
        IOUtils.closeQuietly(zis);
    }
    throw new IOException("can't find classes.dex in the zip");
}

From source file:de.thischwa.pmcms.server.ServletUtils.java

public static boolean writeFile(HttpServletResponse resp, File reqFile) {
    boolean retVal = false;
    InputStream in = null;/* w w w . java2 s  .co m*/
    try {
        in = new BufferedInputStream(new FileInputStream(reqFile));
        IOUtils.copy(in, resp.getOutputStream());
        logger.debug("File successful written to servlet response: " + reqFile.getAbsolutePath());
    } catch (FileNotFoundException e) {
        logger.error("Resource not found: " + reqFile.getAbsolutePath());
    } catch (IOException e) {
        logger.error(String.format("Error while rendering [%s]: %s", reqFile.getAbsolutePath(), e.getMessage()),
                e);
    } finally {
        IOUtils.closeQuietly(in);
    }
    return retVal;
}

From source file:de.weltraumschaf.registermachine.asm.AssemblerTest.java

private ByteCodeFile createAndVerifyByteCodeFile(final String filename)
        throws IOException, AssemblerSyntaxException {
    final InputStream input = getClass().getResourceAsStream(PACKAGE_PREFIX + "/" + filename);
    final ByteCodeFile byteCodeFile = sut.assamble(input, filename);
    IOUtils.closeQuietly(input);
    assertThat(byteCodeFile.isValid(), is(true));
    assertThat(byteCodeFile.getVersion(), is((short) 0x02));
    return byteCodeFile;
}

From source file:io.kahu.hawaii.util.call.http.util.HttpResponseToGZipConverter.java

public void toFile(HttpResponse response, File file) throws ServerException {
    FileOutputStream outputStream = null;
    GZIPOutputStream gzipOS = null;
    try {/*from   w  w  w  .j a v a2s  .  c o  m*/
        outputStream = new FileOutputStream(file);
        gzipOS = new GZIPOutputStream(outputStream);
        response.getEntity().writeTo(gzipOS);
    } catch (IOException e) {
        throw new ServerException(ServerError.IO, e);
    } finally {
        IOUtils.closeQuietly(gzipOS);
        IOUtils.closeQuietly(outputStream);
    }
}