List of usage examples for org.apache.commons.io IOUtils closeQuietly
public static void closeQuietly(OutputStream output)
OutputStream
. From source file:com.bradmcevoy.http.entity.InputStreamEntity.java
@Override public void write(Response response, OutputStream outputStream) throws Exception { try {/*from w w w. j a va2 s .c o m*/ StreamUtils.readTo(inputStream, outputStream); } catch (ReadingException ex) { throw new RuntimeException(ex); } catch (WritingException ex) { log.warn("exception writing, client probably closed connection", ex); } finally { IOUtils.closeQuietly(inputStream); } log.trace("finished sending content"); }
From source file:io.crate.frameworks.mesos.StreamRedirect.java
public void run() { InputStreamReader streamReader = null; BufferedReader bufferedReader = null; try {//from ww w . j a va2 s. c o m streamReader = new InputStreamReader(inputStream); bufferedReader = new BufferedReader(streamReader); String line; while ((line = bufferedReader.readLine()) != null) printStream.println(line); } catch (IOException ioe) { ioe.printStackTrace(); } finally { IOUtils.closeQuietly(bufferedReader); IOUtils.closeQuietly(streamReader); } }
From source file:ch.entwine.weblounge.common.impl.security.AccessControlParser.java
/** * Reads an ACL from an xml input stream. * /*from w ww .j a v a2s. c o m*/ * @param in * the xml input stream * @return the access control list * @throws IOException * if there is a problem reading the stream */ public static AccessControlList parseAcl(InputStream in) throws IOException { Unmarshaller unmarshaller; try { unmarshaller = jaxbContext.createUnmarshaller(); return unmarshaller.unmarshal(DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in), AccessControlListImpl.class).getValue(); } catch (Throwable t) { throw new IOException(t); } finally { IOUtils.closeQuietly(in); } }
From source file:cz.cas.lib.proarc.common.process.OutputConsumer.java
@Override public void run() { BufferedReader reader = new BufferedReader(new InputStreamReader(input)); try {//from w ww . java2 s. c o m for (String line; (line = reader.readLine()) != null;) { if (output.length() > 0) { output.append('\n'); } output.append(line); } } catch (Throwable ex) { error = ex; } finally { LOG.fine("Close."); IOUtils.closeQuietly(reader); } }
From source file:gov.nih.nci.ncicb.tcga.dcc.common.util.md5.MD5ChecksumCreator.java
public byte[] generate(final File fileName) throws NoSuchAlgorithmException, IOException { InputStream theFile = null;/*from w ww . java 2s. c om*/ byte[] result = null; try { final MessageDigest complete; //noinspection IOResourceOpenedButNotSafelyClosed theFile = new FileInputStream(fileName); final byte[] byteArrayBuffer = new byte[bufferSize]; complete = MessageDigest.getInstance("MD5"); int numRead; do { numRead = theFile.read(byteArrayBuffer); if (numRead > 0) { complete.update(byteArrayBuffer, 0, numRead); } } while (numRead != -1); assert complete != null; result = complete.digest(); } finally { IOUtils.closeQuietly(theFile); theFile = null; } return result; }
From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.loader.bamloader.BAMParser.java
public BamXmlResultSet parse(final String fileName) throws IOException, SAXException { logger.info("Started parsing bam file " + fileName); final XMLBinding xmlBinding = new XMLBinding().add("bam-smooks-config.xml"); xmlBinding.intiailize();// w w w .ja v a 2 s . co m InputStreamReader reader = null; try { reader = new InputStreamReader(new FileInputStream(fileName)); Source xmlSource = new StreamSource(reader); BamXmlResultSet bamXmlResultSet = xmlBinding.fromXML(xmlSource, BamXmlResultSet.class); logger.info("Completed parsing bam file " + fileName); return bamXmlResultSet; } finally { IOUtils.closeQuietly(reader); } }
From source file:b2s.idea.mavenize.JarCombiner.java
public void combineAllJarsIn(File folderOfJars, File output) { ZipOutputStream zipOut = null; try {//from w w w. j ava 2 s . co m JarContext context = new JarContext(); zipOut = new ZipOutputStream(new FileOutputStream(output)); for (File jarFile : folderOfJars.listFiles(new IntellijJarFileFilter())) { copyContentsOf(jarFile, zipOut, context); System.out.println(jarFile.getName()); } addServiceEntries(zipOut, context); zipOut.finish(); } catch (IOException e) { throw new RuntimeException("A problem occurred when combining the JARs", e); } finally { IOUtils.closeQuietly(zipOut); } }
From source file:edu.cornell.med.icb.goby.algorithmic.data.WeightsInfo.java
/** * Load weights info from disk./*from w w w . j a v a 2 s . c om*/ * * @param filename The name of the file to load * @return The populated WeightsInfo object read from the file * @throws IOException If the file cannot be read * @throws ClassNotFoundException if the file contains a class that cannot be found. */ public static WeightsInfo load(final String filename) throws IOException, ClassNotFoundException { GZIPInputStream inputStream = null; try { inputStream = new GZIPInputStream(new FileInputStream(filename)); return (WeightsInfo) BinIO.loadObject(inputStream); } finally { IOUtils.closeQuietly(inputStream); } }
From source file:ch.entwine.weblounge.common.impl.content.image.ImageMetadataUtils.java
/** * This utility method extracts image metadata stored in EXIF and IPTC tags * and returns the extracted information in a {@link ImageMetadata}. * /*from ww w .j a v a 2 s. c o m*/ * @param img * image file * @return extracted meta information */ public static ImageMetadata extractMetadata(File img) { BufferedInputStream is = null; try { is = new BufferedInputStream(new FileInputStream(img)); return extractMetadata(is); } catch (FileNotFoundException e) { logger.warn("Tried to extract image metadata from none existing file '{}'", img.getName()); return null; } finally { IOUtils.closeQuietly(is); } }
From source file:com.jayway.restassured.itest.java.FileDownloadITest.java
@Test public void canDownloadLargeFiles() throws Exception { int expectedSize = IOUtils .toByteArray(getClass().getResourceAsStream("/powermock-easymock-junit-1.4.12.zip")).length; final InputStream inputStream = expect().log().headers().when() .get("http://powermock.googlecode.com/files/powermock-easymock-junit-1.4.12.zip").asInputStream(); final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); IOUtils.copy(inputStream, byteArrayOutputStream); IOUtils.closeQuietly(byteArrayOutputStream); IOUtils.closeQuietly(inputStream);/*from w w w .j ava 2s .c o m*/ assertThat(byteArrayOutputStream.size(), equalTo(expectedSize)); }