Groovy - 从http URL进行文件处理 [英] Groovy - File handling from http URL

查看:912
本文介绍了Groovy - 从http URL进行文件处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的其中一台服务器中的文件可以通过http访问。所以,当我们调出一个类似于下面的url时,我们得到了该位置的文件/目录列表:

  http :// mytestserver / files / 

从这个列表中,我只需要选择那些匹配正则表达式格式。



如果这是磁盘中的一个位置,我可以使用eachFileMatch方法并筛选我需要的文件。



有人可以帮助我如何从http URL做到这一点吗?

解决方案

@tim_yates的另一个版本使用 JSoup

<$
$ or $ $ $
$ (doc,files,dirs)= [Jsoup.connect('http://central.maven.org/maven2/com/bloidonia/groovy-stream/').get(),[],[]]
doc.select(pre> a)。each {href - >
def filename = href.text()
filename.endsWith(/)?dirs.add(filename):files.add(filename)
}
println DIRECTORIES:
$ {dirs.join('\ n')}
文件:
$ {files.join('\\\
')}


The files in one of our servers can be accessed via http. So, when we bring up a url similar to the following, we get a list of files/directories in that location:

http://mytestserver/files/

From this list, I need to select only those files that match a regex format.

If this was a location in the disk, I can make use of the method eachFileMatch and filter the files that I need.

Can someone help me how we can do this from a http URL?

解决方案

Another version of @tim_yates Answer using JSoup

@Grab(group='org.jsoup', module='jsoup', version='1.7.3')
import org.jsoup.Jsoup
def (doc,files, dirs) = [Jsoup.connect('http://central.maven.org/maven2/com/bloidonia/groovy-stream/').get(),[],[]]
doc.select("pre > a").each{href ->
    def filename = href.text()
    filename.endsWith("/")?dirs.add(filename):files.add(filename)
}
println """DIRECTORIES : 
${dirs.join('\n')}
FILES : 
${files.join('\n')}
"""

这篇关于Groovy - 从http URL进行文件处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆