List of usage examples for org.apache.commons.io IOUtils closeQuietly
public static void closeQuietly(OutputStream output)
OutputStream
. From source file:com.ikon.util.DatabaseDialectAdapter.java
/** * Adapt "default.sql" to every supported database *///from w w w.j ava 2 s. c o m public static String dialectAdapter(InputStream is, String dialect) { StringBuilder sb = new StringBuilder(); BufferedReader br = null; String line; try { br = new BufferedReader(new InputStreamReader(is)); if (Oracle10gDialect.class.getCanonicalName().equals(dialect)) { log.info("Generation SQL for Oracle10gDialect..."); while ((line = br.readLine()) != null) { sb.append(oracleAdapter(line)).append("\n"); } } else if (SQLServerDialect.class.getCanonicalName().equals(dialect)) { log.info("Generation SQL for SQLServerDialect..."); while ((line = br.readLine()) != null) { sb.append(sqlServerAdapter(line)).append("\n"); } } else { log.info("Generation SQL for GeneralDialect..."); while ((line = br.readLine()) != null) { sb.append(line).append("\n"); } } } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(br); IOUtils.closeQuietly(is); } return sb.toString().trim(); }
From source file:eu.europa.esig.dss.applet.util.FileTypeDetectorUtils.java
/** * @param file//from w ww . j a v a 2 s.c om * @return * @throws FileNotFoundException */ private static boolean isCMS(final File file) throws FileNotFoundException { FileInputStream inputStream = null; try { inputStream = new FileInputStream(file); new CMSSignedData(inputStream); return true; } catch (final CMSException e) { return false; } finally { IOUtils.closeQuietly(inputStream); } }
From source file:it.geosolutions.geoserver.jms.impl.handlers.DocumentFile.java
/** * /* w w w. j av a2 s . c o m*/ * @param xmlString * @return * @throws JDOMException * @throws IOException */ protected static Document parser(String xmlString) throws JDOMException, IOException { InputSource source = null; StringReader reader = null; try { reader = new StringReader(xmlString); source = new InputSource(reader); final SAXBuilder builder = new SAXBuilder(); final Document doc = builder.build(source); return doc; } finally { IOUtils.closeQuietly(reader); } }
From source file:com.msopentech.odatajclient.engine.data.ODataWriter.java
/** * Writes a collection of OData entities. * * @param entities entities to be serialized. * @param format serialization format.//ww w . j ava2s . c om * @param outputType whether to explicitly output type information. * @return stream of serialized objects. */ public static InputStream writeEntities(final Collection<ODataEntity> entities, final ODataPubFormat format, final boolean outputType) { final ByteArrayOutputStream output = new ByteArrayOutputStream(); try { for (ODataEntity entity : entities) { Serializer.entry( ODataBinder.getEntry(entity, ResourceFactory.entryClassForFormat(format), outputType), output); } return new ByteArrayInputStream(output.toByteArray()); } finally { IOUtils.closeQuietly(output); } }
From source file:com.openshift.internal.restclient.capability.resources.OpenShiftBinaryPodLogRetrieval.java
@Override protected void cleanup() { follow = false;// w ww. j a va 2 s. c o m if (getProcess() != null) { IOUtils.closeQuietly(getProcess().getInputStream()); IOUtils.closeQuietly(getProcess().getErrorStream()); } }
From source file:core.service.bus.socket.SocketWrapper.java
public void close() { lock.release();//from ww w. j a v a2 s . c o m IOUtils.closeQuietly(input); IOUtils.closeQuietly(output); try { socket.close(); } catch (IOException e) { // ignore } }
From source file:com.handcraftedbits.bamboo.plugin.go.task.test.FileOutputHandler.java
@Override public void process(@NotNull final InputStream output) throws ProcessException { final FileOutputStream fileOutput; try {//from ww w . j av a2s . c o m fileOutput = new FileOutputStream(this.file, true); } catch (final FileNotFoundException e) { throw new ProcessException(e); } try { IOUtils.copy(output, fileOutput); } catch (final IOException e) { throw new ProcessException(e); } finally { IOUtils.closeQuietly(fileOutput); } }
From source file:com.ctriposs.r2.filter.compression.GzipCompressor.java
@Override public byte[] inflate(InputStream data) throws CompressionException { ByteArrayOutputStream out;//from ww w. j a v a 2 s . co m GZIPInputStream gzip = null; try { out = new ByteArrayOutputStream(); gzip = new GZIPInputStream(data); IOUtils.copy(gzip, out); } catch (IOException e) { throw new CompressionException(CompressionConstants.DECODING_ERROR + getContentEncodingName(), e); } finally { if (gzip != null) { IOUtils.closeQuietly(gzip); } } return out.toByteArray(); }
From source file:com.formkiq.core.util.Zips.java
/** * Is Zip file valid./*from www. ja v a 2s.c o m*/ * @param file {@link File} * @return boolean * @throws IOException IOException */ public static boolean isValid(final File file) throws IOException { ZipFile zipfile = new ZipFile(file); IOUtils.closeQuietly(zipfile); return true; }
From source file:com.netsteadfast.greenstep.util.DynamicHqlUtils.java
public static DynamicHql loadResource(String resource) throws Exception { DynamicHql dynamicHql = resourceDataMap.get(resource); if (dynamicHql == null) { InputStream in = null;//from ww w. ja va 2s . c o m try { in = DynamicHqlUtils.class.getResourceAsStream("/dynamichql/" + resource); byte[] xmlBytes = IOUtils.toByteArray(in); JAXBContext jaxbContext = JAXBContext.newInstance(DynamicHql.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); dynamicHql = (DynamicHql) jaxbUnmarshaller.unmarshal(new ByteArrayInputStream(xmlBytes)); resourceDataMap.put(resource, dynamicHql); } catch (IOException e) { logger.error(e.getMessage().toString()); throw e; } finally { if (in != null) { IOUtils.closeQuietly(in); } in = null; } } return dynamicHql; }