/** Convert a DatanodeInfo[] to a Json array. */ private static Object[] toJsonArray(final DatanodeInfo[] array) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_OBJECT_ARRAY; } else { final Object[] a = new Object[array.length]; for(int i = 0; i < array.length; i++) { a[i] = toJsonMap(array[i]); } return a; } }
private static Object[] toJsonArray(final List<XAttr> array, final XAttrCodec encoding) throws IOException { if (array == null) { return null; } else if (array.size() == 0) { return EMPTY_OBJECT_ARRAY; } else { final Object[] a = new Object[array.size()]; for(int i = 0; i < array.size(); i++) { a[i] = toJsonMap(array.get(i), encoding); } return a; } }
/** Convert a LocatedBlock[] to a Json array. */ private static Object[] toJsonArray(final List<LocatedBlock> array ) throws IOException { if (array == null) { return null; } else if (array.size() == 0) { return EMPTY_OBJECT_ARRAY; } else { final Object[] a = new Object[array.size()]; for(int i = 0; i < array.size(); i++) { a[i] = toJsonMap(array.get(i)); } return a; } }
private static Map<String, Object> toJsonMap(HdfsFileStatus[] statuses) throws IOException { if (statuses == null) { return null; } final Map<String, Object> fileStatuses = new TreeMap<>(); final Map<String, Object> fileStatus = new TreeMap<>(); fileStatuses.put("FileStatuses", fileStatus); final Object[] array = new Object[statuses.length]; fileStatus.put("FileStatus", array); for (int i = 0; i < statuses.length; i++) { array[i] = toJsonMap(statuses[i]); } return fileStatuses; }
public static String toJsonString(BlockStoragePolicy[] storagePolicies) { final Map<String, Object> blockStoragePolicies = new TreeMap<>(); Object[] a = null; if (storagePolicies != null && storagePolicies.length > 0) { a = new Object[storagePolicies.length]; for (int i = 0; i < storagePolicies.length; i++) { a[i] = toJsonMap(storagePolicies[i]); } } blockStoragePolicies.put("BlockStoragePolicy", a); return toJsonString("BlockStoragePolicies", blockStoragePolicies); }
/** Convert a token object to a Json string. */ public static String toJsonString(final Token<? extends TokenIdentifier> token ) throws IOException { return toJsonString(Token.class, toJsonMap(token)); }
public static String toJsonString(SnapshotDiffReport diffReport) { return toJsonString(SnapshotDiffReport.class.getSimpleName(), toJsonMap(diffReport)); }
public static String toJsonString(FsServerDefaults serverDefaults) { return toJsonString(FsServerDefaults.class, toJsonMap(serverDefaults)); }
public static String toJsonString(BlockLocation[] locations) throws IOException { if (locations == null) { return null; } final Map<String, Object> m = new HashMap<>(); Object[] blockLocations = new Object[locations.length]; for(int i=0; i<locations.length; i++) { blockLocations[i] = toJsonMap(locations[i]); } m.put(BlockLocation.class.getSimpleName(), blockLocations); return toJsonString("BlockLocations", m); } }
/** 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 = toJsonMap(status); try { return includeType ? toJsonString(FileStatus.class, m) : MAPPER.writeValueAsString(m); } catch (IOException ignored) { } return null; }
public static String toJsonString(BlockStoragePolicy storagePolicy) { return toJsonString(BlockStoragePolicy.class, toJsonMap(storagePolicy)); }
private static Map<String, Object> toJson(final DirectoryListing listing) throws IOException { final Map<String, Object> m = new TreeMap<>(); // Serialize FileStatus[] to a FileStatuses map m.put("partialListing", toJsonMap(listing.getPartialListing())); // Simple int m.put("remainingEntries", listing.getRemainingEntries()); return m; }
public static String toJsonString( SnapshottableDirectoryStatus[] snapshottableDirectoryList) { if (snapshottableDirectoryList == null) { return toJsonString("SnapshottableDirectoryList", null); } Object[] a = new Object[snapshottableDirectoryList.length]; for (int i = 0; i < snapshottableDirectoryList.length; i++) { a[i] = toJsonMap(snapshottableDirectoryList[i]); } return toJsonString("SnapshottableDirectoryList", a); }
private static Object toJsonMap(SnapshotDiffReport diffReport) { final Map<String, Object> m = new TreeMap<String, Object>(); m.put("snapshotRoot", diffReport.getSnapshotRoot()); m.put("fromSnapshot", diffReport.getFromSnapshot()); m.put("toSnapshot", diffReport.getLaterSnapshotName()); Object[] diffList = new Object[diffReport.getDiffList().size()]; for (int i = 0; i < diffReport.getDiffList().size(); i++) { diffList[i] = toJsonMap(diffReport.getDiffList().get(i)); } m.put("diffList", diffList); return m; }
private static Object toJsonMap( SnapshottableDirectoryStatus snapshottableDirectoryStatus) { final Map<String, Object> m = new TreeMap<String, Object>(); m.put("snapshotNumber", snapshottableDirectoryStatus.getSnapshotNumber()); m.put("snapshotQuota", snapshottableDirectoryStatus.getSnapshotQuota()); m.put("parentFullPath", DFSUtilClient .bytes2String(snapshottableDirectoryStatus.getParentFullPath())); m.put("dirStatus", toJsonMap(snapshottableDirectoryStatus.getDirStatus())); return m; }
/** Convert LocatedBlocks to a Json string. */ public static String toJsonString(final LocatedBlocks locatedblocks ) throws IOException { if (locatedblocks == null) { return null; } final Map<String, Object> m = new TreeMap<String, Object>(); m.put("fileLength", locatedblocks.getFileLength()); m.put("isUnderConstruction", locatedblocks.isUnderConstruction()); m.put("locatedBlocks", toJsonArray(locatedblocks.getLocatedBlocks())); m.put("lastLocatedBlock", toJsonMap(locatedblocks.getLastLocatedBlock())); m.put("isLastBlockComplete", locatedblocks.isLastBlockComplete()); return toJsonString(LocatedBlocks.class, m); }
/** Convert a LocatedBlock to a Json map. */ private static Map<String, Object> toJsonMap(final LocatedBlock locatedblock ) throws IOException { if (locatedblock == null) { return null; } final Map<String, Object> m = new TreeMap<String, Object>(); m.put("blockToken", toJsonMap(locatedblock.getBlockToken())); m.put("isCorrupt", locatedblock.isCorrupt()); m.put("startOffset", locatedblock.getStartOffset()); m.put("block", toJsonMap(locatedblock.getBlock())); m.put("storageTypes", toJsonArray(locatedblock.getStorageTypes())); m.put("locations", toJsonArray(locatedblock.getLocations())); m.put("cachedLocations", toJsonArray(locatedblock.getCachedLocations())); return m; }
/** Convert a token object to a Json string. */ public static String toJsonString(final Token<? extends TokenIdentifier> token ) throws IOException { return toJsonString(Token.class, toJsonMap(token)); }
/** Convert a token object to a Json string. */ public static String toJsonString(final Token<? extends TokenIdentifier> token ) throws IOException { return toJsonString(Token.class, toJsonMap(token)); }
/** Convert LocatedBlocks to a Json string. */ public static String toJsonString(final LocatedBlocks locatedblocks ) throws IOException { if (locatedblocks == null) { return null; } final Map<String, Object> m = new TreeMap<String, Object>(); m.put("fileLength", locatedblocks.getFileLength()); m.put("isUnderConstruction", locatedblocks.isUnderConstruction()); m.put("locatedBlocks", toJsonArray(locatedblocks.getLocatedBlocks())); m.put("lastLocatedBlock", toJsonMap(locatedblocks.getLastLocatedBlock())); m.put("isLastBlockComplete", locatedblocks.isLastBlockComplete()); return toJsonString(LocatedBlocks.class, m); }