@Override public boolean empty() { return Shell32.isAvailable() && Shell32.getInstance().SHEmptyRecycleBin(null, null, Shell32API.SHERB_NOCONFIRMATION) == 0; }
/** * Shorthand for {@link #getResourceAsURL(String, ClassLoader, AbstractFile)} called with the * {@link #getDefaultClassLoader() default class loader} and a <code>null</code> root package file. * * @param path forward slash-separated path to the resource to look for, relative to the parent classpath * location (directory or JAR file) that contains it. * @return a URL pointing to the resource, or <code>null</code> if the resource couldn't be located */ public static URL getResourceAsURL(String path) { return getResourceAsURL(path, getDefaultClassLoader(), null); }
/** * Shorthand for {@link #getResourceAsFile(String, ClassLoader, AbstractFile)} called with the * {@link #getDefaultClassLoader() default class loader} and a <code>null</code> root package file. * * @param path forward slash-separated path to the resource to look for, relative to the parent classpath * location (directory or JAR file) that contains it. * @return an AbstractFile that represents the resource, or <code>null</code> if the resource couldn't be located */ public static AbstractFile getResourceAsFile(String path) { return getResourceAsFile(removeLeadingSlash(path), getDefaultClassLoader(), null); }
/** * Tests <code>ResourceLoader#getPackageResourceAsURL</code> methods. * * @throws IOException should not happen */ @Test public void testPackageResourceAsURL() throws IOException { assertReadable(ResourceLoader.getPackageResourceAsURL(getThisPackage(), getExistingResourceName())); assert ResourceLoader.getPackageResourceAsURL(getThisPackage(), getNonExistingResourceName()) == null; assertReadable(ResourceLoader.getPackageResourceAsURL(getThisPackage(), getExistingResourceName(), getThisClassLoader(), getRootPackageFile())); assert ResourceLoader.getPackageResourceAsURL(getThisPackage(), getNonExistingResourceName(), getThisClassLoader(), getRootPackageFile()) == null; }
/** * Tests <code>ResourceLoader#getPackageResourceAsStream</code> methods. * * @throws IOException should not happen */ @Test public void testPackageResourceAsStream() throws IOException { assertReadable(ResourceLoader.getPackageResourceAsStream(getThisPackage(), getExistingResourceName())); assert ResourceLoader.getPackageResourceAsStream(getThisPackage(), getNonExistingResourceName()) == null; assertReadable(ResourceLoader.getPackageResourceAsStream(getThisPackage(), getExistingResourceName(), getThisClassLoader(), getRootPackageFile())); assert ResourceLoader.getPackageResourceAsStream(getThisPackage(), getNonExistingResourceName(), getThisClassLoader(), getRootPackageFile()) == null; }
/** * Tests <code>ResourceLoader#getPackageResourceAsFile</code> methods. * * @throws IOException should not happen */ @Test public void testPackageResourceAsFile() throws IOException { assertReadable(ResourceLoader.getPackageResourceAsFile(getThisPackage(), getExistingResourceName())); assert ResourceLoader.getPackageResourceAsFile(getThisPackage(), getNonExistingResourceName()) == null; assertReadable(ResourceLoader.getPackageResourceAsFile(getThisPackage(), getExistingResourceName(), getThisClassLoader(), getRootPackageFile())); assert ResourceLoader.getPackageResourceAsFile(getThisPackage(), getNonExistingResourceName(), getThisClassLoader(), getRootPackageFile()) == null; }
/** * Shorthand for {@link #getResourceAsStream(String, ClassLoader, AbstractFile)} called with the * {@link #getDefaultClassLoader() default class loader} and a <code>null</code> root package file. * * @param path forward slash-separated path to the resource to look for, relative to the parent classpath * location (directory or JAR file) that contains it. * @return an InputStream that allows to read the resource, or <code>null</code> if the resource couldn't be located */ public static InputStream getResourceAsStream(String path) { return getResourceAsStream(path, getDefaultClassLoader(), null); }
/** * This method is similar to {@link #getResourceAsURL(String)} except that it looks for a resource with a given * name in a specific package. * * @param ppackage package serving as a base folder for the resource to retrieve * @param name name of the resource in the package. This is a filename only, not a path. * @return a URL pointing to the resource, or <code>null</code> if the resource couldn't be located */ public static URL getPackageResourceAsURL(Package ppackage, String name) { return getPackageResourceAsURL(ppackage, name, getDefaultClassLoader(), null); }
/** * This method is similar to {@link #getResourceAsStream(String)} except that it looks for a resource with a given * name in a specific package. * * @param ppackage package serving as a base folder for the resource to retrieve * @param name name of the resource in the package. This is a filename only, not a path. * @return an InputStream that allows to read the resource, or <code>null</code> if the resource couldn't be located */ public static InputStream getPackageResourceAsStream(Package ppackage, String name) { return getPackageResourceAsStream(ppackage, name, getDefaultClassLoader(), null); }
/** * This method is similar to {@link #getResourceAsFile(String)} except that it looks for a resource with a given * name in a specific package. * * @param ppackage package serving as a base folder for the resource to retrieve * @param name name of the resource in the package. This is a filename only, not a path. * @return an AbstractFile that represents the resource, or <code>null</code> if the resource couldn't be located */ public static AbstractFile getPackageResourceAsFile(Package ppackage, String name) { return getPackageResourceAsFile(ppackage, name, getDefaultClassLoader(), null); }
/** * Returns the JAR file to update. * * @return the JAR file to update */ private static AbstractFile getDestJarFile() { return ResourceLoader.getRootPackageAsFile(SelfUpdateJob.class); }
/** * Returns an input stream on the requested predefined theme. * @param name name of the predefined theme on which to open an input stream. * @return an input stream on the requested predefined theme. * @throws IOException if an I/O related error occurs. */ private static InputStream getPredefinedThemeInputStream(String name) throws IOException { return ResourceLoader.getResourceAsStream(RuntimeConstants.THEMES_PATH + "/" + name + ".xml"); }
/** * Removes any leading slash from the given path and returns it. Does nothing if the path does not have a * leading path. * * @param path the path to normalize * @return the path without a leading slash */ private static String removeLeadingSlash(String path) { return PathUtils.removeLeadingSeparator(path, "/"); }
/** * Returns the depth of the specified entry path, based on the number of path delimiters ('/') it contains. * Top-level entries have a depth of 1. * * @param entryPath the path for which to calculate the depth * @return the depth of the given entry path */ public static int getDepth(String entryPath) { return PathUtils.getDepth(entryPath, "/"); }
/** * Adds all the files in the given array to this FileSet. Does nothing if the specified array is <code>null</code. * * @param files the files to add to this FileSet. */ public void addAll(AbstractFile[] files) { if(files==null) return; for (AbstractFile file : files) add(file); } }
@Override protected boolean isValidDestination(PathUtils.ResolvedDestination resolvedDest, String destPath) { if(resolvedDest==null) return false; int destType = resolvedDest.getDestinationType(); return destType==PathUtils.ResolvedDestination.NEW_FILE || destType==PathUtils.ResolvedDestination.EXISTING_FILE; }
/** * Attemps to change the permissions of the given file and returns <code>true</code> if the <code>chmod</code> * command reported a success. * * @param file the file whose permissions are to be changed * @param permissions the new permissions, in any form accepted by the chmod command * @return true if the <code>chmod</code> command reported a success */ public static boolean chmod(AbstractFile file, String permissions) { return chmod(new AbstractFile[]{file}, permissions); }
/** * Enumeration implementation, returns the same value as {@link #hasMoreFilenames()}. */ public boolean hasMoreElements() { return hasMoreFilenames(); }
/** * Enumeration implementation, returns the same value as {@link #nextFilename()}. */ public String nextElement() throws NoSuchElementException { return nextFilename(); } }
/** * Creates a new empty FileSet with the specified base folder, and adds the given file. * * @param baseFolder the folder containing the files * @param file the file to add */ public FileSet(AbstractFile baseFolder, AbstractFile file) { this.baseFolder = baseFolder; add(file); }