List of usage examples for org.apache.commons.io IOUtils closeQuietly
public static void closeQuietly(OutputStream output)
OutputStream
. From source file:com.opengamma.financial.currency.CurrencyPairsConfigPopulator.java
public static CurrencyPairs createCurrencyPairs() { InputStream inputStream = CurrencyPairsConfigPopulator.class .getResourceAsStream("market-convention-currency-pairs.csv"); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); String pairStr;/*from w w w.j a va 2 s. c om*/ Set<CurrencyPair> pairs = new HashSet<CurrencyPair>(); try { while ((pairStr = reader.readLine()) != null) { try { CurrencyPair pair = CurrencyPair.parse(pairStr.trim()); pairs.add(pair); } catch (IllegalArgumentException e) { s_logger.debug/*warn*/("Unable to create currency pair from " + pairStr, e); } } } catch (IOException ex) { throw new OpenGammaRuntimeException("Problem loading currency pairs into configuration database", ex); } finally { IOUtils.closeQuietly(inputStream); } return CurrencyPairs.of(pairs); }
From source file:com.ikon.util.JBPMUtils.java
/** * Create instance// ww w . j a va2 s. c om */ public static synchronized JbpmConfiguration getConfig() { if (jbpmConfig == null) { File jbpmCfg = new File(Config.JBPM_CONFIG); FileInputStream fisJbpmCfg = null; try { fisJbpmCfg = new FileInputStream(jbpmCfg); log.info("Creating JBPM configuration from {}", jbpmCfg.getPath()); jbpmConfig = JbpmConfiguration.parseInputStream(fisJbpmCfg); } catch (FileNotFoundException e) { log.info("Creating JBPM default configuration"); jbpmConfig = JbpmConfiguration.getInstance(); } finally { IOUtils.closeQuietly(fisJbpmCfg); } } return jbpmConfig; }
From source file:net.sf.keystore_explorer.utilities.io.CopyUtil.java
/** * Copy data from one stream to another and close I/O. * * @param in/* ww w .j a va2s . c o m*/ * Input stream * @param out * Output stream * @throws IOException * If an I/O problem occurred */ public static void copyClose(InputStream in, OutputStream out) throws IOException { try { copy(in, out); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } }
From source file:com.vigglet.oei.service.GetServicePdfServlet.java
@Override protected void downloadPdf(HttpServletRequest req, HttpServletResponse resp, User user, int modelId) throws Exception { File file = new ServicePdf(ServiceUtil.getInstance().findById(modelId), user).createServiceReport(); resp.setContentLength((int) file.length()); FileInputStream fis = new FileInputStream(file); IOUtils.copy(fis, resp.getOutputStream()); IOUtils.closeQuietly(fis); }
From source file:com.github.sparkfy.util.Log4jPropertyHelper.java
public static void updateLog4jConfiguration(/*Class<?> targetClass,*/ String log4jPath) throws Exception { Properties customProperties = new Properties(); FileInputStream fs = null;/* w w w . ja v a2s . c o m*/ InputStream is = null; try { fs = new FileInputStream(log4jPath); // is = targetClass.getResourceAsStream("/log4j.properties"); is = Utils.getClassLoader().getResourceAsStream("com/github/sparkfy/log4j-defaults.properties"); customProperties.load(fs); Properties originalProperties = new Properties(); originalProperties.load(is); for (Entry<Object, Object> entry : customProperties.entrySet()) { originalProperties.setProperty(entry.getKey().toString(), entry.getValue().toString()); } LogManager.resetConfiguration(); PropertyConfigurator.configure(originalProperties); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(fs); } }
From source file:com.moz.fiji.hive.utils.ByteWritable.java
public static <T extends Writable> T asWritable(byte[] bytes, Class<T> clazz) throws IOException { T result = null;//from www.j a v a2 s. co m DataInputStream dataIn = null; try { result = (T) WritableFactories.newInstance(clazz); ByteArrayInputStream in = new ByteArrayInputStream(bytes); dataIn = new DataInputStream(in); result.readFields(dataIn); } finally { IOUtils.closeQuietly(dataIn); } return result; }
From source file:de.csdev.ebus.core.connection.AbstractEBusConnection.java
public boolean close() throws IOException { if (outputStream != null) { outputStream.flush();/*w ww .j a v a2 s. co m*/ } IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(outputStream); inputStream = null; outputStream = null; return true; }
From source file:com.vigglet.oei.vehicle.GetVehiclePdfServlet.java
@Override protected void downloadPdf(HttpServletRequest req, HttpServletResponse resp, User user, final int modelId) throws Exception { File file = new ServicereportPdf(VehicleUtil.getInstance().findById(modelId), user).createServiceReport(); resp.setContentLength((int) file.length()); FileInputStream fis = new FileInputStream(file); IOUtils.copy(fis, resp.getOutputStream()); IOUtils.closeQuietly(fis); }
From source file:com.ikon.util.Serializer.java
/** * @param obj// w ww.ja v a 2 s. com */ public static void write(String filename, Object obj) { FileOutputStream fos = null; ObjectOutputStream oos = null; try { fos = new FileOutputStream(Config.HOME_DIR + File.separator + filename + ".ser"); oos = new ObjectOutputStream(fos); oos.writeObject(obj); } catch (FileNotFoundException e) { log.error(e.getMessage()); } catch (IOException e) { log.error(e.getMessage()); } finally { IOUtils.closeQuietly(oos); IOUtils.closeQuietly(fos); } }
From source file:com.webpagebytes.cms.utility.CmsConfigurationFactory.java
public static CmsConfiguration getConfiguration() { if (configuration == null) { InputStream is = null;/*from w ww.j a va 2 s.co m*/ synchronized (lock) { try { try { is = new FileInputStream(configPath); } catch (FileNotFoundException e) { is = CmsConfigurationFactory.class.getClassLoader().getResourceAsStream(configPath); } XMLConfigReader reader = new XMLConfigReader(); configuration = reader.readConfiguration(is); } catch (Exception e) { log.log(Level.SEVERE, e.getMessage(), e); return null; } finally { IOUtils.closeQuietly(is); } } } return configuration; }