List of usage examples for org.apache.commons.vfs2 FileObject exists
boolean exists() throws FileSystemException;
From source file:org.freedesktop.AbstractFreedesktopService.java
protected void checkAndAddBase(FileObject file) throws IOException, ParseException { if (file.exists()) { addBase(file);// ww w.j a va 2 s .c o m } }
From source file:org.freedesktop.cursors.DefaultCursorService.java
protected Collection<CursorTheme> scanBase(FileObject base) throws IOException { List<CursorTheme> themes = new ArrayList<CursorTheme>(); for (FileObject dir : listDirs(base)) { FileObject cursorTheme = dir.resolveFile("cursor.theme"); FileObject cursorsDir = dir.resolveFile("cursors"); if (cursorTheme.exists() || cursorsDir.exists()) { try { themes.add(new CursorTheme(dir)); } catch (FileNotFoundException fnfe) { // Skip Log.debug("Skipping " + dir + " because index.theme is missing."); } catch (IOException ioe) { Log.warn("Invalid theme directory " + dir.getName().getPath() + "." + ioe.getMessage()); } catch (ParseException ioe) { Log.warn("Invalid theme definition in " + dir.getName().getPath() + ". " + ioe.getMessage()); }//w w w . j av a2 s . c om } else { // Skip Log.debug("Skipping " + dir + " because it is an icon theme."); } } return themes; }
From source file:org.freedesktop.icons.DefaultIconService.java
public boolean isIconExists(String name, int size) throws IOException { String key = name + "_" + size; FileObject file = cache.get(key); ;// w ww. j av a 2 s .c o m if (file != null && file.exists()) { return true; } IconTheme theme = getSelectedTheme(); if (theme != null) { file = findIconHelper(name, size, theme); if (file != null) { cache.put(key, file); return true; } } try { file = lookupFallbackIcon(name); if (file != null) { cache.put(key, file); return true; } } catch (IOException ioe) { } return false; }
From source file:org.freedesktop.icons.DefaultIconService.java
protected Collection<IconTheme> scanBase(FileObject base) throws IOException { List<IconTheme> themes = new ArrayList<IconTheme>(); FileObject[] listDirs = listDirs(base); for (FileObject dir : listDirs) { // TODO cursor themes not supported here FileObject cursorTheme = dir.resolveFile("cursor.theme"); FileObject cursorsDir = dir.resolveFile("cursors"); if (cursorTheme.exists() || cursorsDir.exists()) { // Skip Log.debug("Skipping " + dir + " because it is a cursor theme."); continue; }//ww w . jav a2 s. co m try { themes.add(new IconTheme(dir)); } catch (FileNotFoundException fnfe) { // Skip Log.debug("Skipping " + dir + " because index.theme is missing."); } catch (IOException ioe) { Log.warn("Invalid theme directory " + dir.getName().getPath() + "." + ioe.getMessage()); } } return themes; }
From source file:org.freedesktop.icons.DefaultIconService.java
FileObject lookupFallbackIcon(String iconname) throws IOException { for (FileObject base : bases.keySet()) { for (String extension : SUPPORTED_EXTENSIONS) { FileObject f = base.resolveFile(iconname + "." + extension); if (f.exists()) { return f; }//from w ww. j a v a2s. com } } throw new IOException("No theme or fallback icon for " + iconname + "."); }
From source file:org.freedesktop.icons.IconTheme.java
public IconTheme(FileObject... base) throws IOException { super(ICON_THEME, base); for (FileObject b : base) { FileObject f = b.resolveFile("index.theme"); if (f.exists()) { themeFile = f;// w ww.j av a 2s . c o m break; } } if (themeFile == null) { throw new FileNotFoundException(); } }
From source file:org.freedesktop.icons.IconTheme.java
public FileObject lookupIcon(String icon, int size) throws IOException { checkLoaded();// w w w .j a v a 2s .c om for (Directory directory : getDirectories()) { if (directory.isMatchesSize(size)) { FileObject file = directory.findIcon(icon); if (file != null) { return file; } } } int minimalSize = Integer.MAX_VALUE; FileObject closestFile = null; FileObject firstFile = null; for (Directory directory : getDirectories()) { for (String ext : DefaultIconService.SUPPORTED_EXTENSIONS) { for (FileObject base : getBases()) { FileObject file = base.resolveFile(directory.getKey() + File.separator + icon + "." + ext); int directorySizeDistance = directorySizeDistance(directory, size); if (file.exists()) { if (directorySizeDistance < minimalSize) { closestFile = file; minimalSize = directorySizeDistance; } else { if (firstFile == null) { firstFile = file; } } } } } } return closestFile == null ? firstFile : closestFile; }
From source file:org.freedesktop.wallpapers.Wallpaper.java
public Wallpaper(FileObject... base) throws IOException, ParseException { super(WALLPAPER, base); for (FileObject b : base) { FileObject f = b.getParent().resolveFile(b.getName() + ".desktop"); if (f.exists()) { themeFile = f;//from ww w .j a v a 2 s .c om break; } } if (themeFile == null) { throw new FileNotFoundException(); } }
From source file:org.fuin.vfs2.filter.AgeFileFilter.java
/** * Tests if the specified <code>File</code> is newer than the specified time * reference.//from w w w . jav a 2 s. c o m * * @param fileObject * the <code>File</code> of which the modification date must be * compared, must not be {@code null} * @param timeMillis * the time reference measured in milliseconds since the epoch * (00:00:00 GMT, January 1, 1970) * @return true if the <code>File</code> exists and has been modified after * the given time reference. * @throws IllegalArgumentException * if the file is {@code null} */ private static boolean isFileNewer(final FileObject fileObject, final long timeMillis) { if (fileObject == null) { throw new IllegalArgumentException("No specified file"); } try { if (!fileObject.exists()) { return false; } final FileContent content = fileObject.getContent(); try { final long lastModified = content.getLastModifiedTime(); return lastModified > timeMillis; } finally { content.close(); } } catch (final FileSystemException ex) { throw new RuntimeException(ex); } }
From source file:org.fuin.vfs2.filter.EmptyFileFilter.java
/** * Checks to see if the file is empty. A non-existing file is also * considered empty.//from www. j av a 2s. c om * * @param fileInfo * the file or directory to check * * @return {@code true} if the file or directory is <i>empty</i>, otherwise * {@code false}. */ @Override public boolean accept(final FileSelectInfo fileInfo) { final FileObject file = fileInfo.getFile(); try { if (!file.exists()) { return true; } if (file.getType() == FileType.FOLDER) { final FileObject[] files = file.getChildren(); return files == null || files.length == 0; } final FileContent content = file.getContent(); try { return content.getSize() == 0; } finally { content.close(); } } catch (final FileSystemException ex) { throw new RuntimeException(ex); } }