View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.vfs2.provider.hdfs;
18  
19  import java.util.Arrays;
20  import java.util.Collection;
21  import java.util.Collections;
22  
23  import org.apache.commons.vfs2.Capability;
24  import org.apache.commons.vfs2.FileName;
25  import org.apache.commons.vfs2.FileSystem;
26  import org.apache.commons.vfs2.FileSystemConfigBuilder;
27  import org.apache.commons.vfs2.FileSystemException;
28  import org.apache.commons.vfs2.FileSystemOptions;
29  import org.apache.commons.vfs2.provider.AbstractOriginatingFileProvider;
30  import org.apache.commons.vfs2.provider.http.HttpFileNameParser;
31  
32  /**
33   * FileProvider for HDFS files.
34   *
35   * @since 2.1
36   */
37  public class HdfsFileProvider extends AbstractOriginatingFileProvider {
38  
39      static final Collection<Capability> CAPABILITIES = Collections
40              .unmodifiableCollection(Arrays.asList(Capability.GET_TYPE, Capability.READ_CONTENT,
41                      Capability.CREATE,
42                      Capability.DELETE,
43                      Capability.RENAME,
44                      Capability.WRITE_CONTENT,
45                      Capability.URI, Capability.GET_LAST_MODIFIED,
46                      Capability.SET_LAST_MODIFIED_FILE,
47                      Capability.ATTRIBUTES, Capability.RANDOM_ACCESS_READ, Capability.DIRECTORY_READ_CONTENT,
48                      Capability.LIST_CHILDREN));
49  
50      /**
51       * Constructs a new HdfsFileProvider.
52       */
53      public HdfsFileProvider() {
54          this.setFileNameParser(HttpFileNameParser.getInstance());
55      }
56  
57      /**
58       * Creates a new HdfsFileSystem instance.
59       *
60       * @param rootName Name of the root file.
61       * @param fileSystemOptions Configuration options for this instance.
62       * @throws FileSystemException if error occurred.
63       */
64      @Override
65      protected FileSystem doCreateFileSystem(final FileName rootName, final FileSystemOptions fileSystemOptions)
66              throws FileSystemException {
67          return new HdfsFileSystem(rootName, fileSystemOptions);
68      }
69  
70      /**
71       * Gets Capabilities of HdfsFileSystem.
72       *
73       * @return The capabilities (unmodifiable).
74       */
75      @Override
76      public Collection<Capability> getCapabilities() {
77          return CAPABILITIES;
78      }
79  
80      /**
81       * Gets the config builder.
82       *
83       * @return The config builder for HdfsFileSystems.
84       * @see org.apache.commons.vfs2.provider.AbstractFileProvider#getConfigBuilder()
85       */
86      @Override
87      public FileSystemConfigBuilder getConfigBuilder() {
88          return HdfsFileSystemConfigBuilder.getInstance();
89      }
90  
91  }