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
019package org.apache.hadoop.fs;
020
021import java.io.IOException;
022
023import org.apache.hadoop.classification.InterfaceAudience;
024import org.apache.hadoop.classification.InterfaceStability;
025import 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
032public class LocatedFileStatus extends FileStatus {
033  private BlockLocation[] locations;
034
035
036  public LocatedFileStatus() {
037    super();
038  }
039
040  /**
041   * Constructor 
042   * @param stat a file status
043   * @param locations a file's block locations
044   */
045  public LocatedFileStatus(FileStatus stat, BlockLocation[] locations)
046  throws IOException {
047    this(stat.getLen(), stat.isDirectory(), stat.getReplication(),
048        stat.getBlockSize(), stat.getModificationTime(),
049        stat.getAccessTime(), stat.getPermission(), stat.getOwner(),
050        stat.getGroup(), null, stat.getPath(), locations);
051    if (stat.isSymlink()) {
052      setSymlink(stat.getSymlink());
053    }
054  }
055
056  /**
057   * Constructor
058   * 
059   * @param length a file's length
060   * @param isdir if the path is a directory
061   * @param block_replication the file's replication factor
062   * @param blocksize a file's block size
063   * @param modification_time a file's modification time
064   * @param access_time a file's access time
065   * @param permission a file's permission
066   * @param owner a file's owner
067   * @param group a file's group
068   * @param symlink symlink if the path is a symbolic link
069   * @param path the path's qualified name
070   * @param locations a file's block locations
071   */
072  public LocatedFileStatus(long length, boolean isdir,
073          int block_replication,
074          long blocksize, long modification_time, long access_time,
075          FsPermission permission, String owner, String group, 
076          Path symlink,
077          Path path,
078          BlockLocation[] locations) {
079          super(length, isdir, block_replication, blocksize, modification_time,
080                          access_time, permission, owner, group, symlink, path);
081          this.locations = locations;
082  }
083  
084  /**
085   * Get the file's block locations
086   * @return the file's block locations
087   */
088  public BlockLocation[] getBlockLocations() {
089          return locations;
090  }
091  
092  /**
093   * Compare this FileStatus to another FileStatus
094   * @param   o the FileStatus to be compared.
095   * @return  a negative integer, zero, or a positive integer as this object
096   *   is less than, equal to, or greater than the specified object.
097   */
098  @Override
099  public int compareTo(FileStatus o) {
100    return super.compareTo(o);
101  }
102  
103  /** Compare if this object is equal to another object
104   * @param   o the object to be compared.
105   * @return  true if two file status has the same path name; false if not.
106   */
107  @Override
108  public boolean equals(Object o) {
109    return super.equals(o);
110  }
111  
112  /**
113   * Returns a hash code value for the object, which is defined as
114   * the hash code of the path name.
115   *
116   * @return  a hash code value for the path name.
117   */
118  @Override
119  public int hashCode() {
120    return super.hashCode();
121  }
122}