private static List < String > parseACLArray ( String aclString ) { List < String > acls = new ArrayList < String > ( ) ; if ( aclString == null || aclString . isEmpty ( ) ) { return acls ; } boolean inQuotes = false ; // start at 1 because of leading "{" int beginIndex = 1 ; char prevChar = ' ' ; for ( int i = beginIndex ; i < aclString . length ( ) ; i ++ ) { char c = aclString . charAt ( i ) ; if ( c == ' ' && prevChar != ' ' ) { inQuotes = ! inQuotes ; } else if ( c == ' ' && ! inQuotes ) { acls . add ( aclString . substring ( beginIndex , i ) ) ; beginIndex = i + 1 ; } prevChar = c ; } // add last element removing the trailing "}" acls . add ( aclString . substring ( beginIndex , aclString . length ( ) - 1 ) ) ; // Strip out enclosing quotes, if any. for ( int i = 0 ; i < acls . size ( ) ; i ++ ) { String acl = acls . get ( i ) ; if ( acl . startsWith ( "\"" ) && acl . endsWith ( "\"" ) ) { acl = acl . substring ( 1 , acl . length ( ) - 1 ) ; acls . set ( i , acl ) ; } } return acls ; }
Parse an String of ACLs into a List of ACLs .