List of usage examples for org.apache.commons.io IOUtils closeQuietly
public static void closeQuietly(OutputStream output)
OutputStream
. From source file:com.msopentech.odatajclient.proxy.MediaEntityTestITCase.java
@Test public void read() throws IOException { final InputStream is = container.getCar().get(12).getStream(); assertNotNull(is);// w w w . j ava2 s . co m IOUtils.closeQuietly(is); }
From source file:com.sap.prd.mobile.ios.mios.AbstractProjectModifier.java
protected void persistModel(File pom, Model model) throws IOException { OutputStream os = null;//from www.j a v a 2s . c om try { os = new FileOutputStream(pom); new MavenXpp3Writer().write(os, model); } finally { IOUtils.closeQuietly(os); } }
From source file:com.splunk.shuttl.archiver.bucketlock.SimpleFileLockConstructorTest.java
@AfterMethod(groups = { "fast-unit" }) public void tearDown() { IOUtils.closeQuietly(fileChannel); }
From source file:com.meltmedia.cadmium.core.config.impl.PropertiesWriterImpl.java
@Override public void persistProperties(Properties properties, File propsFile, String message, Logger log) { if (propsFile.canWrite() || !propsFile.exists()) { FileOutputStream out = null; try {/*from w w w. j a va 2 s . c o m*/ ensureDirExists(propsFile.getParent()); out = new FileOutputStream(propsFile); properties.store(out, message); out.flush(); } catch (Exception e) { log.warn("Failed to persist vault properties file.", e); } finally { IOUtils.closeQuietly(out); } } }
From source file:com.google.code.jahath.common.StreamRelay.java
public void run() { byte buf[] = new byte[4096]; try {//from w w w . j a va2 s. c o m int n; while ((n = in.read(buf)) != -1) { if (log.isLoggable(Level.FINER)) { HexDump.log(log, Level.FINER, label, buf, 0, n); } out.write(buf, 0, n); out.flush(); } } catch (IOException ex) { log.log(Level.SEVERE, label, ex); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } log.info(label + " closed"); }
From source file:net.rptools.maptool.client.WebDownloader.java
/** * Read the data at the given URL. This method should not be called on the EDT. * // w ww .ja v a 2s . c o m * @return File pointer to the location of the data, file will be deleted at program end */ public String read() throws IOException { URLConnection conn = url.openConnection(); conn.setConnectTimeout(5000); conn.setReadTimeout(5000); // Send the request. conn.connect(); InputStream in = null; ByteArrayOutputStream out = null; try { in = conn.getInputStream(); out = new ByteArrayOutputStream(); int buflen = 1024 * 30; int bytesRead = 0; byte[] buf = new byte[buflen]; for (int nRead = in.read(buf); nRead != -1; nRead = in.read(buf)) { bytesRead += nRead; out.write(buf, 0, nRead); } } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } return out != null ? new String(out.toByteArray()) : null; }
From source file:eionet.gdem.conversion.excel.ExcelUtils.java
/** * Returns true, if InputStream can be opened with MS Excel. * @param input InputStream//w ww . ja v a 2 s . c o m * @return True, if InputStream can be opened with MS Excel. */ public static boolean isExcelFile(InputStream input) { try { POIFSFileSystem fs = new POIFSFileSystem(input); return true; } catch (Exception e) { return false; } finally { IOUtils.closeQuietly(input); } }
From source file:fm.last.moji.tracker.impl.RequestHandler.java
void close() { IOUtils.closeQuietly(reader); IOUtils.closeQuietly(writer); }
From source file:cn.guoyukun.spring.web.utils.DownloadUtils.java
public static void download(HttpServletRequest request, HttpServletResponse response, String filePath, String displayName) throws IOException { File file = new File(filePath); if (StringUtils.isEmpty(displayName)) { displayName = file.getName();//from w w w .ja v a 2 s. c o m } if (!file.exists() || !file.canRead()) { response.setContentType("text/html;charset=utf-8"); response.getWriter().write("??"); return; } String userAgent = request.getHeader("User-Agent"); boolean isIE = (userAgent != null) && (userAgent.toLowerCase().indexOf("msie") != -1); response.reset(); response.setHeader("Pragma", "No-cache"); response.setHeader("Cache-Control", "must-revalidate, no-transform"); response.setDateHeader("Expires", 0L); response.setContentType("application/x-download"); response.setContentLength((int) file.length()); String displayFilename = displayName.substring(displayName.lastIndexOf("_") + 1); displayFilename = displayFilename.replace(" ", "_"); if (isIE) { displayFilename = URLEncoder.encode(displayFilename, "UTF-8"); response.setHeader("Content-Disposition", "attachment;filename=\"" + displayFilename + "\""); } else { displayFilename = new String(displayFilename.getBytes("UTF-8"), "ISO8859-1"); response.setHeader("Content-Disposition", "attachment;filename=" + displayFilename); } BufferedInputStream is = null; OutputStream os = null; try { os = response.getOutputStream(); is = new BufferedInputStream(new FileInputStream(file)); IOUtils.copy(is, os); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(is); } }
From source file:ch.cyberduck.core.io.ThreadedStreamCloser.java
@Override public void close(final InputStream in) throws ConnectionTimeoutException { final CountDownLatch signal = new CountDownLatch(1); threadFactory.newThread(new Runnable() { @Override/*from w w w .ja v a 2s .c om*/ public void run() { IOUtils.closeQuietly(in); signal.countDown(); } }).start(); try { if (!signal.await(preferences.getInteger("connection.timeout.seconds"), TimeUnit.SECONDS)) { throw new StreamCloseTimeoutException("Timeout closing input stream", null); } } catch (InterruptedException e) { throw new ConnectionTimeoutException(e.getMessage(), e); } }