001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 package org.apache.hadoop.fs;
020
021 import java.io.IOException;
022
023 import org.apache.hadoop.classification.InterfaceAudience;
024 import org.apache.hadoop.classification.InterfaceStability;
025 import org.apache.hadoop.fs.permission.FsPermission;
026
027 /**
028 * This class defines a FileStatus that includes a file's block locations.
029 */
030 @InterfaceAudience.Public
031 @InterfaceStability.Evolving
032 public class LocatedFileStatus extends FileStatus {
033 private BlockLocation[] locations;
034
035 /**
036 * Constructor
037 * @param stat a file status
038 * @param locations a file's block locations
039 */
040 public LocatedFileStatus(FileStatus stat, BlockLocation[] locations)
041 throws IOException {
042 this(stat.getLen(), stat.isDirectory(), stat.getReplication(),
043 stat.getBlockSize(), stat.getModificationTime(),
044 stat.getAccessTime(), stat.getPermission(), stat.getOwner(),
045 stat.getGroup(), null, stat.getPath(), locations);
046 if (isSymlink()) {
047 setSymlink(stat.getSymlink());
048 }
049 }
050
051 /**
052 * Constructor
053 *
054 * @param length a file's length
055 * @param isdir if the path is a directory
056 * @param block_replication the file's replication factor
057 * @param blocksize a file's block size
058 * @param modification_time a file's modification time
059 * @param access_time a file's access time
060 * @param permission a file's permission
061 * @param owner a file's owner
062 * @param group a file's group
063 * @param symlink symlink if the path is a symbolic link
064 * @param path the path's qualified name
065 * @param locations a file's block locations
066 */
067 public LocatedFileStatus(long length, boolean isdir,
068 int block_replication,
069 long blocksize, long modification_time, long access_time,
070 FsPermission permission, String owner, String group,
071 Path symlink,
072 Path path,
073 BlockLocation[] locations) {
074 super(length, isdir, block_replication, blocksize, modification_time,
075 access_time, permission, owner, group, symlink, path);
076 this.locations = locations;
077 }
078
079 /**
080 * Get the file's block locations
081 * @return the file's block locations
082 */
083 public BlockLocation[] getBlockLocations() {
084 return locations;
085 }
086
087 /**
088 * Compare this object to another object
089 *
090 * @param o the object to be compared.
091 * @return a negative integer, zero, or a positive integer as this object
092 * is less than, equal to, or greater than the specified object.
093 *
094 * @throws ClassCastException if the specified object's is not of
095 * type FileStatus
096 */
097 @Override
098 public int compareTo(Object o) {
099 return super.compareTo(o);
100 }
101
102 /** Compare if this object is equal to another object
103 * @param o the object to be compared.
104 * @return true if two file status has the same path name; false if not.
105 */
106 @Override
107 public boolean equals(Object o) {
108 return super.equals(o);
109 }
110
111 /**
112 * Returns a hash code value for the object, which is defined as
113 * the hash code of the path name.
114 *
115 * @return a hash code value for the path name.
116 */
117 @Override
118 public int hashCode() {
119 return super.hashCode();
120 }
121 }