Skip to content

Commit

Permalink
Make FileUtils#moveToTrash a varargs method
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasblaesing committed Feb 13, 2020
1 parent 653c185 commit 7edf6ea
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
7 changes: 4 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ NOTE: as of JNA 4.0, JNA is now dual-licensed under LGPL and AL 2.0 (see LICENSE

NOTE: JNI native support is typically incompatible between minor versions, and almost always incompatible between major versions.

Next Release (5.5.1)
Next Release (5.6.0)
====================

Features
--------
* [#1160](https://github.com/java-native-access/jna/issues/1160): Make FileUtils#moveToTrash a varargs method - [@matthiasblaesing](https://github.com/matthiasblaesing).

Features
--------
Bug Fixes
---------


Release 5.5.0
Expand Down
6 changes: 4 additions & 2 deletions contrib/platform/src/com/sun/jna/platform/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public boolean hasTrash() {
* @param files files to move
* @throws IOException on failure.
*/
public abstract void moveToTrash(File[] files) throws IOException;
public abstract void moveToTrash(File... files) throws IOException;

/** Canonical lazy loading of a singleton. */
private static class Holder {
Expand Down Expand Up @@ -90,14 +90,16 @@ private File getTrashDirectory() {
return trash;
}

@Override
public boolean hasTrash() {
return getTrashDirectory().exists();
}

/** The default implementation attempts to move the file to
* the desktop "Trash" folder.
*/
public void moveToTrash(File[] files) throws IOException {
@Override
public void moveToTrash(File... files) throws IOException {
File trash = getTrashDirectory();
if (!trash.exists()) {
throw new IOException("No trash location found (define fileutils.trash to be the path to the trash)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class FSRef extends Structure {
}

@Override
public void moveToTrash(File[] files) throws IOException {
public void moveToTrash(File... files) throws IOException {
List<String> failed = new ArrayList<String>();
for (File src: files) {
FileManager.FSRef fsref = new FileManager.FSRef();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@

public class W32FileUtils extends FileUtils {

@Override
public boolean hasTrash() {
return true;
}

public void moveToTrash(File[] files) throws IOException {
@Override
public void moveToTrash(File... files) throws IOException {
Shell32 shell = Shell32.INSTANCE;
ShellAPI.SHFILEOPSTRUCT fileop = new ShellAPI.SHFILEOPSTRUCT();
fileop.wFunc = ShellAPI.FO_DELETE;
Expand Down

0 comments on commit 7edf6ea

Please sign in to comment.