hadoop HDFS 流式传输及JAVA API实现代码
首先科普一下什么是流式传输:式传输定义很广泛,主要指通过网络传送流媒体(如视频、音频)的技术总称。其特定含义为通过Internet 将影视节目传送到PC机。实现流式传输有两种方法:实时流式传输(Realtime streaming)和顺序流式传输(progressive streaming)。(来源百度百科)
例如我们看视频,迅雷先下后看的方法叫下载,b站一边缓冲一边播放的方式使流式传输。
流式数据,特点就是,像流水一样,不是一次过来而是一点一点“流”过来。而你处理流式数据也是一点一点处理。如果是全部收到数据以后再处理,那么延迟会很大,而且在很多场合会消耗大量内存。
那么使用JAVA API删除和上传文件的方法部分代码
/**
* 文件的删除
*
* @throws Exception
*/
public static void deleteFile() throws Exception{
FileSystem hdfs = getFileSystem();
Path delef = new Path("install2.log");
boolean isDeleted=hdfs.delete(delef,false);
System.out.println("是否删除?"+ isDeleted);
}
/**作业 文件的上传
* @throws Exception
*/
public static void uploadFile() throws Exception{
FileSystem hdfs = getFileSystem();
Path src = new Path("/root/install.log");
Path dst = new Path("/");
FileStatus files[] = hdfs.listStatus(dst);
for (FileStatus file : files){
System.out.println(file.getPath());
}
System.out.println("---------------------------------");
hdfs.copyFromLocalFile(src,dst);
files = hdfs.listStatus(dst);
for (FileStatus file :files){
System.out.println(file.getPath());
}
}
public static void main(String[] args) throws Exception {
deleteFile();
uploadFile();
}
流式上传文件:
https://blog.csdn.net/l1394049664/article/details/82533286?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-6.control&dist_request_id=1328696.287.16166642218085569&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-6.control
可能我理解的不是很正确,欢迎批评指正