/** * Look for the resource in the home directories, returning the first * readable file. * * @param search * must be non-null, non-empty * @return the URI of the home of the resource */ public static URI findHomeResource(String search) { if (homes == null) { return null; } for (int i = 0; i < homes.length; i++) { URI homeURI = homes[i]; URI override = NetUtil.lengthenURI(homeURI, search); // Make sure the file exists and can be read if (NetUtil.canRead(override)) { return override; } } return null; }
/** * Delete a URI. Currently this only works for file: URIs, however the * interface should not need to change to handle more complex URIs * * @param orig * The URI to delete * @return whether the deleted happened * @throws IOException a problem with I/O happened */ public static boolean delete(URI orig) throws IOException { checkFileURI(orig); return new File(orig.getPath()).delete(); }
/** * When was the given URI last modified. If no modification time is * available then this method return the current time. * * @param uri the URI to examine * @param proxyHost the proxy host * @return the last modified date */ public static long getLastModified(URI uri, String proxyHost) { return getLastModified(uri, proxyHost, null); }
temp = NetUtil.getTemporaryURI("swd", ZIP_SUFFIX); IOUtil.unpackZip(NetUtil.getAsFile(temp), dldir, true, SwordConstants.DIR_CONF, SwordConstants.DIR_DATA); File jswordHome = NetUtil.getAsFile(CWProject.instance().getWritableProjectDir()); IOUtil.unpackZip(NetUtil.getAsFile(temp), jswordHome, false, SwordConstants.DIR_CONF, SwordConstants.DIR_DATA); sbmd.setLibrary(NetUtil.getURI(dldir)); SwordBookDriver.registerNewBook(sbmd); NetUtil.delete(temp); } catch (IOException e) { log.warn("Error deleting temp download file.", e);
temp = NetUtil.getTemporaryURI("swd", ".tmp"); File tempFile = NetUtil.getAsFile(temp); if (!FileManager.copyFile(tempFile, target)) { Log.e(TAG, "Download Error renaming temp file "+tempFile+" to:"+target); NetUtil.delete(temp); } catch (IOException e) { Log.w(TAG, "Error deleting temp download file:" + e.getMessage());
URI home = NetUtil.getURI(new File(cwHome)); if (NetUtil.canWrite(home)) { writeHome = home; } else if (NetUtil.canRead(home)) { readHome = home; URI uricache = getWritableProjectSubdir(DIR_NETCACHE, true); File filecache = new File(uricache.getPath()); NetUtil.setURICacheDir(filecache); } catch (IOException ex) { this.frontendReadHome = NetUtil.lengthenURI(this.readHome, this.frontendName);
/** * Download and install a search index * * @param book * The book to get an index for * @param installer * @throws IOException * @throws InstallException * @throws BookException */ public static void downloadIndex(Book book, Installer installer) throws IOException, InstallException, BookException { // Get a temp home URI tempDownload = NetUtil.getTemporaryURI(TEMP_PREFIX, TEMP_SUFFIX); IndexStatus finalStatus = IndexStatus.UNDONE; try { // Now we know what installer to use, download to the temp file installer.downloadSearchIndex(book, tempDownload); // And install from that file. IndexManager idxman = IndexManagerFactory.getIndexManager(); book.setIndexStatus(IndexStatus.CREATING); idxman.installDownloadedIndex(book, tempDownload); finalStatus = IndexStatus.DONE; } finally { book.setIndexStatus(finalStatus); // tidy up after ourselves if (tempDownload != null) { NetUtil.delete(tempDownload); } } }
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); } }
URI confDir = NetUtil.lengthenURI(cacheDir, "mods.d.zip"); URI cache = getCachedIndexFile(); if (!NetUtil.isFile(cache)) { reloadBookList(); if (!NetUtil.isFile(confDir)) { unpack(cacheDir, cache); ZipArchiveInputStream zin = null; try { fin = NetUtil.getInputStream(confDir); zin = new ZipArchiveInputStream(fin); while (true) {
if (TransformingSAXEventProvider.developmentMode) { if (tinfo != null) { modtime = NetUtil.getLastModified(xsluri); xslStream = NetUtil.getInputStream(xsluri); if (transfact == null) { transfact = TransformerFactory.newInstance(); modtime = NetUtil.getLastModified(xsluri);
private InstalledIndex() { props = new PropertyMap(); URI propURI = getPropertyFileURI(); try { // props = ResourceUtil.getProperties(getClass()); if (NetUtil.canRead(propURI)) { props = NetUtil.loadProperties(propURI); } /* Initial values if prop file empty */ if (props.size() == 0) { props.put(INSTALLED_INDEX_DEFAULT_VERSION, String.valueOf(DEFAULT_INSTALLED_INDEX_VERSION)); storeInstalledIndexMetadata(); } } catch (IOException e) { log.error("Property file read error: " + propURI.toString(), e); } }
URI child = NetUtil.getURI(entryFile); OutputStream dataOut = NetUtil.getOutputStream(child); InputStream dataIn = zf.getInputStream(entry);
/** * @param uri * the resource whose size is wanted * @return the size of that resource */ public static int getSize(URI uri) { return getSize(uri, null, null); }
/** * Attempt to obtain an OutputStream from a URI. The simple case will open * it if it is local. Otherwise, it will call * uri.toURL().openConnection().getOutputStream(), however in some JVMs (MS * at least this fails where new FileOutputStream(url) works. * * @param uri * The URI to attempt to write to * @return An OutputStream connection * @throws IOException a problem with I/O happened */ public static OutputStream getOutputStream(URI uri) throws IOException { return getOutputStream(uri, false); }
BufferedReader din = null; try { in = NetUtil.getInputStream(index);
/** * Read an existing index and use it. * * @param book the book * @param storage * @throws BookException * If we fail to read the index files */ public LuceneIndex(Book book, URI storage) throws BookException { this.book = book; try { this.path = NetUtil.getAsFile(storage).getCanonicalPath(); } catch (IOException ex) { // TRANSLATOR: Error condition: Could not initialize a search index. throw new BookException(JSMsg.gettext("Failed to initialize Lucene search engine."), ex); } initDirectoryAndSearcher(); }
public static int getSize(URI uri, String proxyHost) { return getSize(uri, proxyHost, null); }
out = NetUtil.getOutputStream(dest);
/** * 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); } }
public void scheduleIndexCreation(final Book book) { book.setIndexStatus(IndexStatus.SCHEDULED); IndexStatus finalStatus = IndexStatus.UNDONE; try { URI storage = getStorageArea(book); Index index = new LuceneIndex(book, storage, this.policy); //todo update Installed IndexVersion for newly created index // todo implement: Installed.Index.Version.Book.XXX value add/update in metadata file after creation, use value getLatestIndexVersion(book) // We were successful if the directory exists. if (NetUtil.getAsFile(storage).exists()) { finalStatus = IndexStatus.DONE; INDEXES.put(book, index); //update IndexVersion InstalledIndex.instance().storeLatestVersionAsInstalledIndexMetadata(book); } } catch (IOException e) { Reporter.informUser(LuceneIndexManager.this, e); } catch (BookException e) { Reporter.informUser(LuceneIndexManager.this, e); } finally { book.setIndexStatus(finalStatus); } }