List of usage examples for org.apache.commons.io IOUtils closeQuietly
public static void closeQuietly(OutputStream output)
OutputStream
. From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.XStreamTools.java
public static void toXML(Object object, File outputFile) throws IOException { FileOutputStream outputStream = new FileOutputStream(outputFile); getXStream().toXML(object, outputStream); IOUtils.closeQuietly(outputStream); }
From source file:com.thoughtworks.go.agent.testhelpers.FakeAgentCertificateServlet.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ObjectOutputStream outputStream = null; try {//from www . j a va 2 s .c o m outputStream = new ObjectOutputStream(response.getOutputStream()); outputStream.writeObject(AgentCertificateMother.agentCertificate()); } finally { IOUtils.closeQuietly(outputStream); } }
From source file:com.l2jfree.sql.L2DatabaseInstaller.java
public static void check() throws SAXException, IOException, ParserConfigurationException { final TreeMap<String, String> tables = new TreeMap<String, String>(); final TreeMap<Double, String> updates = new TreeMap<Double, String>(); final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); // FIXME add validation factory.setIgnoringComments(true);//from w w w . ja v a2 s .c om final List<Document> documents = new ArrayList<Document>(); InputStream is = null; try { // load default database schema from resources is = L2DatabaseInstaller.class.getResourceAsStream("database_schema.xml"); documents.add(factory.newDocumentBuilder().parse(is)); } finally { IOUtils.closeQuietly(is); } final File f = new File("./config/database_schema.xml"); // load optional project specific database tables/updates (fails on already existing) if (f.exists()) documents.add(factory.newDocumentBuilder().parse(f)); for (Document doc : documents) { for (Node n1 : L2XML.listNodesByNodeName(doc, "database")) { for (Node n2 : L2XML.listNodesByNodeName(n1, "table")) { final String name = L2XML.getAttribute(n2, "name"); final String definition = L2XML.getAttribute(n2, "definition"); final String oldDefinition = tables.put(name, definition); if (oldDefinition != null) throw new RuntimeException("Found multiple tables with name " + name + "!"); } for (Node n2 : L2XML.listNodesByNodeName(n1, "update")) { final Double revision = Double.valueOf(L2XML.getAttribute(n2, "revision")); final String query = L2XML.getAttribute(n2, "query"); final String oldQuery = updates.put(revision, query); if (oldQuery != null) throw new RuntimeException("Found multiple updates with revision " + revision + "!"); } } } createRevisionTable(); final double databaseRevision = getDatabaseRevision(); if (databaseRevision == -1) // no table exists { for (Entry<String, String> table : tables.entrySet()) { final String tableName = table.getKey(); final String tableDefinition = table.getValue(); installTable(tableName, tableDefinition); } if (updates.isEmpty()) insertRevision(0); else insertRevision(updates.lastKey()); } else // check for possibly required updates { for (Entry<String, String> table : tables.entrySet()) { final String tableName = table.getKey(); final String tableDefinition = table.getValue(); if (L2Database.tableExists(tableName)) continue; System.err.println("Table '" + tableName + "' is missing, so the server attempts to install it."); System.err.println("WARNING! It's highly recommended to check the results manually."); installTable(tableName, tableDefinition); } for (Entry<Double, String> update : updates.entrySet()) { final double updateRevision = update.getKey(); final String updateQuery = update.getValue(); if (updateRevision > databaseRevision) { executeUpdate(updateQuery); insertRevision(updateRevision); } } } }
From source file:dk.netarkivet.common.utils.ChecksumCalculator.java
/** * Calculate MD5 for a file./* w ww .j ava 2s . c o m*/ * * @param src The file to calculate MD5 for. * @return The MD5 sum of a file as a 32 characters long Hex string. */ public static String calculateMd5(final File src) { ArgumentNotValid.checkNotNull(src, "File src"); ArgumentNotValid.checkTrue(src.isFile(), "Argument should be a file"); // Get the MD5 and return it try { final FileInputStream fileInputStream = new FileInputStream(src); try { return calculateMd5(fileInputStream); } finally { IOUtils.closeQuietly(fileInputStream); } } catch (FileNotFoundException e) { throw new IOFailure("Could not read file '" + src.getAbsolutePath() + "'", e); } }
From source file:net.sf.keystore_explorer.crypto.digest.DigestUtil.java
/** * Get a digest of the input stream./*from www. j a v a2 s.co m*/ * * @param istream * Input stream to digest * @param digestType * The message digest algorithm * @return The message digest * @throws CryptoException * If message digester could not be created */ public static byte[] getMessageDigest(InputStream istream, DigestType digestType) throws CryptoException { MessageDigest messageDigester = getMessageDigester(digestType); try { byte[] buffer = new byte[2048]; int read = 0; while ((read = istream.read(buffer)) != -1) { messageDigester.update(buffer, 0, read); } byte[] messageDigest = messageDigester.digest(); return messageDigest; } catch (IOException ex) { throw new CryptoException(res.getString("NoCreateDigest.exception.message"), ex); } finally { IOUtils.closeQuietly(istream); } }
From source file:com.lightboxtechnologies.nsrl.RecordLoader.java
public void load(Reader r, LineHandler lh) throws IOException { BufferedReader br = null;//from w ww.j a v a 2 s . c om try { br = new BufferedReader(r); // first line gives column names, skip it br.readLine(); // process each line String line; long linenum = 0; while ((line = br.readLine()) != null) { ++linenum; lh.handle(line, linenum); } br.close(); } finally { IOUtils.closeQuietly(br); } }
From source file:com.igormaznitsa.mindmap.swing.panel.utils.Icons.java
private Icons(final String name) { final InputStream in = ScalableIcon.class.getClassLoader() .getResourceAsStream("com/igormaznitsa/mindmap/swing/panel/icons/" + name); //NOI18N try {//from www . j a v a2 s . c o m this.icon = new ImageIcon(ImageIO.read(in)); } catch (IOException ex) { throw new Error("Can't load icon " + name, ex); //NOI18N } finally { IOUtils.closeQuietly(in); } }
From source file:com.textocat.textokit.postagger.opennlp.DefaultPOSModelHolder.java
@Override public void load(DataResource dr) throws ResourceInitializationException { if (model != null) { throw new IllegalStateException(); }// w w w. ja v a2 s .c o m InputStream is = null; try { is = dr.getInputStream(); model = new POSModel(is); } catch (IOException e) { throw new IllegalStateException(e); } finally { IOUtils.closeQuietly(is); } }
From source file:gov.nih.nci.ncicb.tcga.dcc.common.dao.TCGAProperties.java
private void init() throws IOException { FileInputStream fileInputStream = null; try {// www . j av a 2s . c om properties = new Properties(); //noinspection IOResourceOpenedButNotSafelyClosed fileInputStream = new FileInputStream(new File(propertyFilePath, propertyFileName)); properties.load(fileInputStream); } finally { IOUtils.closeQuietly(fileInputStream); } }
From source file:com.autentia.web.rest.wadl.zipper.Zip.java
public void close() { IOUtils.closeQuietly(zipOutputStream); }