public class HdfsResource extends AbstractResource implements Serializable
Resource
implementation that connects to Apache Hadoop's HDFS
distributed file system.Modifier and Type | Field and Description |
---|---|
static String |
SCHEME_EMRFS |
static String |
SCHEME_FTP |
static String |
SCHEME_HDFS |
static String |
SCHEME_MAPRFS |
static String |
SCHEME_S3 |
static String |
SCHEME_SWIFT |
static String |
SYSTEM_PROPERTY_HADOOP_CONF_DIR_ENABLED |
Constructor and Description |
---|
HdfsResource(String url)
Creates a
HdfsResource |
HdfsResource(String hostname,
int port,
String filepath)
Creates a
HdfsResource using the "hdfs" scheme |
HdfsResource(String url,
String hadoopConfDir)
Creates a
HdfsResource |
HdfsResource(String scheme,
String hostname,
int port,
String filepath,
String hadoopConfDir)
Creates a
HdfsResource |
Modifier and Type | Method and Description |
---|---|
OutputStream |
append()
Opens up an
OutputStream to append to the resource. |
boolean |
equals(Object obj) |
String |
getFilepath() |
String |
getHadoopConfDir() |
org.apache.hadoop.conf.Configuration |
getHadoopConfiguration() |
org.apache.hadoop.fs.FileSystem |
getHadoopFileSystem() |
org.apache.hadoop.fs.Path |
getHadoopPath() |
String |
getHostname() |
long |
getLastModified()
Gets the last modified timestamp value (measured in milliseconds since
the epoch (00:00:00 GMT, January 1, 1970)) of the resource, if available.
|
String |
getName()
Gets the name of the resource, typically a filename or other identifying
string
|
int |
getPort() |
String |
getQualifiedPath()
Gets the qualified path of the resource, which typically includes slash
or backslash separated nodes in a hierarical tree structure.
|
String |
getScheme() |
long |
getSize()
Gets the size (in number of bytes) of this resource's data.
|
int |
hashCode() |
boolean |
isExists()
Determines if the resource referenced by this object exists or not.
|
boolean |
isReadOnly()
Determines if the file is read only, or if writes are also possible.
|
InputStream |
read()
Opens up an
InputStream to read from the resource. |
OutputStream |
write()
Opens up an
OutputStream to write to the resource. |
public static final String SYSTEM_PROPERTY_HADOOP_CONF_DIR_ENABLED
public static final String SCHEME_HDFS
public static final String SCHEME_SWIFT
public static final String SCHEME_EMRFS
public static final String SCHEME_MAPRFS
public static final String SCHEME_S3
public static final String SCHEME_FTP
public HdfsResource(String url)
HdfsResource
url
- a URL of the form: scheme://hostname:port/path/to/filepublic HdfsResource(String url, String hadoopConfDir)
HdfsResource
url
- a URL of the form: scheme://hostname:port/path/to/filehadoopConfDir
- the path of a directory containing the Hadoop and HDFS
configuration file(s).public HdfsResource(String hostname, int port, String filepath)
HdfsResource
using the "hdfs" schemehostname
- the HDFS (namenode) hostnameport
- the HDFS (namenode) port numberfilepath
- the path on HDFS to the file, starting with slash ('/')public HdfsResource(String scheme, String hostname, int port, String filepath, String hadoopConfDir)
HdfsResource
scheme
- the scheme to use (consider using SCHEME_HDFS
or any
of the other "SCHEME_" constants).hostname
- the HDFS (namenode) hostnameport
- the HDFS (namenode) port numberfilepath
- the path on HDFS to the file, starting with slash ('/')hadoopConfDir
- the path of a directory containing the Hadoop and HDFS
configuration file(s).public String getScheme()
public String getFilepath()
public String getHostname()
public int getPort()
public String getHadoopConfDir()
public String getName()
Resource
public String getQualifiedPath()
Resource
getQualifiedPath
in interface Resource
public boolean isReadOnly()
Resource
isReadOnly
in interface Resource
public boolean isExists()
Resource
public long getSize()
Resource
public long getLastModified()
Resource
getLastModified
in interface Resource
public OutputStream write() throws ResourceException
Resource
OutputStream
to write to the resource. Consumers of
this method are expected to invoke the OutputStream.close()
method manually.
If possible, the other write(...) method is preferred over this one,
since it guarantees proper closing of the resource's handles.write
in interface Resource
ResourceException
public OutputStream append() throws ResourceException
Resource
OutputStream
to append to the resource. Consumers of
this method are expected to invoke the OutputStream.close()
method manually.
If possible, the other append(...) method is preferred over this one,
since it guarantees proper closing of the resource's handles.append
in interface Resource
ResourceException
public InputStream read() throws ResourceException
Resource
InputStream
to read from the resource. Consumers of
this method are expected to invoke the InputStream.close()
method
manually.
If possible, the other read(...) methods are preferred over this one,
since they guarantee proper closing of the resource's handles.read
in interface Resource
ResourceException
public org.apache.hadoop.conf.Configuration getHadoopConfiguration()
public org.apache.hadoop.fs.FileSystem getHadoopFileSystem()
public org.apache.hadoop.fs.Path getHadoopPath()
Copyright © 2007–2017 The Apache Software Foundation. All rights reserved.