public synchronized BundleEntry getEntry(String path) { if (!checkedOpen()) return null; ZipEntry zipEntry = getZipEntry(path); if (zipEntry == null) { if (path.length() == 0 || path.charAt(path.length() - 1) == '/') { // this is a directory request lets see if any entries exist in this directory if (containsDir(path)) return new DirZipBundleEntry(this, path); } return null; } return new ZipBundleEntry(zipEntry, this); }
/** * Return an InputStream for the entry. * * @return InputStream for the entry * @exception java.io.IOException */ public InputStream getInputStream() throws IOException { ZipBundleFile zipBundleFile = bundleFile; if (!zipBundleFile.isMruEnabled()) return bundleFile.getZipFile().getInputStream(zipEntry); zipBundleFile.incrementReference(); InputStream result = null; try { return result = new ZipBundleEntryInputStream(zipBundleFile.getZipFile().getInputStream(zipEntry)); } finally { if (result == null) // an exception occurred; decrement the reference zipBundleFile.decrementReference(); } }
@SuppressWarnings("deprecation") public URL getFileURL() { try { return bundleFile.extractDirectory(name).toURL(); } catch (MalformedURLException e) { // this cannot happen. return null; } } }
/** * Extracts a directory and all sub content to disk * @param dirName the directory name to extract * @return the File used to extract the content to. A value * of <code>null</code> is returned if the directory to extract does * not exist or if content extraction is not supported. */ protected synchronized File extractDirectory(String dirName) { if (!checkedOpen()) return null; Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { String entryPath = entries.nextElement().getName(); if (entryPath.startsWith(dirName) && !entryPath.endsWith("/")) //$NON-NLS-1$ getFile(entryPath, false); } return getExtractFile(dirName); }
public synchronized File getFile(String entry, boolean nativeCode) { if (!checkedOpen()) return null; ZipEntry zipEntry = getZipEntry(entry); if (zipEntry == null) return null; File nested = getExtractFile(zipEntry.getName()); if (nested != null) { if (nested.exists()) { if (nested.isDirectory()) extractDirectory(zipEntry.getName()); } else { if (zipEntry.getName().endsWith("/")) { //$NON-NLS-1$ throw new IOException(NLS.bind(Msg.ADAPTOR_DIRECTORY_CREATE_EXCEPTION, nested.getAbsolutePath())); extractDirectory(zipEntry.getName()); } else { InputStream in = zipFile.getInputStream(zipEntry);
public File getFile(String entry, boolean nativeCode) { if (!lockOpen()) { return null; ZipEntry zipEntry = getZipEntry(entry); if (zipEntry == null) return null; File nested = getExtractFile(zipEntry.getName()); if (nested != null) { if (nested.exists()) { if (nested.isDirectory()) extractDirectory(zipEntry.getName()); } else { if (zipEntry.getName().endsWith("/")) { //$NON-NLS-1$ throw new IOException(NLS.bind(Msg.ADAPTOR_DIRECTORY_CREATE_EXCEPTION, nested.getAbsolutePath())); extractDirectory(zipEntry.getName()); } else { InputStream in = zipFile.getInputStream(zipEntry);
private static BundleFile getBundlFile(Class<?> clazz) throws BundleException { URL objUrl = clazz.getProtectionDomain().getCodeSource().getLocation(); File jarOrDirectory = new File(objUrl.getPath()); if (!(jarOrDirectory.exists() && jarOrDirectory.canRead())) { throw new BundleException(String.format("Path '%s' for '%s' is not accessible exist on local file system.", objUrl, clazz.getName()), BundleException.READ_ERROR); } try { return jarOrDirectory.isDirectory() ? new DirBundleFile(jarOrDirectory, false) : new ZipBundleFile(jarOrDirectory, null, null, null); } catch (IOException e) { throw new BundleException(String.format("Cannot access bundle at '%s'.", jarOrDirectory), BundleException.READ_ERROR, e); } }
public void open() throws IOException { getZipFile(); }
throw new NullPointerException(); if (!checkedOpen()) return null; getEntryPaths(path, entryPath.substring(path.length()), recurse, result);
public BundleEntry getEntry(String path) { if (!lockOpen()) { return null; } try { ZipEntry zipEntry = getZipEntry(path); if (zipEntry == null) { if (path.length() == 0 || path.charAt(path.length() - 1) == '/') { // this is a directory request lets see if any entries exist in this directory if (containsDir(path)) return new DirZipBundleEntry(this, path); } return null; } return new ZipBundleEntry(zipEntry, this); } finally { openLock.unlock(); } }
/** * Extracts a directory and all sub content to disk * @param dirName the directory name to extract * @return the File used to extract the content to. A value * of <code>null</code> is returned if the directory to extract does * not exist or if content extraction is not supported. */ File extractDirectory(String dirName) { if (!lockOpen()) { return null; } try { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { String entryPath = entries.nextElement().getName(); if (entryPath.startsWith(dirName) && !entryPath.endsWith("/")) //$NON-NLS-1$ getFile(entryPath, false); } return getExtractFile(dirName); } finally { openLock.unlock(); } }
@SuppressWarnings("deprecation") public URL getFileURL() { try { File file = bundleFile.getFile(zipEntry.getName(), false); if (file != null) return file.toURL(); } catch (MalformedURLException e) { //This can not happen. } return null; } }
public void close() throws IOException { try { stream.close(); } finally { synchronized (this) { if (closed) return; closed = true; } bundleFile.decrementReference(); } }
private void getEntryPaths(String path, String entry, boolean recurse, LinkedHashSet<String> entries) { if (entry.length() == 0) return; int slash = entry.indexOf('/'); if (slash == -1) entries.add(path + entry); else { path = path + entry.substring(0, slash + 1); entries.add(path); if (recurse) getEntryPaths(path, entry.substring(slash + 1), true, entries); } }
@Override public Enumeration<String> getEntryPaths(String path, boolean recurse) { if (!lockOpen()) { return null; getEntryPaths(path, entryPath.substring(path.length()), recurse, result);
public ZipBundleEntryInputStream(InputStream stream) { super(stream); incrementReference(); }
public synchronized File getFile(String entry, boolean nativeCode) { if (!checkedOpen()) return null; ZipEntry zipEntry = getZipEntry(entry); if (zipEntry == null) return null; File nested = getExtractFile(zipEntry.getName()); if (nested != null) { if (nested.exists()) { if (nested.isDirectory()) extractDirectory(zipEntry.getName()); } else { if (zipEntry.getName().endsWith("/")) { //$NON-NLS-1$ throw new IOException(NLS.bind(Msg.ADAPTOR_DIRECTORY_CREATE_EXCEPTION, nested.getAbsolutePath())); extractDirectory(zipEntry.getName()); } else { InputStream in = zipFile.getInputStream(zipEntry);
/** * Extracts a directory and all sub content to disk * @param dirName the directory name to extract * @return the File used to extract the content to. A value * of <code>null</code> is returned if the directory to extract does * not exist or if content extraction is not supported. */ protected synchronized File extractDirectory(String dirName) { if (!checkedOpen()) return null; Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { String entryPath = entries.nextElement().getName(); if (entryPath.startsWith(dirName) && !entryPath.endsWith("/")) //$NON-NLS-1$ getFile(entryPath, false); } return getExtractFile(dirName); }
public File getFile(String entry, boolean nativeCode) { if (!lockOpen()) { return null; ZipEntry zipEntry = getZipEntry(entry); if (zipEntry == null) return null; File nested = getExtractFile(zipEntry.getName()); if (nested != null) { if (nested.exists()) { if (nested.isDirectory()) extractDirectory(zipEntry.getName()); } else { if (zipEntry.getName().endsWith("/")) { //$NON-NLS-1$ throw new IOException(NLS.bind(Msg.ADAPTOR_DIRECTORY_CREATE_EXCEPTION, nested.getAbsolutePath())); extractDirectory(zipEntry.getName()); } else { InputStream in = zipFile.getInputStream(zipEntry);
public BundleFile createBundleFile(File content, Generation generation, boolean isDirectory, boolean isBase) { BundleFile result; try { if (isDirectory) { boolean strictPath = Boolean.parseBoolean(equinoxContainer.getConfiguration().getConfiguration(EquinoxConfiguration.PROPERTY_STRICT_BUNDLE_ENTRY_PATH, Boolean.FALSE.toString())); result = new DirBundleFile(content, strictPath); } else { result = new ZipBundleFile(content, generation, mruList, getConfiguration().getDebug()); } } catch (IOException e) { throw new RuntimeException("Could not create bundle file.", e); //$NON-NLS-1$ } return wrapBundleFile(result, generation, isBase); }