/// <summary>Convert a HdfsFileStatus object to a Json string.</summary> public static string ToJsonString(HdfsFileStatus status, bool includeType) { if (status == null) { return(null); } IDictionary <string, object> m = new SortedDictionary <string, object>(); m["pathSuffix"] = status.GetLocalName(); m["type"] = JsonUtil.PathType.ValueOf(status); if (status.IsSymlink()) { m["symlink"] = status.GetSymlink(); } m["length"] = status.GetLen(); m["owner"] = status.GetOwner(); m["group"] = status.GetGroup(); FsPermission perm = status.GetPermission(); m["permission"] = ToString(perm); if (perm.GetAclBit()) { m["aclBit"] = true; } if (perm.GetEncryptedBit()) { m["encBit"] = true; } m["accessTime"] = status.GetAccessTime(); m["modificationTime"] = status.GetModificationTime(); m["blockSize"] = status.GetBlockSize(); m["replication"] = status.GetReplication(); m["fileId"] = status.GetFileId(); m["childrenNum"] = status.GetChildrenNum(); m["storagePolicy"] = status.GetStoragePolicy(); ObjectMapper mapper = new ObjectMapper(); try { return(includeType ? ToJsonString(typeof(FileStatus), m) : mapper.WriteValueAsString (m)); } catch (IOException) { } return(null); }
/// <summary>Write a node to output.</summary> /// <remarks> /// Write a node to output. /// Node information includes path, modification, permission, owner and group. /// For files, it also includes size, replication and block-size. /// </remarks> /// <exception cref="System.IO.IOException"/> internal static void WriteInfo(Path fullpath, HdfsFileStatus i, XMLOutputter doc) { SimpleDateFormat ldf = df.Get(); doc.StartTag(i.IsDir() ? "directory" : "file"); doc.Attribute("path", fullpath.ToUri().GetPath()); doc.Attribute("modified", ldf.Format(Sharpen.Extensions.CreateDate(i.GetModificationTime ()))); doc.Attribute("accesstime", ldf.Format(Sharpen.Extensions.CreateDate(i.GetAccessTime ()))); if (!i.IsDir()) { doc.Attribute("size", i.GetLen().ToString()); doc.Attribute("replication", i.GetReplication().ToString()); doc.Attribute("blocksize", i.GetBlockSize().ToString()); } doc.Attribute("permission", (i.IsDir() ? "d" : "-") + i.GetPermission()); doc.Attribute("owner", i.GetOwner()); doc.Attribute("group", i.GetGroup()); doc.EndTag(); }
internal static FileStatus ToFileStatus(HdfsFileStatus f, string parent) { return(new FileStatus(f.GetLen(), f.IsDir(), f.GetReplication(), f.GetBlockSize() , f.GetModificationTime(), f.GetAccessTime(), f.GetPermission(), f.GetOwner(), f .GetGroup(), f.IsSymlink() ? new Path(f.GetSymlink()) : null, new Path(f.GetFullName (parent)))); }
public static Nfs3FileAttributes GetNfs3FileAttrFromFileStatus(HdfsFileStatus fs, IdMappingServiceProvider iug) { NfsFileType fileType = fs.IsDir() ? NfsFileType.Nfsdir : NfsFileType.Nfsreg; fileType = fs.IsSymlink() ? NfsFileType.Nfslnk : fileType; int nlink = (fileType == NfsFileType.Nfsdir) ? fs.GetChildrenNum() + 2 : 1; long size = (fileType == NfsFileType.Nfsdir) ? GetDirSize(fs.GetChildrenNum()) : fs.GetLen(); return(new Nfs3FileAttributes(fileType, nlink, fs.GetPermission().ToShort(), iug. GetUidAllowingUnknown(fs.GetOwner()), iug.GetGidAllowingUnknown(fs.GetGroup()), size, 0, fs.GetFileId(), fs.GetModificationTime(), fs.GetAccessTime(), new Nfs3FileAttributes.Specdata3 ())); }