Save This Page
Home » hadoop-0.14.4 » org.apache » hadoop » fs » [javadoc | source]
    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one
    3    * or more contributor license agreements.  See the NOTICE file
    4    * distributed with this work for additional information
    5    * regarding copyright ownership.  The ASF licenses this file
    6    * to you under the Apache License, Version 2.0 (the
    7    * "License"); you may not use this file except in compliance
    8    * with the License.  You may obtain a copy of the License at
    9    *
   10    *     http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    * Unless required by applicable law or agreed to in writing, software
   13    * distributed under the License is distributed on an "AS IS" BASIS,
   14    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   15    * See the License for the specific language governing permissions and
   16    * limitations under the License.
   17    */
   18   
   19   package org.apache.hadoop.fs;
   20   
   21   import java.io;
   22   import java.net.URI;
   23   
   24   import org.apache.hadoop.conf.Configuration;
   25   import org.apache.hadoop.util.Progressable;
   26   
   27   /****************************************************************
   28    * A <code>FilterFileSystem</code> contains
   29    * some other file system, which it uses as
   30    * its  basic file system, possibly transforming
   31    * the data along the way or providing  additional
   32    * functionality. The class <code>FilterFileSystem</code>
   33    * itself simply overrides all  methods of
   34    * <code>FileSystem</code> with versions that
   35    * pass all requests to the contained  file
   36    * system. Subclasses of <code>FilterFileSystem</code>
   37    * may further override some of  these methods
   38    * and may also provide additional methods
   39    * and fields.
   40    *
   41    *****************************************************************/
   42   public class FilterFileSystem extends FileSystem {
   43     
   44     protected FileSystem fs;
   45     
   46     public FilterFileSystem(FileSystem fs) {
   47       this.fs = fs;
   48     }
   49   
   50     /** Called after a new FileSystem instance is constructed.
   51      * @param name a uri whose authority section names the host, port, etc.
   52      *   for this FileSystem
   53      * @param conf the configuration
   54      */
   55     public void initialize(URI name, Configuration conf) throws IOException {
   56       fs.initialize(name, conf);
   57     }
   58   
   59     /** Returns a URI whose scheme and authority identify this FileSystem.*/
   60     public URI getUri() {
   61       return fs.getUri();
   62     }
   63   
   64     /** @deprecated call #getUri() instead.*/
   65     public String getName() {
   66       return fs.getName();
   67     }
   68   
   69     /** Make sure that a path specifies a FileSystem. */
   70     public Path makeQualified(Path path) {
   71       return fs.makeQualified(path);
   72     }
   73     
   74     ///////////////////////////////////////////////////////////////
   75     // FileSystem
   76     ///////////////////////////////////////////////////////////////
   77   
   78     /** Check that a Path belongs to this FileSystem. */
   79     protected void checkPath(Path path) {
   80       fs.checkPath(path);
   81     }
   82   
   83     /**
   84      * Return a 2D array of size 1x1 or greater, containing hostnames 
   85      * where portions of the given file can be found.  For a nonexistent 
   86      * file or regions, null will be returned.
   87      *
   88      * This call is most helpful with DFS, where it returns 
   89      * hostnames of machines that contain the given file.
   90      *
   91      * The FileSystem will simply return an elt containing 'localhost'.
   92      */
   93     public String[][] getFileCacheHints(Path f, long start, long len)
   94       throws IOException {
   95       return fs.getFileCacheHints(f, start, len);
   96     }
   97   
   98     /**
   99      * Opens an FSDataInputStream at the indicated Path.
  100      * @param f the file name to open
  101      * @param bufferSize the size of the buffer to be used.
  102      */
  103     public FSDataInputStream open(Path f, int bufferSize) throws IOException {
  104       return fs.open(f, bufferSize);
  105     }
  106     
  107     /**
  108      * Opens an FSDataOutputStream at the indicated Path with write-progress
  109      * reporting.
  110      * @param f the file name to open
  111      * @param overwrite if a file with this name already exists, then if true,
  112      *   the file will be overwritten, and if false an error will be thrown.
  113      * @param bufferSize the size of the buffer to be used.
  114      * @param replication required block replication for the file. 
  115      */
  116     public FSDataOutputStream create(Path f, 
  117                                      boolean overwrite,
  118                                      int bufferSize,
  119                                      short replication,
  120                                      long blockSize,
  121                                      Progressable progress
  122                                      ) throws IOException {
  123       return fs.create(f, overwrite, bufferSize, replication, blockSize, progress);
  124     }
  125   
  126     /**
  127      * Set replication for an existing file.
  128      * 
  129      * @param src file name
  130      * @param replication new replication
  131      * @throws IOException
  132      * @return true if successful;
  133      *         false if file does not exist or is a directory
  134      */
  135     public boolean setReplication(Path src, short replication) throws IOException {
  136       return fs.setReplication(src, replication);
  137     }
  138     
  139     /**
  140      * Renames Path src to Path dst.  Can take place on local fs
  141      * or remote DFS.
  142      */
  143     public boolean rename(Path src, Path dst) throws IOException {
  144       return fs.rename(src, dst);
  145     }
  146     
  147     /** Delete a file */
  148     public boolean delete(Path f) throws IOException {
  149       return fs.delete(f);
  150     }
  151     
  152     /** Check if exists.
  153      * @param f source file
  154      */
  155     public boolean exists(Path f) throws IOException {
  156       return fs.exists(f);
  157     }
  158   
  159     /** List files in a directory. */
  160     public Path[] listPaths(Path f) throws IOException {
  161       return fs.listPaths(f);
  162     }
  163     
  164     /**
  165      * Set the current working directory for the given file system. All relative
  166      * paths will be resolved relative to it.
  167      * 
  168      * @param newDir
  169      */
  170     public void setWorkingDirectory(Path newDir) {
  171       fs.setWorkingDirectory(newDir);
  172     }
  173     
  174     /**
  175      * Get the current working directory for the given file system
  176      * 
  177      * @return the directory pathname
  178      */
  179     public Path getWorkingDirectory() {
  180       return fs.getWorkingDirectory();
  181     }
  182     
  183     /**
  184      * Make the given file and all non-existent parents into directories. Has
  185      * the semantics of Unix 'mkdir -p'. Existence of the directory hierarchy is
  186      * not an error.
  187      */
  188     public boolean mkdirs(Path f) throws IOException {
  189       return fs.mkdirs(f);
  190     }
  191   
  192     /**
  193      * Obtain a lock on the given Path
  194      * 
  195      * @deprecated FS does not support file locks anymore.
  196      */
  197     @Deprecated
  198     public void lock(Path f, boolean shared) throws IOException {
  199       fs.lock(f, shared);
  200     }
  201   
  202     /**
  203      * Release the lock
  204      * 
  205      * @deprecated FS does not support file locks anymore.     
  206      */
  207     @Deprecated
  208     public void release(Path f) throws IOException {
  209       fs.release(f);
  210     }
  211   
  212     /**
  213      * The src file is on the local disk.  Add it to FS at
  214      * the given dst name.
  215      * delSrc indicates if the source should be removed
  216      */
  217     public void copyFromLocalFile(boolean delSrc, Path src, Path dst)
  218       throws IOException {
  219       fs.copyFromLocalFile(delSrc, src, dst);
  220     }
  221     
  222     /**
  223      * The src file is under FS, and the dst is on the local disk.
  224      * Copy it from FS control to the local dst name.
  225      * delSrc indicates if the src will be removed or not.
  226      */   
  227     public void copyToLocalFile(boolean delSrc, Path src, Path dst)
  228       throws IOException {
  229       fs.copyToLocalFile(delSrc, src, dst);
  230     }
  231     
  232     /**
  233      * Returns a local File that the user can write output to.  The caller
  234      * provides both the eventual FS target name and the local working
  235      * file.  If the FS is local, we write directly into the target.  If
  236      * the FS is remote, we write into the tmp local area.
  237      */
  238     public Path startLocalOutput(Path fsOutputFile, Path tmpLocalFile)
  239       throws IOException {
  240       return fs.startLocalOutput(fsOutputFile, tmpLocalFile);
  241     }
  242   
  243     /**
  244      * Called when we're all done writing to the target.  A local FS will
  245      * do nothing, because we've written to exactly the right place.  A remote
  246      * FS will copy the contents of tmpLocalFile to the correct target at
  247      * fsOutputFile.
  248      */
  249     public void completeLocalOutput(Path fsOutputFile, Path tmpLocalFile)
  250       throws IOException {
  251       fs.completeLocalOutput(fsOutputFile, tmpLocalFile);
  252     }
  253   
  254     /** Return the number of bytes that large input files should be optimally
  255      * be split into to minimize i/o time. */
  256     public long getDefaultBlockSize() {
  257       return fs.getDefaultBlockSize();
  258     }
  259     
  260     /**
  261      * Get the default replication.
  262      */
  263     public short getDefaultReplication() {
  264       return fs.getDefaultReplication();
  265     }
  266   
  267     /**
  268      * Get file status.
  269      */
  270     public FileStatus getFileStatus(Path f) throws IOException {
  271       return fs.getFileStatus(f);
  272     }
  273   
  274     @Override
  275     public Configuration getConf() {
  276       return fs.getConf();
  277     }
  278     
  279     @Override
  280     public void close() throws IOException {
  281       super.close();
  282       fs.close();
  283     }
  284   }

Save This Page
Home » hadoop-0.14.4 » org.apache » hadoop » fs » [javadoc | source]