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