001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.vfs2.provider.hdfs; 018 019import java.util.Arrays; 020import java.util.Collection; 021import java.util.Collections; 022 023import org.apache.commons.vfs2.Capability; 024import org.apache.commons.vfs2.FileName; 025import org.apache.commons.vfs2.FileSystem; 026import org.apache.commons.vfs2.FileSystemConfigBuilder; 027import org.apache.commons.vfs2.FileSystemException; 028import org.apache.commons.vfs2.FileSystemOptions; 029import org.apache.commons.vfs2.provider.AbstractOriginatingFileProvider; 030import org.apache.commons.vfs2.provider.http.HttpFileNameParser; 031 032/** 033 * FileProvider for HDFS files. 034 * 035 * @since 2.1 036 */ 037public class HdfsFileProvider extends AbstractOriginatingFileProvider { 038 039 static final Collection<Capability> CAPABILITIES = Collections 040 .unmodifiableCollection(Arrays.asList(Capability.GET_TYPE, Capability.READ_CONTENT, 041 Capability.CREATE, 042 Capability.DELETE, 043 Capability.RENAME, 044 Capability.WRITE_CONTENT, 045 Capability.URI, Capability.GET_LAST_MODIFIED, 046 Capability.SET_LAST_MODIFIED_FILE, 047 Capability.ATTRIBUTES, Capability.RANDOM_ACCESS_READ, Capability.DIRECTORY_READ_CONTENT, 048 Capability.LIST_CHILDREN)); 049 050 /** 051 * Constructs a new HdfsFileProvider. 052 */ 053 public HdfsFileProvider() { 054 setFileNameParser(HttpFileNameParser.getInstance()); 055 } 056 057 /** 058 * Creates a new HdfsFileSystem instance. 059 * 060 * @param rootName Name of the root file. 061 * @param fileSystemOptions Configuration options for this instance. 062 * @throws FileSystemException if error occurred. 063 */ 064 @Override 065 protected FileSystem doCreateFileSystem(final FileName rootName, final FileSystemOptions fileSystemOptions) 066 throws FileSystemException { 067 return new HdfsFileSystem(rootName, fileSystemOptions); 068 } 069 070 /** 071 * Gets Capabilities of HdfsFileSystem. 072 * 073 * @return The capabilities (unmodifiable). 074 */ 075 @Override 076 public Collection<Capability> getCapabilities() { 077 return CAPABILITIES; 078 } 079 080 /** 081 * Gets the config builder. 082 * 083 * @return The config builder for HdfsFileSystems. 084 * @see org.apache.commons.vfs2.provider.AbstractFileProvider#getConfigBuilder() 085 */ 086 @Override 087 public FileSystemConfigBuilder getConfigBuilder() { 088 return HdfsFileSystemConfigBuilder.getInstance(); 089 } 090 091}