public class HdfsResourceLoader
extends org.springframework.core.io.DefaultResourceLoader
implements org.springframework.core.io.support.ResourcePatternResolver, org.springframework.core.PriorityOrdered, java.io.Closeable, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean
Constructor and Description |
---|
HdfsResourceLoader(org.apache.hadoop.conf.Configuration config)
Constructs a new
HdfsResourceLoader instance. |
HdfsResourceLoader(org.apache.hadoop.conf.Configuration config,
java.net.URI uri)
Constructs a new
HdfsResourceLoader instance. |
HdfsResourceLoader(org.apache.hadoop.conf.Configuration config,
java.net.URI uri,
java.lang.String user)
Constructs a new
HdfsResourceLoader instance. |
HdfsResourceLoader(org.apache.hadoop.fs.FileSystem fs)
Constructs a new
HdfsResourceLoader instance. |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
void |
close() |
void |
destroy() |
protected java.lang.String |
determineRootDir(java.lang.String location)
Determine the root directory for the given location.
|
protected java.util.Set<org.springframework.core.io.Resource> |
doFindMatchingFileSystemResources(org.apache.hadoop.fs.Path rootDir,
java.lang.String subPattern)
Find all resources in the file system that match the given location pattern
via the Ant-style PathMatcher.
|
protected java.util.Set<org.springframework.core.io.Resource> |
doFindPathMatchingFileResources(org.springframework.core.io.Resource rootDirResource,
java.lang.String subPattern)
Find all resources in the hdfs file system that match the given location pattern
via the Ant-style PathMatcher.
|
protected void |
doRetrieveMatchingFiles(java.lang.String fullPattern,
org.apache.hadoop.fs.Path dir,
java.util.Set<org.apache.hadoop.fs.Path> result)
Recursively retrieve files that match the given pattern,
adding them to the given result list.
|
protected org.springframework.core.io.Resource[] |
findPathMatchingResources(java.lang.String locationPattern)
Find all resources that match the given location pattern via the
Ant-style PathMatcher.
|
java.lang.ClassLoader |
getClassLoader() |
org.apache.hadoop.fs.FileSystem |
getFileSystem()
Returns the Hadoop file system used by this resource loader.
|
int |
getOrder() |
org.springframework.core.io.Resource |
getResource(java.lang.String location) |
protected org.springframework.core.io.Resource |
getResourceByPath(java.lang.String path) |
org.springframework.core.io.Resource[] |
getResources(java.lang.String locationPattern) |
protected java.util.Set<org.apache.hadoop.fs.Path> |
retrieveMatchingFiles(org.apache.hadoop.fs.Path rootDir,
java.lang.String pattern)
Retrieve files that match the given path pattern,
checking the given directory and its subdirectories.
|
void |
setHandleNoprefix(boolean handleNoprefix)
Sets the handle noprefix.
|
void |
setResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver resourcePatternResolver)
Sets the resource pattern resolver.
|
void |
setUseCodecs(boolean useCodecs)
Indicates whether to use (or not) the codecs found inside the Hadoop
configuration.
|
public HdfsResourceLoader(org.apache.hadoop.conf.Configuration config)
HdfsResourceLoader
instance.config
- Hadoop configuration to use.public HdfsResourceLoader(org.apache.hadoop.conf.Configuration config, java.net.URI uri, java.lang.String user)
HdfsResourceLoader
instance.config
- Hadoop configuration to use.uri
- Hadoop file system URI.user
- Hadoop user for accessing the file system.public HdfsResourceLoader(org.apache.hadoop.conf.Configuration config, java.net.URI uri)
HdfsResourceLoader
instance.config
- Hadoop configuration to use.uri
- Hadoop file system URI.public HdfsResourceLoader(org.apache.hadoop.fs.FileSystem fs)
HdfsResourceLoader
instance.fs
- Hadoop file system to use.protected org.springframework.core.io.Resource getResourceByPath(java.lang.String path)
getResourceByPath
in class org.springframework.core.io.DefaultResourceLoader
public org.springframework.core.io.Resource getResource(java.lang.String location)
getResource
in interface org.springframework.core.io.ResourceLoader
getResource
in class org.springframework.core.io.DefaultResourceLoader
public org.springframework.core.io.Resource[] getResources(java.lang.String locationPattern) throws java.io.IOException
getResources
in interface org.springframework.core.io.support.ResourcePatternResolver
java.io.IOException
public int getOrder()
getOrder
in interface org.springframework.core.Ordered
public void destroy() throws java.io.IOException
destroy
in interface org.springframework.beans.factory.DisposableBean
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
public void afterPropertiesSet() throws java.lang.Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
java.lang.Exception
public java.lang.ClassLoader getClassLoader()
getClassLoader
in interface org.springframework.core.io.ResourceLoader
getClassLoader
in class org.springframework.core.io.DefaultResourceLoader
public void setHandleNoprefix(boolean handleNoprefix)
handleNoprefix
- the new handle noprefixpublic org.apache.hadoop.fs.FileSystem getFileSystem()
public void setUseCodecs(boolean useCodecs)
useCodecs
- whether to use any codecs defined in the Hadoop configurationpublic void setResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver resourcePatternResolver)
resourcePatternResolver
- the new resource pattern resolverprotected org.springframework.core.io.Resource[] findPathMatchingResources(java.lang.String locationPattern) throws java.io.IOException
locationPattern
- the location pattern to matchjava.io.IOException
- in case of I/O errorsprotected java.util.Set<org.springframework.core.io.Resource> doFindPathMatchingFileResources(org.springframework.core.io.Resource rootDirResource, java.lang.String subPattern) throws java.io.IOException
rootDirResource
- the root directory as ResourcesubPattern
- the sub pattern to match (below the root directory)java.io.IOException
- in case of I/O errorsprotected java.util.Set<org.springframework.core.io.Resource> doFindMatchingFileSystemResources(org.apache.hadoop.fs.Path rootDir, java.lang.String subPattern) throws java.io.IOException
rootDir
- the root directory in the file systemsubPattern
- the sub pattern to match (below the root directory)java.io.IOException
- in case of I/O errorsPathMatcher
protected java.util.Set<org.apache.hadoop.fs.Path> retrieveMatchingFiles(org.apache.hadoop.fs.Path rootDir, java.lang.String pattern) throws java.io.IOException
rootDir
- the directory to start frompattern
- the pattern to match against, * relative to the root directoryjava.io.IOException
- if directory contents could not be retrievedprotected void doRetrieveMatchingFiles(java.lang.String fullPattern, org.apache.hadoop.fs.Path dir, java.util.Set<org.apache.hadoop.fs.Path> result) throws java.io.IOException
fullPattern
- the pattern to match against, with prepended root directory pathdir
- the current directoryresult
- the Set of matching File instances to add tojava.io.IOException
- if directory contents could not be retrievedprotected java.lang.String determineRootDir(java.lang.String location)
Used for determining the starting point for file matching,
resolving the root directory location and passing it
into doFindPathMatchingPathResources
, with the
remainder of the location as pattern.
Will return "/dir/" for the pattern "/dir/*.xml", for example.
location
- the location to check