Exemple #1
0
 public static String toJsonString(final List<XAttr> xAttrs) throws IOException {
   final List<String> names = Lists.newArrayListWithCapacity(xAttrs.size());
   for (XAttr xAttr : xAttrs) {
     names.add(XAttrHelper.getPrefixName(xAttr));
   }
   String ret = JSON.toString(names);
   final Map<String, Object> finalMap = new TreeMap<String, Object>();
   finalMap.put("XAttrNames", ret);
   return JSON.toString(finalMap);
 }
Exemple #2
0
 /** Convert an Object[] to a List of LocatedBlock. */
 private static List<LocatedBlock> toLocatedBlockList(final Object[] objects) throws IOException {
   if (objects == null) {
     return null;
   } else if (objects.length == 0) {
     return Collections.emptyList();
   } else {
     final List<LocatedBlock> list = new ArrayList<LocatedBlock>(objects.length);
     for (int i = 0; i < objects.length; i++) {
       list.add(toLocatedBlock((Map<?, ?>) objects[i]));
     }
     return list;
   }
 }
Exemple #3
0
  public static List<String> toXAttrNames(final Map<?, ?> json) throws IOException {
    if (json == null) {
      return null;
    }

    final String namesInJson = (String) json.get("XAttrNames");
    final Object[] xattrs = (Object[]) JSON.parse(namesInJson);
    final List<String> names = Lists.newArrayListWithCapacity(json.keySet().size());

    for (int i = 0; i < xattrs.length; i++) {
      names.add((String) (xattrs[i]));
    }
    return names;
  }
Exemple #4
0
  /** Convert a Json map to a AclStatus object. */
  public static AclStatus toAclStatus(final Map<?, ?> json) {
    if (json == null) {
      return null;
    }

    final Map<?, ?> m = (Map<?, ?>) json.get(AclStatus.class.getSimpleName());

    AclStatus.Builder aclStatusBuilder = new AclStatus.Builder();
    aclStatusBuilder.owner((String) m.get("owner"));
    aclStatusBuilder.group((String) m.get("group"));
    aclStatusBuilder.stickyBit((Boolean) m.get("stickyBit"));

    final Object[] entries = (Object[]) m.get("entries");

    List<AclEntry> aclEntryList = new ArrayList<AclEntry>();
    for (int i = 0; i < entries.length; i++) {
      AclEntry aclEntry = AclEntry.parseAclEntry((String) entries[i], true);
      aclEntryList.add(aclEntry);
    }
    aclStatusBuilder.addEntries(aclEntryList);
    return aclStatusBuilder.build();
  }