栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

基于springboot,hdfs的网盘系统(云服务器搭建的分布式架构上的hdfs,windows编译器IDEA,包含全开发流程,springboot部署在linux上,可公网访问)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

基于springboot,hdfs的网盘系统(云服务器搭建的分布式架构上的hdfs,windows编译器IDEA,包含全开发流程,springboot部署在linux上,可公网访问)

持续更新中。。。。

mainController
package cn.object.demo02.controller;

import cn.object.demo02.HDFS;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

//Rest模式
@RestController
@RequestMapping(value = "/hdfs")
public class mainController {

    @GetMapping
    public String getById(){
        System.out.println("Springboot is running");

        return "Springboot is running";
    }

    @RequestMapping(value = "/getRootDirectory",method = RequestMethod.GET)
    public List getDirectory() throws IOException {
        return HDFS.showRoot();

    }

    @RequestMapping(value = "/{str}",method = RequestMethod.DELETE)
    public String delete(@PathVariable String str){
        System.out.println(str);
        return str;
    }

//    @Request

}

Demo02Application
package cn.object.demo02;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.IOException;

@SpringBootApplication
public class Demo02Application {
	private static FileSystem hdfs;

	public static void main(String[] args) throws IOException {
		HDFS.init();

		SpringApplication.run(Demo02Application.class, args);
	}

}

HDFS
package cn.object.demo02;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

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


public class HDFS {
    public static FileSystem hdfs;
    public static List hdfsDirectories = new ArrayList<>();

    public static void init() throws IOException {
        System.out.println("-----------hdfs-starting---------");
        Configuration conf = new Configuration();

//        conf.set("fs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem");
        conf.set("fs.defaultFS","hdfs://centos01:9000");

        hdfs = FileSystem.get(conf);
        System.out.println("------------hdfs-running--------");
    }

//    public static void




    public static List showRoot() throws IOException {
        FileStatus fs = hdfs.getFileStatus(new Path("hdfs:/"));

        showDir(fs);

        return hdfsDirectories;
    }

    private static void showDir(FileStatus fs) throws IOException {

        Path path = fs.getPath();
        hdfsDirectories.add(path.toString());

        if(fs.isDirectory()){
            FileStatus[] f = hdfs.listStatus(path);
            if(f.length > 0)
                for(FileStatus file : f)
                    showDir(file);
        }
    }

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/762494.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号