Java 实现HDFS API接口 与获取Active NameNode Address

Java 实现HDFS API接口

 

接口:

 

import java.util.List;

/**
 * 缓存接口
 * 
 * <pre>
 * Modify Information:
 * Author       Date        Description
 * ============ =========== ============================
 * xiaoming     2017-05-08  Create this file
 * </pre>
 * 
 */
public interface HdfsFileSystem {

    /**
     * 创建一个文件,如果已存在则返回失败
     * 
     * @param dst HDFS文件目录地址
     * @param contents 要写入文件数据
     * @return 成功返回true 如果存在返回 false
     * @throws Exception
     */
    boolean createFile(String dst, String contents) throws Exception;

    /**
     * 上传本地文件
     * 
     * @param src 源文件
     * @param dst 目标文件地址
     * 
     * @return 成功返回true 如果存在返回 false
     * @throws Exception
     */
    boolean uploadFile(String src, String dst) throws Exception;

    /**
     * 重命名文件
     * 
     * @param oldName 原文件名
     * @param newName 命名后文件名
     * @return 成功返回true 失败返回false
     * @throws Exception
     */
    boolean rename(String oldName, String newName) throws Exception;

    /**
     * 新建文件夹
     * 
     * @param filePath 文件路径
     * @return 成功返回true 失败返回false
     * @throws Exception
     */
    boolean mkdir(String filePath) throws Exception;

    /**
     * 删除文件
     * 
     * @param filePath 文件路径
     * @return 成功返回true 失败返回false
     * @throws Exception
     */
    boolean delete(String path) throws Exception;

    /**
     * 下载文件
     * 
     * @param src hdfs文件路径
     * @param dst 下载到本地路径
     * @return 成功返回true 失败返回false
     * @throws Exception
     */
    boolean downloadFile(String src, String dst) throws Exception;

    /**
     * 判断文件是否存在
     * 
     * @param path 文件路径
     * @return 存在返回true 不存在返回false
     * @throws Exception
     */
    boolean isExist(String path) throws Exception;

    /**
     * 读取分布式文件系统文件,每行放入一个字符串,返回一个字符串数组
     * 
     * @param path 文件路径
     * @return 成功返回字符串数组 不成功返回null
     * @throws Exception
     */
    List<String> readFile(String path) throws Exception;

    /**
     * 从文件夹中读取文件
     * @param path
     * @return
     * @throws Exception
     */
    List<String> readFileFromDirectory(String path) throws Exception;

}

 

 

 

 

 

 

 

 

 

 

 

不多说,看代码:

 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apa
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wangxiaoming

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值