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.fs; 020 021 import java.io.*; 022 import java.net.URI; 023 import java.util.EnumSet; 024 import java.util.List; 025 026 import org.apache.hadoop.classification.InterfaceAudience; 027 import org.apache.hadoop.classification.InterfaceStability; 028 import org.apache.hadoop.conf.Configuration; 029 import org.apache.hadoop.fs.permission.FsPermission; 030 import org.apache.hadoop.security.token.Token; 031 import org.apache.hadoop.util.Progressable; 032 033 /**************************************************************** 034 * A <code>FilterFileSystem</code> contains 035 * some other file system, which it uses as 036 * its basic file system, possibly transforming 037 * the data along the way or providing additional 038 * functionality. The class <code>FilterFileSystem</code> 039 * itself simply overrides all methods of 040 * <code>FileSystem</code> with versions that 041 * pass all requests to the contained file 042 * system. Subclasses of <code>FilterFileSystem</code> 043 * may further override some of these methods 044 * and may also provide additional methods 045 * and fields. 046 * 047 *****************************************************************/ 048 @InterfaceAudience.Public 049 @InterfaceStability.Stable 050 public class FilterFileSystem extends FileSystem { 051 052 protected FileSystem fs; 053 054 /* 055 * so that extending classes can define it 056 */ 057 public FilterFileSystem() { 058 } 059 060 public FilterFileSystem(FileSystem fs) { 061 this.fs = fs; 062 this.statistics = fs.statistics; 063 } 064 065 /** Called after a new FileSystem instance is constructed. 066 * @param name a uri whose authority section names the host, port, etc. 067 * for this FileSystem 068 * @param conf the configuration 069 */ 070 public void initialize(URI name, Configuration conf) throws IOException { 071 fs.initialize(name, conf); 072 } 073 074 /** Returns a URI whose scheme and authority identify this FileSystem.*/ 075 public URI getUri() { 076 return fs.getUri(); 077 } 078 079 /** Make sure that a path specifies a FileSystem. */ 080 public Path makeQualified(Path path) { 081 return fs.makeQualified(path); 082 } 083 084 /////////////////////////////////////////////////////////////// 085 // FileSystem 086 /////////////////////////////////////////////////////////////// 087 088 /** Check that a Path belongs to this FileSystem. */ 089 protected void checkPath(Path path) { 090 fs.checkPath(path); 091 } 092 093 public BlockLocation[] getFileBlockLocations(FileStatus file, long start, 094 long len) throws IOException { 095 return fs.getFileBlockLocations(file, start, len); 096 } 097 098 @Override 099 public Path resolvePath(final Path p) throws IOException { 100 return fs.resolvePath(p); 101 } 102 /** 103 * Opens an FSDataInputStream at the indicated Path. 104 * @param f the file name to open 105 * @param bufferSize the size of the buffer to be used. 106 */ 107 public FSDataInputStream open(Path f, int bufferSize) throws IOException { 108 return fs.open(f, bufferSize); 109 } 110 111 /** {@inheritDoc} */ 112 public FSDataOutputStream append(Path f, int bufferSize, 113 Progressable progress) throws IOException { 114 return fs.append(f, bufferSize, progress); 115 } 116 117 /** {@inheritDoc} */ 118 @Override 119 public FSDataOutputStream create(Path f, FsPermission permission, 120 boolean overwrite, int bufferSize, short replication, long blockSize, 121 Progressable progress) throws IOException { 122 return fs.create(f, permission, 123 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, boolean recursive) throws IOException { 149 return fs.delete(f, recursive); 150 } 151 152 /** 153 * Mark a path to be deleted when FileSystem is closed. 154 * When the JVM shuts down, 155 * all FileSystem objects will be closed automatically. 156 * Then, 157 * the marked path will be deleted as a result of closing the FileSystem. 158 * 159 * The path has to exist in the file system. 160 * 161 * @param f the path to delete. 162 * @return true if deleteOnExit is successful, otherwise false. 163 * @throws IOException 164 */ 165 public boolean deleteOnExit(Path f) throws IOException { 166 return fs.deleteOnExit(f); 167 } 168 169 /** List files in a directory. */ 170 public FileStatus[] listStatus(Path f) throws IOException { 171 return fs.listStatus(f); 172 } 173 174 /** 175 * {@inheritDoc} 176 */ 177 @Override 178 public RemoteIterator<Path> listCorruptFileBlocks(Path path) 179 throws IOException { 180 return fs.listCorruptFileBlocks(path); 181 } 182 183 /** List files and its block locations in a directory. */ 184 public RemoteIterator<LocatedFileStatus> listLocatedStatus(Path f) 185 throws IOException { 186 return fs.listLocatedStatus(f); 187 } 188 189 public Path getHomeDirectory() { 190 return fs.getHomeDirectory(); 191 } 192 193 194 /** 195 * Set the current working directory for the given file system. All relative 196 * paths will be resolved relative to it. 197 * 198 * @param newDir 199 */ 200 public void setWorkingDirectory(Path newDir) { 201 fs.setWorkingDirectory(newDir); 202 } 203 204 /** 205 * Get the current working directory for the given file system 206 * 207 * @return the directory pathname 208 */ 209 public Path getWorkingDirectory() { 210 return fs.getWorkingDirectory(); 211 } 212 213 protected Path getInitialWorkingDirectory() { 214 return fs.getInitialWorkingDirectory(); 215 } 216 217 /** {@inheritDoc} */ 218 @Override 219 public FsStatus getStatus(Path p) throws IOException { 220 return fs.getStatus(p); 221 } 222 223 /** {@inheritDoc} */ 224 @Override 225 public boolean mkdirs(Path f, FsPermission permission) throws IOException { 226 return fs.mkdirs(f, permission); 227 } 228 229 /** 230 * The src file is on the local disk. Add it to FS at 231 * the given dst name. 232 * delSrc indicates if the source should be removed 233 */ 234 public void copyFromLocalFile(boolean delSrc, Path src, Path dst) 235 throws IOException { 236 fs.copyFromLocalFile(delSrc, src, dst); 237 } 238 239 /** 240 * The src files are on the local disk. Add it to FS at 241 * the given dst name. 242 * delSrc indicates if the source should be removed 243 */ 244 public void copyFromLocalFile(boolean delSrc, boolean overwrite, 245 Path[] srcs, Path dst) 246 throws IOException { 247 fs.copyFromLocalFile(delSrc, overwrite, srcs, dst); 248 } 249 250 /** 251 * The src file is on the local disk. Add it to FS at 252 * the given dst name. 253 * delSrc indicates if the source should be removed 254 */ 255 public void copyFromLocalFile(boolean delSrc, boolean overwrite, 256 Path src, Path dst) 257 throws IOException { 258 fs.copyFromLocalFile(delSrc, overwrite, src, dst); 259 } 260 261 /** 262 * The src file is under FS, and the dst is on the local disk. 263 * Copy it from FS control to the local dst name. 264 * delSrc indicates if the src will be removed or not. 265 */ 266 public void copyToLocalFile(boolean delSrc, Path src, Path dst) 267 throws IOException { 268 fs.copyToLocalFile(delSrc, src, dst); 269 } 270 271 /** 272 * Returns a local File that the user can write output to. The caller 273 * provides both the eventual FS target name and the local working 274 * file. If the FS is local, we write directly into the target. If 275 * the FS is remote, we write into the tmp local area. 276 */ 277 public Path startLocalOutput(Path fsOutputFile, Path tmpLocalFile) 278 throws IOException { 279 return fs.startLocalOutput(fsOutputFile, tmpLocalFile); 280 } 281 282 /** 283 * Called when we're all done writing to the target. A local FS will 284 * do nothing, because we've written to exactly the right place. A remote 285 * FS will copy the contents of tmpLocalFile to the correct target at 286 * fsOutputFile. 287 */ 288 public void completeLocalOutput(Path fsOutputFile, Path tmpLocalFile) 289 throws IOException { 290 fs.completeLocalOutput(fsOutputFile, tmpLocalFile); 291 } 292 293 /** Return the total size of all files in the filesystem.*/ 294 public long getUsed() throws IOException{ 295 return fs.getUsed(); 296 } 297 298 /** Return the number of bytes that large input files should be optimally 299 * be split into to minimize i/o time. */ 300 public long getDefaultBlockSize() { 301 return fs.getDefaultBlockSize(); 302 } 303 304 /** 305 * Get the default replication. 306 */ 307 public short getDefaultReplication() { 308 return fs.getDefaultReplication(); 309 } 310 311 /** 312 * Get file status. 313 */ 314 public FileStatus getFileStatus(Path f) throws IOException { 315 return fs.getFileStatus(f); 316 } 317 318 /** {@inheritDoc} */ 319 public FileChecksum getFileChecksum(Path f) throws IOException { 320 return fs.getFileChecksum(f); 321 } 322 323 /** {@inheritDoc} */ 324 public void setVerifyChecksum(boolean verifyChecksum) { 325 fs.setVerifyChecksum(verifyChecksum); 326 } 327 328 @Override 329 public Configuration getConf() { 330 return fs.getConf(); 331 } 332 333 @Override 334 public void close() throws IOException { 335 super.close(); 336 fs.close(); 337 } 338 339 /** {@inheritDoc} */ 340 @Override 341 public void setOwner(Path p, String username, String groupname 342 ) throws IOException { 343 fs.setOwner(p, username, groupname); 344 } 345 346 /** {@inheritDoc} */ 347 @Override 348 public void setTimes(Path p, long mtime, long atime 349 ) throws IOException { 350 fs.setTimes(p, mtime, atime); 351 } 352 353 /** {@inheritDoc} */ 354 @Override 355 public void setPermission(Path p, FsPermission permission 356 ) throws IOException { 357 fs.setPermission(p, permission); 358 } 359 360 @Override 361 protected FSDataOutputStream primitiveCreate(Path f, 362 FsPermission absolutePermission, EnumSet<CreateFlag> flag, 363 int bufferSize, short replication, long blockSize, Progressable progress, int bytesPerChecksum) 364 throws IOException { 365 return fs.primitiveCreate(f, absolutePermission, flag, 366 bufferSize, replication, blockSize, progress, bytesPerChecksum); 367 } 368 369 @Override 370 @SuppressWarnings("deprecation") 371 protected boolean primitiveMkdir(Path f, FsPermission abdolutePermission) 372 throws IOException { 373 return fs.primitiveMkdir(f, abdolutePermission); 374 } 375 376 @Override // FileSystem 377 public String getCanonicalServiceName() { 378 return fs.getCanonicalServiceName(); 379 } 380 381 @Override // FileSystem 382 @SuppressWarnings("deprecation") 383 public Token<?> getDelegationToken(String renewer) throws IOException { 384 return fs.getDelegationToken(renewer); 385 } 386 387 @Override // FileSystem 388 public List<Token<?>> getDelegationTokens(String renewer) throws IOException { 389 return fs.getDelegationTokens(renewer); 390 } 391 }