/** * Parse {@link PreserveAttributes} from a string of the form \[rbugp]*\: * * r -> preserve replication * * b -> preserve block size * * u -> preserve owner * * g -> preserve group * * p -> preserve permissions * Characters not in this character set will be ignored. * * @param s String of the form \[rbugp]*\ * @return Parsed {@link PreserveAttributes} */ public static PreserveAttributes fromMnemonicString(String s) { if (Strings.isNullOrEmpty(s)) { return new PreserveAttributes(0); } s = s.toLowerCase(); Preconditions.checkArgument(ATTRIBUTES_REGEXP.matcher(s).matches(), "Invalid %s string %s, must be of the form %s.", PreserveAttributes.class.getSimpleName(), s, ATTRIBUTES_REGEXP.pattern()); int value = 0; for (Option option : Option.values()) { if (s.indexOf(option.token) >= 0) { value |= 1 << option.ordinal(); } } return new PreserveAttributes(value); }
/** * Parse {@link PreserveAttributes} from a string of the form \[rbugp]*\: * * r -> preserve replication * * b -> preserve block size * * u -> preserve owner * * g -> preserve group * * p -> preserve permissions * Characters not in this character set will be ignored. * * @param s String of the form \[rbugp]*\ * @return Parsed {@link PreserveAttributes} */ public static PreserveAttributes fromMnemonicString(String s) { if (Strings.isNullOrEmpty(s)) { return new PreserveAttributes(0); } s = s.toLowerCase(); Preconditions.checkArgument(ATTRIBUTES_REGEXP.matcher(s).matches(), "Invalid %s string %s, must be of the form %s.", PreserveAttributes.class.getSimpleName(), s, ATTRIBUTES_REGEXP.pattern()); int value = 0; for (Option option : Option.values()) { if (s.indexOf(option.token) >= 0) { value |= 1 << option.ordinal(); } } return new PreserveAttributes(value); }
/** * @return true if attribute should be preserved. */ public boolean preserve(Option option) { return 0 < (this.options & (1 << option.ordinal())); }
/** * @return true if attribute should be preserved. */ public boolean preserve(Option option) { return 0 < (this.options & (1 << option.ordinal())); }