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.unmodifiableCollection(Arrays
40              .asList(new Capability[]
41              {
42                      Capability.GET_TYPE,
43                      Capability.READ_CONTENT,
44                      Capability.URI,
45                      Capability.GET_LAST_MODIFIED,
46                      Capability.ATTRIBUTES,
47                      Capability.RANDOM_ACCESS_READ,
48                      Capability.DIRECTORY_READ_CONTENT,
49                      Capability.LIST_CHILDREN }));
50  
51      /**
52       * Constructs a new HdfsFileProvider.
53       */
54      public HdfsFileProvider()
55      {
56          super();
57          this.setFileNameParser(HttpFileNameParser.getInstance());
58      }
59  
60      /**
61       * Create a new HdfsFileSystem instance.
62       * @param rootName Name of the root file.
63       * @param fileSystemOptions Configuration options for this instance.
64       * @throws FileSystemException if error occurred.
65       */
66      @Override
67      protected FileSystem doCreateFileSystem(final FileName rootName, final FileSystemOptions fileSystemOptions)
68              throws FileSystemException
69      {
70          return new HdfsFileSystem(rootName, fileSystemOptions);
71      }
72  
73      /**
74       * Get Capabilities of HdfsFileSystem.
75       * @return The capabilities (unmodifiable).
76       */
77      @Override
78      public Collection<Capability> getCapabilities()
79      {
80          return CAPABILITIES;
81      }
82  
83      /**
84       * Return config builder.
85       * @return A config builder for HdfsFileSystems.
86       * @see org.apache.commons.vfs2.provider.AbstractFileProvider#getConfigBuilder()
87       */
88      @Override
89      public FileSystemConfigBuilder getConfigBuilder()
90      {
91          return HdfsFileSystemConfigBuilder.getInstance();
92      }
93  
94  }