List of usage examples for org.apache.commons.io IOUtils closeQuietly
public static void closeQuietly(OutputStream output)
OutputStream
. From source file:de.fu_berlin.inf.dpp.core.util.FileUtils.java
/** * Calculate Adler32 checksum for given file. * * @return checksum of file//w w w . j a v a 2 s. c o m * @throws IOException if checksum calculation has been failed. */ public static long checksum(IFile file) throws IOException { InputStream in; try { in = file.getContents(); } catch (IOException e) { throw new IOException("failed to calculate checksum.", e); } byte[] buffer = new byte[BUFFER_SIZE]; Adler32 adler = new Adler32(); int read; try { while ((read = in.read(buffer)) != -1) { adler.update(buffer, 0, read); } } finally { IOUtils.closeQuietly(in); } return adler.getValue(); }
From source file:abfab3d.io.output.SVXWriter.java
/** * Writes a grid out to an svx file//www .j av a2 s .co m * @param grid * @param file */ public void write(AttributeGrid grid, String file) { FileOutputStream fos = null; BufferedOutputStream bos = null; try { fos = new FileOutputStream(file); bos = new BufferedOutputStream(fos); write(grid, bos); } catch (IOException ioe) { ioe.printStackTrace(); } finally { IOUtils.closeQuietly(bos); IOUtils.closeQuietly(fos); } }
From source file:eionet.gdem.conversion.converters.XMLConverter.java
@Override public String convert(InputStream source, InputStream xslt, OutputStream result, String cnvFileExt) throws GDEMException, Exception { String xmlFile = Utils.getUniqueTmpFileName("." + cnvFileExt); if (result != null) { runXslTransformation(source, xslt, result); } else {//from w ww . j a va 2 s . c o m try { result = new FileOutputStream(xmlFile); runXslTransformation(source, xslt, result); } catch (IOException e) { throw new GDEMException("Error creating XML output file " + e.toString(), e); } finally { IOUtils.closeQuietly(result); } } return xmlFile; }
From source file:com.blogspot.jabelarminecraft.blocksmith.VersionChecker.java
@Override public void run() { InputStream in = null;/*w ww .j a v a 2 s . c o m*/ try { in = new URL( "https://raw.githubusercontent.com/jabelar/MagicBeans-1.7.10/master/src/main/java/com/blogspot/jabelarminecraft/magicbeans/version_file") .openStream(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { latestVersion = IOUtils.readLines(in).get(0); // toString(in); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { IOUtils.closeQuietly(in); } System.out.println("Latest mod version = " + latestVersion); isLatestVersion = BlockSmith.MODVERSION.equals(latestVersion); System.out.println("Are you running latest version = " + isLatestVersion); }
From source file:com.blogspot.jabelarminecraft.magicbeans.VersionChecker.java
@Override public void run() { InputStream in = null;/*w w w .j a va2 s . c om*/ try { in = new URL( "https://raw.githubusercontent.com/jabelar/MagicBeans-1.7.10/master/src/main/java/com/blogspot/jabelarminecraft/magicbeans/version_file") .openStream(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { latestVersion = IOUtils.readLines(in).get(0); // toString(in); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { IOUtils.closeQuietly(in); } System.out.println("Latest mod version = " + latestVersion); isLatestVersion = MagicBeans.MODVERSION.equals(latestVersion); System.out.println("Are you running latest version = " + isLatestVersion); }
From source file:eionet.gdem.conversion.converters.TextConverter.java
@Override public String convert(InputStream source, InputStream xslt, OutputStream result, String cnvFileExt) throws GDEMException, Exception { String outFile = Utils.getUniqueTmpFileName("." + cnvFileExt); if (result != null) { runXslTransformation(source, xslt, result); } else {//from w ww. ja v a2 s . c o m try { result = new FileOutputStream(outFile); runXslTransformation(source, xslt, result); } catch (IOException e) { throw new GDEMException("Error creating TEXT output file:" + e.toString(), e); } finally { IOUtils.closeQuietly(result); } } return outFile; }
From source file:com.comcast.video.dawg.filter.gzip.GZipServletResponseWrapper.java
/** * Closes the stream and releases any system resources associated with it. Closing a previously closed stream has no * effect.//from w w w .ja va 2s . c o m */ public void close() { // PrintWriter.close does not throw exceptions. Thus, the call does not need // be inside a try-catch block. if (this.printWriter != null) { this.printWriter.close(); } IOUtils.closeQuietly(gzipOutputStream); }
From source file:com.adaptris.core.services.GzipService.java
/** * @see com.adaptris.core.Service#doService(AdaptrisMessage) *//* w w w . ja va 2s . c om*/ @Override public void doService(AdaptrisMessage msg) throws ServiceException { InputStream in = null; GZIPOutputStream out = null; try { in = msg.getInputStream(); out = new GZIPOutputStream(msg.getOutputStream()); IOUtils.copy(in, out); } catch (Exception e) { throw new ServiceException(e); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } }
From source file:com.eryansky.common.utils.io.ResourceUtils.java
/** * {res}.properties?/*from ww w . j a va 2 s .co m*/ * @param resource ? * @return ? */ public static String loadFromResource(String resource) { InputStream in = null; BufferedReader reader = null; try { in = new FileInputStream(resource); reader = new BufferedReader(new InputStreamReader(in, "utf-8")); return IOUtils.toString(reader); } catch (Exception excp) { throw new RuntimeException(excp); } finally { IOUtils.closeQuietly(reader); IOUtils.closeQuietly(in); reader = null; } }
From source file:de.knurt.fam.template.controller.json.JSONController2.java
/** * print out json with the key and values got from * {@link JSONController2#getKeyAndValues(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)} * //from w ww . ja va 2s . c o m * @param rq * request * @param rs * response * @return null */ public ModelAndView handleRequest(HttpServletRequest rq, HttpServletResponse rs) { PrintWriter pw = null; try { rs.setHeader("Content-type", "application/json"); pw = rs.getWriter(); IOUtils.write(this.getJSONObject().toString(), pw); } catch (IOException ex) { this.onIOException(ex); } finally { IOUtils.closeQuietly(pw); } return null; }