码迷,mamicode.com
首页 > 其他好文 > 详细

HDFS 断点续传,写文件功能

时间:2015-12-09 13:41:15      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:

实际上这是个 HDFS 的工具类部分代码。 首先

public static Configuration configuration = null;
public static FileSystem fileSystem = null;

static {
try {
if (null == configuration) {
configuration = new Configuration();
}
if (null == fileSystem) {
fileSystem = FileSystem.get(URI.create(RockyConstants.HDFS_PATH), configuration);
}
}
catch (IOException e) {
e.printStackTrace()
;
}
}

/**
* 整文件存入 HDFS
*
* @throws Exception
*/
public static boolean putHDFS(String filePath, byte[] info) {
try {
FSDataOutputStream writer = fileSystem.create(
new Path(filePath), true);
writer.write(info);
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}

/**
* 断点续传存入
* @throws IOException
*/
public static void continueUpload(String targetPath, byte[] info) throws IOException{
Path fsPath = new Path(targetPath);
// 第一次
if (!fileSystem.exists(fsPath)) {
putHDFS(targetPath,info);
} else {
// 续传
FSDataOutputStream writer = fileSystem.append(fsPath);
writer.write(info);
writer.flush();
writer.close();
}
}






HDFS 断点续传,写文件功能

标签:

原文地址:http://www.cnblogs.com/rocky24/p/5032385.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!