Class HdfsFileSystem
java.lang.Object
com.northconcepts.datapipeline.core.DataObject
com.northconcepts.datapipeline.core.Endpoint
com.northconcepts.datapipeline.internal.lang.FileSystem
com.northconcepts.datapipeline.filesystem.hdfs.HdfsFileSystem
Class for accessing the Hadoop Distributed File System.
-
Field Summary
Fields inherited from class com.northconcepts.datapipeline.core.Endpoint
BUFFER_SIZE, captureElapsedTime, DEFAULT_READ_BUFFER_SIZEFields inherited from class com.northconcepts.datapipeline.core.DataObject
id, log, name, TIMESTAMP_FORMAT -
Constructor Summary
ConstructorsConstructorDescriptionHdfsFileSystem(String hdfsUri) Enables access to Hadoop Distributed File System with the user name supplied through aCredentialsResolver(seesetCredentialsResolver(CredentialsResolver)).
URI Example: "hdfs://localhost:9000"HdfsFileSystem(String hdfsUri, String userName) Enables access to Hadoop Distributed File System.
URI Example: "hdfs://localhost:9000" -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the HDFS connection.List<FileStatus> listFolder(String folderName) Returns the contents of the folder.List<FileStatus> Returns aListof all HDFS files and folders under the root folder.voidopen()Opens a connection to the Hadoop Distributed File System.Reads the specified file in the HDFS root folder.Reads the file in the specified HDFS folder.setCredentialsResolver(CredentialsResolver credentialsResolver) Sets the resolver supplying this file system's user name (Credentials.USERNAME) — resolved on eachopen(), never at construction, so rotated values are picked up on the next connection.Writes the file to the HDFS File System.Writes the file to the HDFS File System.Methods inherited from class com.northconcepts.datapipeline.internal.lang.FileSystem
credentialValue, getCredentialsResolver, getCurrentCredentials, refreshCredentials, resolveCredentialsMethods inherited from class com.northconcepts.datapipeline.core.Endpoint
addElapsedtime, addExceptionProperties, assertClosed, assertNotOpened, assertOpened, finalize, getClosedOn, getDescription, getElapsedTime, getElapsedTimeAsString, getNestedEndpoint, getOpenedOn, getOpenElapsedTime, getOpenElapsedTimeAsString, getRootEndpoint, getSelfTime, getSelfTimeAsString, getState, isCaptureElapsedTime, isClosed, isOpen, setCaptureElapsedTime, setDescription, toString
-
Constructor Details
-
HdfsFileSystem
Enables access to Hadoop Distributed File System.
URI Example: "hdfs://localhost:9000"- Parameters:
hdfsUri- the URI of the Hadoop Distributed File System
-
HdfsFileSystem
Enables access to Hadoop Distributed File System with the user name supplied through aCredentialsResolver(seesetCredentialsResolver(CredentialsResolver)).
URI Example: "hdfs://localhost:9000"- Parameters:
hdfsUri- the URI of the Hadoop Distributed File System
-
-
Method Details
-
setCredentialsResolver
Sets the resolver supplying this file system's user name (Credentials.USERNAME) — resolved on eachopen(), never at construction, so rotated values are picked up on the next connection. When the resolved credentials don't contain a user name, the constructor-supplied value is used.- Overrides:
setCredentialsResolverin classFileSystem
-
open
Opens a connection to the Hadoop Distributed File System.- Overrides:
openin classEndpoint- Throws:
DataException
-
close
Closes the HDFS connection.- Overrides:
closein classFileSystem- Throws:
DataException
-
readFile
Reads the file in the specified HDFS folder. To specify a nested folder use "/" as separator.
Example:
- readFile("folderOne", "filename") - reads the file in folderOne
- readFile("folderOne/folderTwo", "filename") - reads the file in folderTwo which is under folderOne
- Parameters:
folderName- the name of the folderfileName- the file name to read.- Returns:
- an
InputStream - Throws:
Throwable
-
readFile
Reads the specified file in the HDFS root folder.- Parameters:
fileName- the file name to read.- Returns:
- an
InputStream - Throws:
Throwable
-
listFolder
Returns the contents of the folder. To specify a nested folder use "/" as separator.
Example:
- listFolder("folderOne") - reads the contents of folderOne which is under the root folder
- listFolder("folderOne/folderTwo") - reads the contents of folderTwo which is under folderOne
- Throws:
Throwable
-
listRootFolder
Returns aListof all HDFS files and folders under the root folder.- Returns:
- the contents as a
List - Throws:
Throwable
-
writeFile
Writes the file to the HDFS File System. If the file exists, it is overwritten.- Parameters:
fileName- the name of the file- Returns:
- an
OutputStreamfor writing - Throws:
Throwable
-
writeFile
Writes the file to the HDFS File System. If the file exists, it is overwritten. To specify a nested folder use "/" as separator.
Example:
- writeFile("folderOne", "filename") - writes the file to folderOne
- writeFile("folderOne/folderTwo", "filename") - writes the file to folderTwo which is under folderOne
- Parameters:
folderName- the destination folderfileName- the name of the file- Returns:
- an
OutputStreamfor writing - Throws:
Throwable
-