/** * Unmarshals an ACL from an xml input stream. * * @param in * the xml input stream * @return the acl * @throws IOException * if there is a problem unmarshaling the stream * @throws AccessControlParsingException * if the format is invalid */ public static AccessControlList parseAcl(InputStream in) throws IOException, AccessControlParsingException { return parseAcl(IOUtils.toString(in, ENCODING)); }
@Override public AccessControlList apply(String s) { return parseAclSilent(s); } };
@Override public String apply(AccessControlList acl) { return toJsonSilent(acl); } };
/** * Parses a string into an ACL. * * @param serializedForm * the string containing the xml or json formatted access control list. * @return the access control list * @throws IOException * if the encoding is invalid * @throws AccessControlParsingException * if the format is invalid */ public static AccessControlList parseAcl(String serializedForm) throws IOException, AccessControlParsingException { // Determine whether to parse this as XML or JSON if (serializedForm.startsWith("{")) { return parseJson(serializedForm); } else { return parseXml(IOUtils.toInputStream(serializedForm, ENCODING)); } }
public static String toJsonSilent(AccessControlList acl) { try { return toJson(acl); } catch (IOException e) { return chuck(e); } }
/** Same like {@link #parseAcl(String)} but throws runtime exceptions in case of an error. */ public static AccessControlList parseAclSilent(String serializedForm) { try { return parseAcl(serializedForm); } catch (Exception e) { return chuck(e); } }
@Override public Either<Exception, AccessControlList> apply(String s) { try { return right(parseAcl(s)); } catch (Exception e) { return left(e); } } };