3909N/A * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. 893N/A * Redistribution and use in source and binary forms, with or without 893N/A * modification, are permitted provided that the following conditions 893N/A * - Redistributions of source code must retain the above copyright 893N/A * notice, this list of conditions and the following disclaimer. 893N/A * - Redistributions in binary form must reproduce the above copyright 893N/A * notice, this list of conditions and the following disclaimer in the 893N/A * documentation and/or other materials provided with the distribution. 2362N/A * - Neither the name of Oracle nor the names of its 893N/A * contributors may be used to endorse or promote products derived 893N/A * from this software without specific prior written permission. 893N/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 893N/A * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 893N/A * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 893N/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 893N/A * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 893N/A * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 893N/A * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 893N/A * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 893N/A * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 893N/A * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 893N/A * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 4378N/A * This source code is provided to illustrate the usage of a given feature 4378N/A * or technique and has been deliberately simplified. Additional steps 4378N/A * required for a production-quality application, such as security checks, 4378N/A * input validation and proper error handling, might not be present in 893N/A * Sample code that changes the permissions of files in a similar manner to the 893N/A * Compiles a list of one or more <em>symbolic mode expressions</em> that 893N/A * may be used to change a set of file permissions. This method is 893N/A * intended for use where file permissions are required to be changed in 893N/A * a manner similar to the UNIX <i>chmod</i> program. 893N/A * <p> The {@code exprs} parameter is a comma separated list of expressions 893N/A * where each takes the form: 893N/A * <i>who operator</i> [<i>permissions</i>] 893N/A * where <i>who</i> is one or more of the characters {@code 'u'}, {@code 'g'}, 893N/A * {@code 'o'}, or {@code 'a'} meaning the owner (user), group, others, or 893N/A * all (owner, group, and others) respectively. 893N/A * <p> <i>operator</i> is the character {@code '+'}, {@code '-'}, or {@code 893N/A * '='} signifying how permissions are to be changed. {@code '+'} means the 893N/A * permissions are added, {@code '-'} means the permissions are removed, and 893N/A * {@code '='} means the permissions are assigned absolutely. 893N/A * <p> <i>permissions</i> is a sequence of zero or more of the following: 893N/A * {@code 'r'} for read permission, {@code 'w'} for write permission, and 893N/A * {@code 'x'} for execute permission. If <i>permissions</i> is omitted 893N/A * when assigned absolutely, then the permissions are cleared for 893N/A * the owner, group, or others as identified by <i>who</i>. When omitted 893N/A * when adding or removing then the expression is ignored. 893N/A * <p> The following examples demonstrate possible values for the {@code 893N/A * <td> {@code u=rw} </td> 893N/A * <td> Sets the owner permissions to be read and write. </td> 893N/A * <td> {@code ug+w} </td> 893N/A * <td> Sets the owner write and group write permissions. </td> 893N/A * <td> {@code u+w,o-rwx} </td> 893N/A * <td> Sets the owner write, and removes the others read, others write 893N/A * and others execute permissions. </td> 893N/A * <td> {@code o=} </td> 893N/A * <td> Sets the others permission to none (others read, others write and 893N/A * others execute permissions are removed if set) </td> 893N/A * List of one or more <em>symbolic mode expressions</em> 893N/A * @return A {@code Changer} that may be used to changer a set of 893N/A * @throws IllegalArgumentException 893N/A * If the value of the {@code exprs} parameter is invalid 893N/A // minimum is who and operator (u= for example) 893N/A // permissions that the changer will add or remove 893N/A // iterate over each of expression modes 893N/A // minimum of who and operator 893N/A case 'u' : u =
true;
break;
893N/A case 'g' : g =
true;
break;
893N/A case 'o' : o =
true;
break;
893N/A case 'a' : u =
true; g =
true; o =
true;
break;
893N/A // get operator and permissions 893N/A // who= means remove all 893N/A case 'r' : r =
true;
break;
893N/A case 'w' : w =
true;
break;
893N/A case 'x' : x =
true;
break;
893N/A // update permissions set 893N/A * A task that <i>changes</i> a set of {@link PosixFilePermission} elements. 893N/A * Applies the changes to the given set of permissions. 893N/A * The set of permissions to change 893N/A * @return The {@code perms} parameter 893N/A * Changes the permissions of the file using the given Changer. 893N/A * Changes the permission of each file and directory visited 893N/A // compile the symbolic mode expressions