/** * When this WebResource is no longer needed it should be shutdown to return * underlying resources back to the OS. */ public void shutdown() { IOUtil.close(client); }
public void releaseResources() { IOUtil.close(bdtRaf); bdtRaf = null; }
public static Properties loadProperties(File propertiesFile) { Properties properties = new Properties(); if (propertiesFile.exists()) { FileInputStream in = null; try { in = new FileInputStream(propertiesFile); properties.load(in); } catch (Exception e) { Log.e(TAG, "Error loading properties", e); } finally { IOUtil.close(in); } } return properties; }
/** * Outputs the mappings for debug purposes to the log file. */ private void trace() { if (LOGGER.isTraceEnabled()) { PrintStream ps = null; try { ByteArrayOutputStream os = new ByteArrayOutputStream(); ps = new PrintStream(os); dump(ps); String output = os.toString("UTF8"); LOGGER.trace(output); } catch (UnsupportedEncodingException e) { // It is impossible! LOGGER.error("Encoding UTF8 not supported.", e); } finally { IOUtil.close(ps); } } }
private int readIncfile() throws IOException { int ret = -1; if (incfile == null) { // then attempt to initialise it initIncFile(); } if (this.incfile != null) { FileInputStream fis = null; try { fis = new FileInputStream(this.incfile); byte[] buffer = new byte[4]; if (fis.read(buffer) != 4) { LOGGER.error("Read data is not of appropriate size of 4 bytes!"); throw new IOException("Incfile is not 4 bytes long"); } ret = SwordUtil.decodeLittleEndian32(buffer, 0); // also store this this.incfileValue = ret; } catch (FileNotFoundException e) { LOGGER.error("Error on writing to incfile, file should exist already!: {}", e.getMessage(), e); } finally { IOUtil.close(fis); } } return ret; }
e.printStackTrace(); } finally { IOUtil.close(inputStream);
public static Properties readPropertiesFile(String folder, String filename) { Properties returnProperties = new Properties(); Resources resources = BibleApplication.Companion.getApplication().getResources(); AssetManager assetManager = resources.getAssets(); if (!filename.endsWith(DOT_PROPERTIES)) { filename = filename+DOT_PROPERTIES; } if (StringUtils.isNotEmpty(folder)) { filename = folder+File.separator+filename; } // Read from the /assets directory InputStream inputStream = null; try { // check to see if a user has created his own reading plan with this name inputStream = assetManager.open(filename); returnProperties.load(inputStream); log.debug("The properties are now loaded from: " + filename); } catch (IOException e) { System.err.println("Failed to open property file:"+filename); e.printStackTrace(); } finally { IOUtil.close(inputStream); } return returnProperties; } }
/** * Load up properties given by a URI. * * @param uri * the location of the properties * @return the properties given by the URI * @throws IOException a problem with I/O happened */ public static PropertyMap loadProperties(URI uri) throws IOException { InputStream is = null; try { is = NetUtil.getInputStream(uri); PropertyMap prop = new PropertyMap(); prop.load(is); is.close(); return prop; } finally { IOUtil.close(is); } }
IOUtil.close(xslStream);
} catch (IOException ex) { IOUtil.close(bdtRaf);
/** * Store the properties at the location given by the uri using the supplied * title. * * @param properties * the properties to store * @param uri * the location of the store * @param title * the label held in the properties file * @throws IOException a problem with I/O happened */ public static void storeProperties(PropertyMap properties, URI uri, String title) throws IOException { OutputStream out = null; try { out = NetUtil.getOutputStream(uri); PropertyMap temp = new PropertyMap(); temp.putAll(properties); temp.store(out, title); } finally { IOUtil.close(out); } }