com.sun.jna.platform.FileUtils Java Examples

The following examples show how to use com.sun.jna.platform.FileUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Utils.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: NativeLocalTrashFeature.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
@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);
    }
}
 
Example #3
Source File: Utils.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 deleteMaybeToTrash(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()));

	// FileUtils is com.sun, soooo big ass try around it
	try {
		// move to system trash, if possible
		FileUtils fileUtils = FileUtils.getInstance();
		if (fileUtils.hasTrash()) {
			fileUtils.moveToTrash(new File[] { file });
			return true;
		}
	} catch (Throwable t) {
		softErr(t, "Failed to move file '%s' to trash.", file.getAbsolutePath());
	}

	// delete otherwise
	if (file.isDirectory())
		deleteDirectory(file);
	else
		file.delete();
	return false;
}
 
Example #4
Source File: PathManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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
          THashSet.class,               // trove4j
          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);
}