/** * Deletes a file or directory. If a system trash directory is available, * the file or directory will be moved there instead. * @param file the file or directory to delete * @return true if moved to trash, and false if deleted * @throws IOException if given file does not exist */ public static boolean deleteToTrash(File file) throws IOException { if (file == null) throw new IOException("File cannot be null."); if (!file.exists()) throw new IOException(String.format("File '%s' does not exist.", file.getAbsolutePath())); // move to system trash, if possible FileUtils fileUtils = FileUtils.getInstance(); if (fileUtils.hasTrash()) { try { fileUtils.moveToTrash(new File[] { file }); return true; } catch (IOException e) { Log.warn(String.format("Failed to move file '%s' to trash.", file.getAbsolutePath()), e); } } // delete otherwise if (file.isDirectory()) deleteDirectory(file); else file.delete(); return false; }
public static boolean moveToTrash(File fileToDelete) { FileUtils fileUtils = FileUtils.getInstance(); if (fileUtils.hasTrash()) { try { fileUtils.moveToTrash( new File[] { fileToDelete } ); return true; } catch (IOException ioe) { } } return false; }
@Override public void trash(final Local file) throws LocalAccessDeniedException { try { FileUtils.getInstance().moveToTrash(new File[]{new File(file.getAbsolute())}); } catch(IOException e) { log.warn(String.format("Failed to move %s to Trash", file.getName())); new DefaultLocalTrashFeature().trash(file); } }
/** * Move to trash if trash exist in OS, else remove from file system * * @param fileToRemove: file to be removed * @return true if file is removed successfully * @throws IOException */ public static boolean removeFile(File fileToRemove) throws IOException { FileUtils fileUtils = FileUtils.getInstance(); if (fileUtils.hasTrash()) { fileUtils.moveToTrash( new File[]{fileToRemove} ); return true; } else { return deleteFolderOrFile(fileToRemove); } }
/** * Move to trash * * @param file * @return */ public static boolean moveToTrash(File file) { File[] files = new File[1]; files[0] = file; try { FileUtils.getInstance().moveToTrash(files); return true; } catch (Exception e) { return false; } finally { files[0] = null; } }
/** * Move to trash * * @param files * @return */ public static boolean moveToTrash(List<File> files) { try { FileUtils.getInstance().moveToTrash((File[]) files.toArray()); return true; } catch (Exception e) { return false; } }
private void moveToTrash(File[] files) throws IOException { FileUtils fileUtils = FileUtils.getInstance(); if(fileUtils.hasTrash()) { fileUtils.moveToTrash(files); } else { // delete for(File file:files) { org.apache.commons.io.FileUtils.forceDelete(file); } } }
@NotNull public static Collection<String> getUtilClassPath() { final List<Class<?>> classes = Arrays.asList( PathManager.class, // module 'util' NotNull.class, // module 'annotations' SystemInfoRt.class, // module 'util-rt' Document.class, // jDOM Appender.class, // log4j THashSet.class, // trove4j PicoContainer.class, // PicoContainer TypeMapper.class, // JNA FileUtils.class, // JNA (jna-utils) PatternMatcher.class // OROMatcher ); final Set<String> classPath = new HashSet<String>(); for (Class<?> aClass : classes) { final String path = getJarPathForClass(aClass); if (path != null) { classPath.add(path); } } final String resourceRoot = getResourceRoot(PathManager.class, "/messages/CommonBundle.properties"); // platform-resources-en if (resourceRoot != null) { classPath.add(new File(resourceRoot).getAbsolutePath()); } return Collections.unmodifiableCollection(classPath); }
@Nonnull public static Collection<String> getUtilClassPath() { final Class<?>[] classes = {PathManager.class, // module 'util' Nonnull.class, // module 'annotations' SystemInfoRt.class, // module 'util-rt' Document.class, // jDOM Appender.class, // log4j THashSet.class, // trove4j PicoContainer.class, // PicoContainer TypeMapper.class, // JNA FileUtils.class, // JNA (jna-platform) PatternMatcher.class // OROMatcher }; final Set<String> classPath = new HashSet<String>(); for (Class<?> aClass : classes) { final String path = getJarPathForClass(aClass); if (path != null) { classPath.add(path); } } final String resourceRoot = getResourceRoot(PathManager.class, "/messages/CommonBundle.properties"); // platform-resources-en if (resourceRoot != null) { classPath.add(new File(resourceRoot).getAbsolutePath()); } return Collections.unmodifiableCollection(classPath); }
@NotNull public static Collection<String> getUtilClassPath() { final Class<?>[] classes = { PathManager.class, // module 'util' Flow.class, // module 'annotations' SystemInfoRt.class, // module 'util-rt' Document.class, // jDOM Appender.class, // log4j THashSet.class, // trove4j PicoContainer.class, // PicoContainer TypeMapper.class, // JNA FileUtils.class, // JNA (jna-platform) PatternMatcher.class, // OROMatcher Snappy.class // Snappy }; final Set<String> classPath = new HashSet<String>(); for (Class<?> aClass : classes) { final String path = getJarPathForClass(aClass); if (path != null) { classPath.add(path); } } final String annotationsRoot = getJarPathForClass(Flow.class); if (annotationsRoot != null && !annotationsRoot.endsWith(".jar")) { // We're running IDEA built from sources. Flow.class is under annotations-common, and NotNull.class is under annotations. Add both // roots to classpath. final File notNullRoot = new File(new File(annotationsRoot).getParentFile(), "annotations"); if (notNullRoot.exists()) { classPath.add(notNullRoot.getAbsolutePath()); } } final String resourceRoot = getResourceRoot(PathManager.class, "/messages/CommonBundle.properties"); // platform-resources-en if (resourceRoot != null) { classPath.add(new File(resourceRoot).getAbsolutePath()); } return Collections.unmodifiableCollection(classPath); }