Java 类org.apache.hadoop.hdfs.web.resources.XAttrEncodingParam 实例源码

项目:hadoop    文件:FSImageLoader.java   
/**
 * Return the JSON formatted XAttrs of the specified file.
 *
 * @param path
 *          a path specifies a file
 * @return JSON formatted XAttrs
 * @throws IOException
 *           if failed to serialize fileStatus to JSON.
 */
String getXAttrs(String path, List<String> names, String encoder)
        throws IOException {

  List<XAttr> xAttrs = getXAttrList(path);
  List<XAttr> filtered;
  if (names == null || names.size() == 0) {
    filtered = xAttrs;
  } else {
    filtered = Lists.newArrayListWithCapacity(names.size());
    for (String name : names) {
      XAttr search = XAttrHelper.buildXAttr(name);

      boolean found = false;
      for (XAttr aXAttr : xAttrs) {
        if (aXAttr.getNameSpace() == search.getNameSpace()
                && aXAttr.getName().equals(search.getName())) {

          filtered.add(aXAttr);
          found = true;
          break;
        }
      }

      if (!found) {
        throw new IOException(
                "At least one of the attributes provided was not found.");
      }
    }

  }
  return JsonUtil.toJsonString(filtered,
          new XAttrEncodingParam(encoder).getEncoding());
}
项目:aliyun-oss-hadoop-fs    文件:FSImageLoader.java   
/**
 * Return the JSON formatted XAttrs of the specified file.
 *
 * @param path
 *          a path specifies a file
 * @return JSON formatted XAttrs
 * @throws IOException
 *           if failed to serialize fileStatus to JSON.
 */
String getXAttrs(String path, List<String> names, String encoder)
    throws IOException {

  List<XAttr> xAttrs = getXAttrList(path);
  List<XAttr> filtered;
  if (names == null || names.size() == 0) {
    filtered = xAttrs;
  } else {
    filtered = Lists.newArrayListWithCapacity(names.size());
    for (String name : names) {
      XAttr search = XAttrHelper.buildXAttr(name);

      boolean found = false;
      for (XAttr aXAttr : xAttrs) {
        if (aXAttr.getNameSpace() == search.getNameSpace()
            && aXAttr.getName().equals(search.getName())) {

          filtered.add(aXAttr);
          found = true;
          break;
        }
      }

      if (!found) {
        throw new IOException(
            "At least one of the attributes provided was not found.");
      }
    }

  }
  return JsonUtil.toJsonString(filtered,
      new XAttrEncodingParam(encoder).getEncoding());
}