public static void copyToFile(InputStream is, File dst) throws IOException { FileOutputStream fos = null; try { fos = new FileOutputStream(dst); byte[] buf = new byte[1024]; int i = 0; while ((i = is.read(buf)) != -1) { fos.write(buf, 0, i); } } finally { closeQuietly(fos); } }
public static void copyFile(File src, File dst) throws IOException { FileInputStream fis = null; try { fis = new FileInputStream(src); copyToFile(fis, dst); } finally { closeQuietly(fis); } }
private static void saveDevice(XMLElement doc) { File configFile = new File(".", "device-tmp.xml"); FileWriter fw = null; try { fw = new FileWriter(configFile); doc.write(fw); fw.close(); } catch (IOException ex) { System.out.println(ex); } finally { IOUtils.closeQuietly(fw); } }
IOUtils.closeQuietly(buildVersionInputStream); IOUtils.closeQuietly(mavenDataInputStream);
private Image getImage(String str) throws IOException { // TODO not always true, there could be some loading images before // invoke startApp, right now getCurrentMIDlet returns prevoius MIDlet Object midlet = MIDletBridge.getCurrentMIDlet(); if (midlet == null) { midlet = getClass(); } InputStream is = midlet.getClass().getResourceAsStream(str); if (is == null) { throw new IOException(str + " could not be found."); } try { return getImage(is); } finally { IOUtils.closeQuietly(is); } }
private Image getImage(String str) throws IOException { // TODO not always true, there could be some loading images before // invoke startApp, right now getCurrentMIDlet returns prevoius MIDlet Object midlet = MIDletBridge.getCurrentMIDlet(); if (midlet == null) { midlet = getClass(); } InputStream is = midlet.getClass().getResourceAsStream(str); if (is == null) { throw new IOException(str + " could not be found."); } try { return getImage(is); } finally { IOUtils.closeQuietly(is); } }
} catch (Throwable ignore) { } finally { IOUtils.closeQuietly(out);
private static void loadConfigFile(String configFileName) throws IOException { File configFile = new File(getConfigPath(), configFileName); InputStream is = null; String xml = ""; try { InputStream dis = new BufferedInputStream(is = new FileInputStream(configFile)); while (dis.available() > 0) { byte[] b = new byte[dis.available()]; dis.read(b); xml += new String(b); } configXml = new XMLElement(); configXml.parseString(xml); } catch (XMLParseException e) { Logger.error(e); createDefaultConfigXml(); } finally { IOUtils.closeQuietly(is); } }
IOUtils.closeQuietly(jis); IOUtils.closeQuietly(ijis); IOUtils.closeQuietly(jos);
IOUtils.closeQuietly(is);
public static void saveConfig() { urlsMRU.save(configXml.getChildOrNew("files").getChildOrNew("recent")); File configFile = new File(getConfigPath(), "config2.xml"); getConfigPath().mkdirs(); FileWriter fw = null; try { fw = new FileWriter(configFile); configXml.write(fw); fw.close(); } catch (IOException ex) { Logger.error(ex); } finally { IOUtils.closeQuietly(fw); } }
writer.write("</html>\n"); } finally { IOUtils.closeQuietly(writer);
IOUtils.closeQuietly(jis); IOUtils.closeQuietly(is);
private static XMLElement loadDeviceDescriptor(ClassLoader classLoader, String descriptorLocation) throws IOException { InputStream descriptor = classLoader.getResourceAsStream(descriptorLocation); if (descriptor == null) { throw new IOException("Cannot find descriptor at: " + descriptorLocation); } XMLElement doc; try { doc = loadXmlDocument(descriptor); } finally { IOUtils.closeQuietly(descriptor); } String parent = doc.getStringAttribute("extends"); if (parent != null) { return inheritXML(loadDeviceDescriptor(classLoader, expandResourcePath(besourceBase(descriptorLocation), parent)), doc, "/"); } return doc; }
Message.error("Unable to read MANIFEST", e); } finally { IOUtils.closeQuietly(is);