Exemplo n.º 1
0
  /** Convert a HdfsFileStatus object to a Json string. */
  public static String toJsonString(final HdfsFileStatus status, boolean includeType) {
    if (status == null) {
      return null;
    }
    final Map<String, Object> m = new TreeMap<String, Object>();
    m.put("pathSuffix", status.getLocalName());
    m.put("type", PathType.valueOf(status));
    if (status.isSymlink()) {
      m.put("symlink", status.getSymlink());
    }

    m.put("length", status.getLen());
    m.put("owner", status.getOwner());
    m.put("group", status.getGroup());
    FsPermission perm = status.getPermission();
    m.put("permission", toString(perm));
    if (perm.getAclBit()) {
      m.put("aclBit", true);
    }
    if (perm.getEncryptedBit()) {
      m.put("encBit", true);
    }
    m.put("accessTime", status.getAccessTime());
    m.put("modificationTime", status.getModificationTime());
    m.put("blockSize", status.getBlockSize());
    m.put("replication", status.getReplication());
    m.put("fileId", status.getFileId());
    m.put("childrenNum", status.getChildrenNum());
    m.put("storagePolicy", status.getStoragePolicy());
    return includeType ? toJsonString(FileStatus.class, m) : JSON.toString(m);
  }
Exemplo n.º 2
0
 /**
  * Write a node to output. Node information includes path, modification, permission, owner and
  * group. For files, it also includes size, replication and block-size.
  */
 static void writeInfo(String parent, HdfsFileStatus i, XMLOutputter doc) throws IOException {
   final SimpleDateFormat ldf = df.get();
   doc.startTag(i.isDir() ? "directory" : "file");
   doc.attribute("path", i.getFullPath(new Path(parent)).toUri().getPath());
   doc.attribute("modified", ldf.format(new Date(i.getModificationTime())));
   doc.attribute("accesstime", ldf.format(new Date(i.getAccessTime())));
   if (!i.isDir()) {
     doc.attribute("size", String.valueOf(i.getLen()));
     doc.attribute("replication", String.valueOf(i.getReplication()));
     doc.attribute("blocksize", String.valueOf(i.getBlockSize()));
   }
   doc.attribute("permission", (i.isDir() ? "d" : "-") + i.getPermission());
   doc.attribute("owner", i.getOwner());
   doc.attribute("group", i.getGroup());
   doc.endTag();
 }
Exemplo n.º 3
0
 /** Convert a HdfsFileStatus object to a Json string. */
 public static String toJsonString(final HdfsFileStatus status, boolean includeType) {
   if (status == null) {
     return null;
   }
   final Map<String, Object> m = new TreeMap<String, Object>();
   m.put("localName", status.getLocalName());
   m.put("isDir", status.isDir());
   m.put("len", status.getLen());
   m.put("owner", status.getOwner());
   m.put("group", status.getGroup());
   m.put("permission", toString(status.getPermission()));
   m.put("accessTime", status.getAccessTime());
   m.put("modificationTime", status.getModificationTime());
   m.put("blockSize", status.getBlockSize());
   m.put("replication", status.getReplication());
   return includeType ? toJsonString(HdfsFileStatus.class, m) : JSON.toString(m);
 }