package com.tzld.piaoquan.recommend.model.produce.service;

import lombok.extern.slf4j.Slf4j;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.IOException;
import java.io.Serializable;

/**
 * @author dyp
 */
@Slf4j
public class HDFSService implements Serializable {
    private FileSystem fSystem;

    public HDFSService() throws IOException {
        fSystem = FileSystem.get(new Configuration());
    }

    public boolean createDir(String dir) throws IOException {
        Path dirPath = new Path(dir);
        if (!fSystem.exists(dirPath)) {
            fSystem.mkdirs(dirPath);
        }
        return true;
    }

    public boolean delete(String path) throws IOException {
        return fSystem.delete(new Path(path));
    }

}
