public static List<PermissionType> reverseValues() { List<PermissionType> values = Arrays.asList(PermissionType.values()); Collections.reverse(values); return values; } }
public int getIntValue() { int bitShift = 0; int perms = 0; for(PermissionAccess a : PermissionAccess.values()) { for(PermissionType p : PermissionType.values()) { if(getBitValue(a, p)) perms |= (1<<bitShift); bitShift++; } } return perms; } }
/** * Changes this file's permissions to the specified permissions int. * The permissions int should be constructed using the permission types and accesses defined in * {@link com.mucommander.commons.file.PermissionType} and {@link com.mucommander.commons.file.PermissionAccess}. * * <p>Implementation note: the default implementation of this method calls sequentially {@link #changePermission(int, int, boolean)}, * for each permission and access (that's a total 9 calls). This may affect performance on filesystems which need * to perform an I/O request to change each permission individually. In that case, and if the fileystem allows * to change all permissions at once, this method should be overridden.</p> * * @param permissions new permissions for this file * @throws IOException if the permissions couldn't be changed, either because of insufficient permissions or because * of an I/O error. * @throws UnsupportedFileOperationException if this method relies on a file operation that is not supported * or not implemented by the underlying filesystem. */ public void changePermissions(int permissions) throws IOException, UnsupportedFileOperationException { int bitShift = 0; PermissionBits mask = getChangeablePermissions(); for(PermissionAccess a : PermissionAccess.values()) { for(PermissionType p : PermissionType.values()) { if(mask.getBitValue(a, p)) changePermission(a, p, (permissions & (1<<bitShift))!=0); bitShift++; } } }
/** * Tests {@link AbstractFile#getPermissions()}. * * @throws IOException should not happen * @throws NoSuchAlgorithmException should not happen */ @Test public void testGetPermissions() throws IOException, NoSuchAlgorithmException { assert tempFile.getPermissions() != null; createFile(tempFile, 0); FilePermissions permissions = tempFile.getPermissions(); PermissionBits getPermMask = permissions.getMask(); assert permissions != null; int getPermMaskInt = getPermMask.getIntValue(); int bitShift = 0; int bitMask; boolean canGetPermission; for(PermissionAccess a : PermissionAccess.values()) { for(PermissionType p : PermissionType.values()) { bitMask = 1<<bitShift; canGetPermission = (getPermMaskInt & bitMask)!=0; assert getPermMask.getBitValue(a, p)==canGetPermission: "inconsistent bit and int value for ("+a+", "+p+")"; if(canGetPermission) { assert permissions.getBitValue(a, p)==((permissions.getIntValue() & bitMask)!=0): "inconsistent bit and int value for ("+a+", "+p+")"; } bitShift++; } } }
for(PermissionType p : PermissionType.values()) { bitMask = 1<<bitShift;