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