Add PathUtiFiles.getFileAttributeView() shorthands.
PathUtils.getAclFileAttributeView(Path, LinkOption...)
PathUtils.getDosFileAttributeView(Path, LinkOption...)
PathUtils.getPosixFileAttributeView(Path, LinkOption...)
MODIFY
src/changes/changes.xml
src/changes/changes.xml
@@ -244,6 +244,12 @@ The <action> type attribute can be add,update,fix,remove.
<action dev="ggregory" type="add" due-to="Gary Gregory">
Add PathUtils.writeString(Path, CharSequence, Charset, OpenOption...).
</action>
+ <action dev="ggregory" type="add" due-to="Gary Gregory">
+ Add PathUtiFiles.getFileAttributeView() shorthands:
+ - PathUtils.getAclFileAttributeView(Path, LinkOption...)
+ - PathUtils.getDosFileAttributeView(Path, LinkOption...)
+ - PathUtils.getPosixFileAttributeView(Path, LinkOption...)
+ </action>
<!-- UPDATE -->
<action dev="ggregory" type="add" due-to="Gary Gregory">
Update FileEntry to use FileTime instead of long for file time stamps.

MODIFY
src/main/java/org/apache/commons/io/file/PathUtils.java
src/main/java/org/apache/commons/io/file/PathUtils.java
@@ -729,14 +729,50 @@ public static boolean fileContentEquals(final Path path1, final Path path2, fina
* @since 2.8.0
*/
public static List<AclEntry> getAclEntryList(final Path sourcePath) throws IOException {
- final AclFileAttributeView fileAttributeView = Files.getFileAttributeView(sourcePath, AclFileAttributeView.class);
+ final AclFileAttributeView fileAttributeView = getAclFileAttributeView(sourcePath);
return fileAttributeView == null ? null : fileAttributeView.getAcl();
}
+ /**
+ * Shorthand for {@code Files.getFileAttributeView(path, AclFileAttributeView.class)}.
+ *
+ * @param path the path to the file.
+ * @param options how to handle symbolic links.
+ * @return a AclFileAttributeView, or {@code null} if the attribute view type is not available.
+ * @since 2.12.0
+ */
+ public static AclFileAttributeView getAclFileAttributeView(final Path path, final LinkOption... options) {
+ return Files.getFileAttributeView(path, AclFileAttributeView.class, options);
+ }
+
+ /**
+ * Shorthand for {@code Files.getFileAttributeView(path, DosFileAttributeView.class)}.
+ *
+ * @param path the path to the file.
+ * @param options how to handle symbolic links.
+ * @return a DosFileAttributeView, or {@code null} if the attribute view type is not available.
+ * @since 2.12.0
+ */
+ public static DosFileAttributeView getDosFileAttributeView(final Path path, final LinkOption... options) {
+ return Files.getFileAttributeView(path, DosFileAttributeView.class, options);
+ }
+
private static FileTime getLastModifiedTime(final Path path, final LinkOption... options) throws IOException {
return Files.getLastModifiedTime(Objects.requireNonNull(path, "path"), options);
}
+ /**
+ * Shorthand for {@code Files.getFileAttributeView(path, PosixFileAttributeView.class)}.
+ *
+ * @param path the path to the file.
+ * @param options how to handle symbolic links.
+ * @return a PosixFileAttributeView, or {@code null} if the attribute view type is not available.
+ * @since 2.12.0
+ */
+ public static PosixFileAttributeView getPosixFileAttributeView(final Path path, final LinkOption... options) {
+ return Files.getFileAttributeView(path, PosixFileAttributeView.class, options);
+ }
+
/**
* Gets a {@link Path} representing the system temporary directory.
*
@@ -915,6 +951,7 @@ public static boolean isOlder(final Path file, final Instant instant, final Link
return isOlder(file, FileTime.from(instant), options);
}
+
/**
* Tests if the given {@code Path} is older than the given time reference.
*
@@ -943,7 +980,6 @@ public static boolean isOlder(final Path file, final Path reference) throws IOEx
return isOlder(file, getLastModifiedTime(reference));
}
-
/**
* Tests whether the given {@code Path} is a regular file or not. Implemented as a null-safe delegate to
* {@code Files.isRegularFile(Path path, LinkOption... options)}.
@@ -1152,7 +1188,7 @@ public static void setLastModifiedTime(final Path sourceFile, final Path targetF
*/
public static Path setReadOnly(final Path path, final boolean readOnly, final LinkOption... linkOptions) throws IOException {
final List<Exception> causeList = new ArrayList<>(2);
- final DosFileAttributeView fileAttributeView = Files.getFileAttributeView(path, DosFileAttributeView.class, linkOptions);
+ final DosFileAttributeView fileAttributeView = getDosFileAttributeView(path, linkOptions);
if (fileAttributeView != null) {
// Windows 10
try {
@@ -1163,7 +1199,7 @@ public static Path setReadOnly(final Path path, final boolean readOnly, final Li
causeList.add(e);
}
}
- final PosixFileAttributeView posixFileAttributeView = Files.getFileAttributeView(path, PosixFileAttributeView.class, linkOptions);
+ final PosixFileAttributeView posixFileAttributeView = getPosixFileAttributeView(path, linkOptions);
if (posixFileAttributeView != null) {
// Not Windows 10
final PosixFileAttributes readAttributes = posixFileAttributeView.readAttributes();

MODIFY
src/test/java/org/apache/commons/io/file/PathUtilsTest.java
src/test/java/org/apache/commons/io/file/PathUtilsTest.java
@@ -283,11 +283,11 @@ public void testSetReadOnlyFile() throws IOException {
PathUtils.setReadOnly(resolved, true);
assertEquals(true, Files.isReadable(resolved));
assertEquals(false, Files.isWritable(resolved));
- final DosFileAttributeView dosFileAttributeView = Files.getFileAttributeView(resolved, DosFileAttributeView.class);
+ final DosFileAttributeView dosFileAttributeView = PathUtils.getDosFileAttributeView(resolved);
if (dosFileAttributeView != null) {
assertTrue(dosFileAttributeView.readAttributes().isReadOnly());
}
- final PosixFileAttributeView posixFileAttributeView = Files.getFileAttributeView(resolved, PosixFileAttributeView.class);
+ final PosixFileAttributeView posixFileAttributeView = PathUtils.getPosixFileAttributeView(resolved);
if (posixFileAttributeView != null) {
// Not Windows
final Set<PosixFilePermission> permissions = posixFileAttributeView.readAttributes().permissions();

Add PathUtiFiles.getFileAttributeView() shorthands.

- PathUtils.getAclFileAttributeView(Path, LinkOption...)
- PathUtils.getDosFileAttributeView(Path, LinkOption...)
- PathUtils.getPosixFileAttributeView(Path, LinkOption...)