Search in sources :

Example 1 with NameSpace

use of org.apache.hadoop.fs.XAttr.NameSpace in project hadoop by apache.

the class XAttrHelper method buildXAttr.

/**
   * Build <code>XAttr</code> from name with prefix and value.
   * Name can not be null. Value can be null. The name and prefix
   * are validated.
   * Both name and namespace are case sensitive.
   */
public static XAttr buildXAttr(String name, byte[] value) {
    Preconditions.checkNotNull(name, "XAttr name cannot be null.");
    final int prefixIndex = name.indexOf(".");
    if (prefixIndex < 3) {
        // Prefix length is at least 3.
        throw new HadoopIllegalArgumentException("An XAttr name must be " + "prefixed with user/trusted/security/system/raw, followed by a '.'");
    } else if (prefixIndex == name.length() - 1) {
        throw new HadoopIllegalArgumentException("XAttr name cannot be empty.");
    }
    NameSpace ns;
    final String prefix = name.substring(0, prefixIndex);
    if (StringUtils.equalsIgnoreCase(prefix, NameSpace.USER.toString())) {
        ns = NameSpace.USER;
    } else if (StringUtils.equalsIgnoreCase(prefix, NameSpace.TRUSTED.toString())) {
        ns = NameSpace.TRUSTED;
    } else if (StringUtils.equalsIgnoreCase(prefix, NameSpace.SYSTEM.toString())) {
        ns = NameSpace.SYSTEM;
    } else if (StringUtils.equalsIgnoreCase(prefix, NameSpace.SECURITY.toString())) {
        ns = NameSpace.SECURITY;
    } else if (StringUtils.equalsIgnoreCase(prefix, NameSpace.RAW.toString())) {
        ns = NameSpace.RAW;
    } else {
        throw new HadoopIllegalArgumentException("An XAttr name must be " + "prefixed with user/trusted/security/system/raw, followed by a '.'");
    }
    return (new XAttr.Builder()).setNameSpace(ns).setName(name.substring(prefixIndex + 1)).setValue(value).build();
}
Also used : HadoopIllegalArgumentException(org.apache.hadoop.HadoopIllegalArgumentException) NameSpace(org.apache.hadoop.fs.XAttr.NameSpace) XAttr(org.apache.hadoop.fs.XAttr)

Aggregations

HadoopIllegalArgumentException (org.apache.hadoop.HadoopIllegalArgumentException)1 XAttr (org.apache.hadoop.fs.XAttr)1 NameSpace (org.apache.hadoop.fs.XAttr.NameSpace)1