/** * 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); }
/** * Unpack a zip file to a given directory. Honor the paths as given in the * zip file. * * @param file * The zip file to download * @param destdir * The directory to unpack up * @throws IOException * If there is an file error */ public static void unpackZip(File file, File destdir) throws IOException { unpackZip(file, destdir, true); }
public void reload(Filter<String> keepers) throws BookException { // Always run if it is filtered // Always run if a filter is supplied // Do not run if it is already not filtered and no filter is supplied if (!filtered && keepers == null) { return; } this.supported = true; if (configJSword != null) { configJSword.clear(); } if (configFrontend != null) { configFrontend.clear(); } try { if (installed) { loadFile(keepers); } else { byte[] buffer = IOUtil.getZipEntry(bookConf); loadBuffer(buffer, keepers); } adjustConfig(); report(configAll); this.configJSword = addConfig(MetaDataLocator.JSWORD); this.configFrontend = addConfig(MetaDataLocator.FRONTEND); } catch (IOException ex) { throw new BookException("unable to load conf", ex); } }
public void installDownloadedIndex(Book book, URI tempDest) throws BookException { try { URI storage = getStorageArea(book); File zip = NetUtil.getAsFile(tempDest); IOUtil.unpackZip(zip, NetUtil.getAsFile(storage)); //todo Index.Version management?? } catch (IOException ex) { // TRANSLATOR: The search index could not be moved to it's final location. throw new BookException(JSMsg.gettext("Installation failed."), ex); } }
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; } }