/** * Converts a byte array to a string using UTF8 encoding. */ public static String bytes2String(byte[] bytes) { return bytes2String(bytes, 0, bytes.length); }
public String getSymlinkString() { return DFSUtil.bytes2String(symlink); }
public INodeAttributes getAttributes(byte[][] components, INodeAttributes inode) { String[] elements = new String[components.length]; for (int i = 0; i < elements.length; i++) { elements[i] = DFSUtil.bytes2String(components[i]); } return getAttributes(elements, inode); }
/** * @return null if the local name is null; otherwise, return the local name. */ public final String getLocalName() { final byte[] name = getLocalNameBytes(); return name == null? null: DFSUtil.bytes2String(name); }
(firstComponent == null || firstComponent.length == 0)); if (offset == 0 && length == 1) { return isAbsolute ? Path.SEPARATOR : bytes2String(firstComponent); pos += len; return bytes2String(result);
/** * Verify child's name for fs limit. * * @param childName byte[] containing new child name * @param parentPath String containing parent path * @throws PathComponentTooLongException child's name is too long. */ void verifyMaxComponentLength(byte[] childName, String parentPath) throws PathComponentTooLongException { if (maxComponentLength == 0) { return; } final int length = childName.length; if (length > maxComponentLength) { final PathComponentTooLongException e = new PathComponentTooLongException( maxComponentLength, length, parentPath, DFSUtil.bytes2String(childName)); if (namesystem.isImageLoaded()) { throw e; } else { // Do not throw if edits log is still being processed NameNode.LOG.error("ERROR in FSDirectory.verifyINodeName", e); } } }
/** * Load a node stored in the created list from fsimage. * @param createdNodeName The name of the created node. * @param parent The directory that the created list belongs to. * @return The created node. */ public static INode loadCreated(byte[] createdNodeName, INodeDirectory parent) throws IOException { // the INode in the created list should be a reference to another INode // in posterior SnapshotDiffs or one of the current children for (DirectoryDiff postDiff : parent.getDiffs()) { final INode d = postDiff.getChildrenDiff().getDeleted(createdNodeName); if (d != null) { return d; } // else go to the next SnapshotDiff } // use the current child INode currentChild = parent.getChild(createdNodeName, Snapshot.CURRENT_STATE_ID); if (currentChild == null) { throw new IOException("Cannot find an INode associated with the INode " + DFSUtil.bytes2String(createdNodeName) + " in created list while loading FSImage."); } return currentChild; }
public String getFullPathName() { // Get the full path name of this inode. if (isRoot()) { return Path.SEPARATOR; } // compute size of needed bytes for the path int idx = 0; for (INode inode = this; inode != null; inode = inode.getParent()) { // add component + delimiter (if not tail component) idx += inode.getLocalNameBytes().length + (inode != this ? 1 : 0); } byte[] path = new byte[idx]; for (INode inode = this; inode != null; inode = inode.getParent()) { if (inode != this) { path[--idx] = Path.SEPARATOR_CHAR; } byte[] name = inode.getLocalNameBytes(); idx -= name.length; System.arraycopy(name, 0, path, idx, name.length); } return DFSUtil.bytes2String(path); }
private INodeAttributes getINodeAttrs(byte[][] pathByNameArr, int pathIdx, INode inode, int snapshotId) { INodeAttributes inodeAttrs = inode.getSnapshotINode(snapshotId); if (getAttributesProvider() != null) { String[] elements = new String[pathIdx + 1]; /** * {@link INode#getPathComponents(String)} returns a null component * for the root only path "/". Assign an empty string if so. */ if (pathByNameArr.length == 1 && pathByNameArr[0] == null) { elements[0] = ""; } else { for (int i = 0; i < elements.length; i++) { elements[i] = DFSUtil.bytes2String(pathByNameArr[i]); } } inodeAttrs = getAttributesProvider().getAttributes(elements, inodeAttrs); } return inodeAttrs; }
private static byte[][] resolveDotInodesPath( byte[][] pathComponents, FSDirectory fsd) throws FileNotFoundException { final String inodeId = DFSUtil.bytes2String(pathComponents[3]); final long id; try {
components[1] = DFSUtil.bytes2String( renameReservedRootComponentOnUpgrade( DFSUtil.string2Bytes(components[1]), components[i] = DFSUtil.bytes2String( renameReservedComponentOnUpgrade( DFSUtil.string2Bytes(components[i]),
existing.getPath() + "/" + DFSUtil.bytes2String(localName)); return null; DFSUtil.bytes2String(localName) + " is added");
/** * Get the string representation of the symlink. * @return the symlink as a string. */ public final String getSymlink() { return DFSUtil.bytes2String(symlink); }
/** * Get the string representation of the local name * @return the local name in string */ public final String getLocalName() { return DFSUtil.bytes2String(path); }
static String getPathString(byte[] path) { String pathStr = DFSUtil.bytes2String(path); if (pathStr.isEmpty()) { return Path.CUR_DIR; } else { return Path.CUR_DIR + Path.SEPARATOR + pathStr; } }
/** * create a directory at path specified by parent */ private static INodesInPath unprotectedMkdir(FSDirectory fsd, long inodeId, INodesInPath parent, byte[] name, PermissionStatus permission, List<AclEntry> aclEntries, long timestamp) throws QuotaExceededException, AclException, FileAlreadyExistsException { assert fsd.hasWriteLock(); assert parent.getLastINode() != null; if (!parent.getLastINode().isDirectory()) { throw new FileAlreadyExistsException("Parent path is not a directory: " + parent.getPath() + " " + DFSUtil.bytes2String(name)); } final INodeDirectory dir = new INodeDirectory(inodeId, name, permission, timestamp); INodesInPath iip = fsd.addLastINode(parent, dir, permission.getPermission(), true); if (iip != null && aclEntries != null) { AclStorage.updateINodeAcl(dir, aclEntries, Snapshot.CURRENT_STATE_ID); } return iip; } }
static DirectoryListing getListingInt(FSDirectory fsd, FSPermissionChecker pc, final String srcArg, byte[] startAfter, boolean needLocation) throws IOException { final INodesInPath iip = fsd.resolvePath(pc, srcArg, DirOp.READ); // Get file name when startAfter is an INodePath. This is not the // common case so avoid any unnecessary processing unless required. if (startAfter.length > 0 && startAfter[0] == Path.SEPARATOR_CHAR) { final String startAfterString = DFSUtil.bytes2String(startAfter); if (FSDirectory.isReservedName(startAfterString)) { try { byte[][] components = INode.getPathComponents(startAfterString); components = FSDirectory.resolveComponents(components, fsd); startAfter = components[components.length - 1]; } catch (IOException e) { // Possibly the inode is deleted throw new DirectoryListingStartAfterNotFoundException( "Can't find startAfter " + startAfterString); } } } boolean isSuperUser = true; if (fsd.isPermissionEnabled()) { if (iip.getLastINode() != null && iip.getLastINode().isDirectory()) { fsd.checkPathAccess(pc, iip, FsAction.READ_EXECUTE); } isSuperUser = pc.isSuperUser(); } return getListing(fsd, iip, startAfter, needLocation, isSuperUser); }
public INodeAttributes getAttributes(byte[][] components, INodeAttributes inode) { String[] elements = new String[components.length]; for (int i = 0; i < elements.length; i++) { elements[i] = DFSUtil.bytes2String(components[i]); } return getAttributes(elements, inode); }
/** * @return null if the local name is null; otherwise, return the local name. */ public final String getLocalName() { final byte[] name = getLocalNameBytes(); return name == null? null: DFSUtil.bytes2String(name); }
private INodeAttributes getINodeAttrs(byte[][] pathByNameArr, int pathIdx, INode inode, int snapshotId) { INodeAttributes inodeAttrs = inode.getSnapshotINode(snapshotId); if (getAttributesProvider() != null) { String[] elements = new String[pathIdx + 1]; for (int i = 0; i < elements.length; i++) { elements[i] = DFSUtil.bytes2String(pathByNameArr[i]); } inodeAttrs = getAttributesProvider().getAttributes(elements, inodeAttrs); } return inodeAttrs; }