commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r784342 - /commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileProtection.java
Date Sat, 13 Jun 2009 06:46:36 GMT
Author: mturk
Date: Sat Jun 13 06:46:35 2009
New Revision: 784342

URL: http://svn.apache.org/viewvc?rev=784342&view=rev
Log:
Add helper method for constructing the EnumSet from Unix octal mode numbers

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileProtection.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileProtection.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileProtection.java?rev=784342&r1=784341&r2=784342&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileProtection.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileProtection.java
Sat Jun 13 06:46:35 2009
@@ -96,4 +96,25 @@
         }
         return set;
     }
+
+    /**
+     * Returns {@code EnumSet} of {@code FileProtection} enums
+     * from the Unix octal mode number.
+     * @param mode Octal number used to construct the {@code EnumSet}
+     * with {@code FileProtection} values mathching the value flags.
+     * @return set of {@code FileProtection} enums.
+     */
+    public static EnumSet<FileProtection> modeOf(int mode)
+    {
+        EnumSet<FileProtection> set = EnumSet.noneOf(FileProtection.class);
+		int value = (mode & 0x07) +
+ 					(((mode >> 3) & 0x07) << 4) +
+ 					(((mode >> 6) & 0x07) << 8) +
+ 					(((mode >> 9) & 0x07) << 12);
+        for (FileProtection e : values()) {
+            if ((e.value & value) == e.value)
+                set.add(e);
+        }
+        return set;
+    }
 }



Mime
View raw message