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 */
018package org.apache.hadoop.hdfs.client;
019
020import java.io.IOException;
021import java.util.List;
022
023import org.apache.hadoop.classification.InterfaceAudience;
024import org.apache.hadoop.classification.InterfaceStability;
025import org.apache.hadoop.fs.FSDataInputStream;
026import org.apache.hadoop.hdfs.DFSInputStream;
027import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
028import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
029import org.apache.hadoop.hdfs.protocol.LocatedBlock;
030
031/**
032 * The Hdfs implementation of {@link FSDataInputStream}.
033 */
034@InterfaceAudience.Public
035@InterfaceStability.Evolving
036public class HdfsDataInputStream extends FSDataInputStream {
037  public HdfsDataInputStream(DFSInputStream in) throws IOException {
038    super(in);
039  }
040
041  /**
042   * Get the datanode from which the stream is currently reading.
043   */
044  public DatanodeInfo getCurrentDatanode() {
045    return ((DFSInputStream) in).getCurrentDatanode();
046  }
047
048  /**
049   * Get the block containing the target position.
050   */
051  public ExtendedBlock getCurrentBlock() {
052    return ((DFSInputStream) in).getCurrentBlock();
053  }
054
055  /**
056   * Get the collection of blocks that has already been located.
057   */
058  public synchronized List<LocatedBlock> getAllBlocks() throws IOException {
059    return ((DFSInputStream) in).getAllBlocks();
060  }
061
062  /**
063   * Get the visible length of the file. It will include the length of the last
064   * block even if that is in UnderConstruction state.
065   * 
066   * @return The visible length of the file.
067   */
068  public long getVisibleLength() throws IOException {
069    return ((DFSInputStream) in).getFileLength();
070  }
071
072  /**
073   * Get statistics about the reads which this DFSInputStream has done.
074   * Note that because HdfsDataInputStream is buffered, these stats may
075   * be higher than you would expect just by adding up the number of
076   * bytes read through HdfsDataInputStream.
077   */
078  public synchronized DFSInputStream.ReadStatistics getReadStatistics() {
079    return ((DFSInputStream) in).getReadStatistics();
080  }
081}