比如我们要解压这个url下 http://域名:端口号/文件夹/datai-cli-0.0.2.tgz,datai-cli-0.0.2.tgz的tgz文件里的某个文件,然后在上传,废话不多说了,上代码了
抓取url里的tgz文件,解压成inpitStream
public InputStream downLoadFromUrl(String urlStr) throws IOException{
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
//设置超时间为3秒
conn.setConnectTimeout(3*1000);
//防止屏蔽程序抓取而返回403错误
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
//得到输入流
InputStream inputStream = conn.getInputStream();
return inputStream;
}
List<File> file = unTar(new GzipCompressorInputStream(inputStream),destDir);
解压tgz文件,找到特定文件 返回fiel集合,上传
private List<File> unTar(InputStream inputStream, String destDir) throws Exception {
TarArchiveInput