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.mapred;
020
021import java.io.IOException;
022import java.io.DataInput;
023import java.io.DataOutput;
024
025import org.apache.hadoop.classification.InterfaceAudience;
026import org.apache.hadoop.classification.InterfaceStability;
027import org.apache.hadoop.classification.InterfaceStability.Evolving;
028import org.apache.hadoop.fs.Path;
029
030/** A section of an input file.  Returned by {@link
031 * InputFormat#getSplits(JobConf, int)} and passed to
032 * {@link InputFormat#getRecordReader(InputSplit,JobConf,Reporter)}. 
033 */
034@InterfaceAudience.Public
035@InterfaceStability.Stable
036public class FileSplit extends org.apache.hadoop.mapreduce.InputSplit 
037                       implements InputSplitWithLocationInfo {
038  org.apache.hadoop.mapreduce.lib.input.FileSplit fs; 
039  protected FileSplit() {
040    fs = new org.apache.hadoop.mapreduce.lib.input.FileSplit();
041  }
042
043  /** Constructs a split.
044   * @deprecated
045   * @param file the file name
046   * @param start the position of the first byte in the file to process
047   * @param length the number of bytes in the file to process
048   */
049  @Deprecated
050  public FileSplit(Path file, long start, long length, JobConf conf) {
051    this(file, start, length, (String[])null);
052  }
053
054  /** Constructs a split with host information
055   *
056   * @param file the file name
057   * @param start the position of the first byte in the file to process
058   * @param length the number of bytes in the file to process
059   * @param hosts the list of hosts containing the block, possibly null
060   */
061  public FileSplit(Path file, long start, long length, String[] hosts) {
062    fs = new org.apache.hadoop.mapreduce.lib.input.FileSplit(file, start,
063           length, hosts);
064  }
065  
066  /** Constructs a split with host information
067  *
068  * @param file the file name
069  * @param start the position of the first byte in the file to process
070  * @param length the number of bytes in the file to process
071  * @param hosts the list of hosts containing the block, possibly null
072  * @param inMemoryHosts the list of hosts containing the block in memory
073  */
074 public FileSplit(Path file, long start, long length, String[] hosts,
075     String[] inMemoryHosts) {
076   fs = new org.apache.hadoop.mapreduce.lib.input.FileSplit(file, start,
077          length, hosts, inMemoryHosts);
078 }
079  
080  public FileSplit(org.apache.hadoop.mapreduce.lib.input.FileSplit fs) {
081    this.fs = fs;
082  }
083
084  /** The file containing this split's data. */
085  public Path getPath() { return fs.getPath(); }
086  
087  /** The position of the first byte in the file to process. */
088  public long getStart() { return fs.getStart(); }
089  
090  /** The number of bytes in the file to process. */
091  public long getLength() { return fs.getLength(); }
092
093  public String toString() { return fs.toString(); }
094
095  ////////////////////////////////////////////
096  // Writable methods
097  ////////////////////////////////////////////
098
099  public void write(DataOutput out) throws IOException {
100    fs.write(out);
101  }
102  public void readFields(DataInput in) throws IOException {
103    fs.readFields(in);
104  }
105
106  public String[] getLocations() throws IOException {
107    return fs.getLocations();
108  }
109  
110  @Override
111  @Evolving
112  public SplitLocationInfo[] getLocationInfo() throws IOException {
113    return fs.getLocationInfo();
114  }
115}