List of usage examples for org.apache.commons.io IOUtils closeQuietly
public static void closeQuietly(OutputStream output)
OutputStream
. From source file:demo.server.FlowServiceImpl.java
@Override public String getMainFlow() { final InputStream flowFileStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream("/Main.flow"); if (flowFileStream == null) { return null; } else {//from w ww . j a v a 2s . c om try { return IOUtils.toString(flowFileStream, "UTF-8"); } catch (final IOException e) { return null; } finally { IOUtils.closeQuietly(flowFileStream); } } }
From source file:net.firejack.platform.core.utils.InstallUtils.java
public static <E extends Entry> Environments<E> deserialize(InputStream stream, Class... classes) { try {//w w w .ja v a2s . c o m return FileUtils.readJAXB(stream, classes); } catch (Exception e) { logger.warn("The environment.xml has not been parsed."); } finally { IOUtils.closeQuietly(stream); } return null; }
From source file:net.sf.zekr.engine.theme.Theme.java
/** * Save a ThemeData configuration file.//w w w . jav a 2 s . c o m * * @param td theme data object to be stored to the disk * @throws IOException */ public static void save(ThemeData td) throws IOException { OutputStreamWriter osw = new OutputStreamWriter( new FileOutputStream(Naming.getThemePropsDir() + "/" + td.fileName)); LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>(); map.put("name", td.name); map.put("author", td.author); map.put("version", td.version); map.putAll(td.props); ConfigUtils.write(new MapConfiguration(map), osw); // ConfigurationUtils.dump(new MapConfiguration(map), new PrintWriter(osw)); IOUtils.closeQuietly(osw); }
From source file:net.bpelunit.util.ZipUtil.java
public static void zipDirectory(File directory, File zipFile) throws IOException { @SuppressWarnings("unchecked") Collection<File> files = FileUtils.listFiles(directory, null, true); FileOutputStream fzos = null; ZipOutputStream zos = null;/*w ww . j a v a2 s . c o m*/ try { fzos = new FileOutputStream(zipFile); zos = new ZipOutputStream(fzos); for (File f : files) { String fileNameInZIP = directory.toURI().relativize(f.toURI()).getPath(); ZipEntry zipEntry = new ZipEntry(fileNameInZIP); zos.putNextEntry(zipEntry); FileInputStream fileInputStream = new FileInputStream(f); try { IOUtils.copy(fileInputStream, zos); } finally { IOUtils.closeQuietly(fileInputStream); } } } finally { IOUtils.closeQuietly(zos); IOUtils.closeQuietly(fzos); } }
From source file:au.org.emii.geoserver.extensions.filters.layer.data.io.FilterConfigurationFile.java
public void write(List<Filter> filters) throws TemplateException, IOException { FilterConfigurationWriter configurationWriter = new FilterConfigurationWriter(filters); Writer writer = null;/* www.j a v a 2 s . c o m*/ try { writer = new FileWriter(getFilePath()); configurationWriter.write(writer); } finally { IOUtils.closeQuietly(writer); } }
From source file:io.mandrel.io.payload.InputStreamPayload.java
/** * if we created the stream, then it is already consumed on close. */ @Override public void release() { IOUtils.closeQuietly(rawContent); }
From source file:com.l2jfree.security.HexID.java
/** * Save hexadecimal ID of the server in the properties file. * //from www . ja va2 s .com * @param serverId game server ID * @param hexId (String) : hexadecimal ID of the server to store * @param fileName (String) : name of the properties file */ public static void saveHexid(int serverId, String hexId, String fileName) { OutputStream out = null; try { out = new FileOutputStream(fileName); final Properties hexSetting = new Properties(); hexSetting.setProperty("ServerID", String.valueOf(serverId)); hexSetting.setProperty("HexID", hexId); hexSetting.store(out, "the hexID to auth into login"); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(out); } }
From source file:com.mycompany.osgiwebfelix.BundleInstaller.java
public Bundle installBundleFromFile(File savedBundleFile, boolean startBundle, boolean updateExistingBundle) throws IOException, BundleException { InputStream bundleInputStream = null; BundleContext bundleContext = (BundleContext) sc.getAttribute(BundleContext.class.getName()); try {/*w w w . ja v a 2 s . c o m*/ bundleInputStream = FileUtils.openInputStream(savedBundleFile); final String bundleFileLocationAsURL = savedBundleFile.toURI().toURL().toExternalForm(); Bundle bundle = bundleContext.installBundle(bundleFileLocationAsURL, bundleInputStream); bundle.start(); return bundle; } finally { IOUtils.closeQuietly(bundleInputStream); } }
From source file:com.textocat.textokit.morph.opencorpora.resource.MorphDictionaryImplTest.java
@Before public void setUp() throws Exception { FileInputStream fis = FileUtils.openInputStream(new File("test-data/dict.opcorpora.test.xml")); try {//from w w w . jav a 2 s .c o m dict = XmlDictionaryParser.parse(fis); gm = dict.getGramModel(); } finally { IOUtils.closeQuietly(fis); } dict.setWfPredictor(new DummyWordformPredictor(dict)); }
From source file:com.alibaba.simpleimage.BaseTest.java
public void doReadWrite(File in, boolean toRGB, File out, ImageFormat format) throws Exception { WriteRender wr = null;/* w w w .j av a2s. c o m*/ InputStream inStream = new FileInputStream(in); try { ReadRender rr = new ReadRender(inStream, toRGB); wr = new WriteRender(rr, out, format); wr.render(); } finally { IOUtils.closeQuietly(inStream); if (wr != null) { wr.dispose(); } } }