hdfs路径 linux路径,四、记录1----获取hdfs上FileSystem的方法 记录2:正则匹配路径:linux、hdfs...

/*** 经过正则获取该目录下知足条件的全部目录

*@paramluceneFilePathRegular 正则目录,如/user/solrindex/正则表达式

*@return知足正则表达式的目录集合 list*/

public static ListfetchDirByRegularLinux(String luceneFilePathRegular){

List list=new ArrayList<>();//分割获取主目录

int len= luceneFilePathRegular.lastIndexOf(EtlConstants.LINUX_ROUTE_SEGMENT)+1;

String mainDir=luceneFilePathRegular.substring(0, len);

String regular=luceneFilePathRegular.substring(len,luceneFilePathRegular.length());

File dir=newFile(mainDir);if(dir.exists() &&dir.isDirectory()){

File [] arr=dir.listFiles();for(File file : arr) {if (file.exists() &&file.isDirectory()) {

String fileName=file.getName();if(matchStr(fileName, regular)) {

list.add(file.getAbsolutePath()+SolrUtil.INDEX_DIR_SUFFIX);

}

}

}

}if(list.size()>0){

LOGGER.info("经过正则匹配到的Solr目录有:");for(String s : list) {

LOGGER.info(s);

}

}else{

LOGGER.error("路径{}下,不存在知足正则:{}条件的目录", dir, regular);

}returnlist;

}/*** 经过正则获取该目录下知足条件的全部目录

*@paramluceneFilePathRegular 正则目录,如hdfs:/user/solrindex/正则表达式

*@paramnameNodeConfigPath //获取name配置信息目录

*@return知足正则表达式的目录集合 list*/

public static ListfetchDirByRegularHdfs(String luceneFilePathRegular,String nameNodeConfigPath){

List list=new ArrayList<>();

FileSystem fs=HdfsUtil.getFileSystem(nameNodeConfigPath);

String prefixHdfs=luceneFilePathRegular.split(":")[0];

String hdfsPath=luceneFilePathRegular.split(":")[1];//分割获取主目录

int len= hdfsPath.lastIndexOf(EtlConstants.LINUX_ROUTE_SEGMENT)+1;

String mainDir=hdfsPath.substring(0, len);

String regular=hdfsPath.substring(len, hdfsPath.length());try{

FileStatus[] fileStatuses= fs.globStatus(new Path(mainDir+"*"));for(FileStatus fileStatus : fileStatuses){if (fileStatus.isDirectory() &&matchStr(fileStatus.getPath().getName(), regular)) {

list.add(prefixHdfs+":"+mainDir+fileStatus.getPath().getName()+SolrUtil.INDEX_DIR_SUFFIX);

}

}

}catch(IOException e) {

LOGGER.error("获取hdfs目录信息异常,路径:{},异常信息:{}",luceneFilePathRegular,e.getMessage());

e.printStackTrace();

}if(list.size()>0){

LOGGER.info("经过正则匹配到的Solr目录有:");for(String s : list) {

LOGGER.info(s);

}

}else{

LOGGER.error("路径{}下,不存在知足正则:{}条件的目录", luceneFilePathRegular, regular);

}returnlist;

}/*** @Method Description:按正则表示是匹配字符串

*@paramstr

*@paramregular

*@return*@author: libingjie*/

public staticBoolean matchStr(String str, String regular) {

Pattern pattern=Pattern.compile(regular);

Matcher matcher=pattern.matcher(str);returnmatcher.matches();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值