记录瞬间

import org.jacoco.core.data.ExecutionDataWriter;
import org.jacoco.core.runtime.RemoteControlReader;
import org.jacoco.core.runtime.RemoteControlWriter; import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.util.List; /**
* This example connects to a coverage agent that run in output mode
* <code>tcpserver</code> and requests execution data. The collected data is
* dumped to a local file.
*/
public class ExecutionDataClient { public String downLoadDump(String path, List<String> ipPort) {
int flag = 0;
String getDirName = getDirNum(path);
for (String getIPPost : ipPort){
String dirName = getDirName + "/" + getIPPost.replace(":", "_") + "_jacoco.exec";
String ip = getIPPost.split(":")[0];
int port = Integer.parseInt(getIPPost.split(":")[1]);
try {
final FileOutputStream localFile = new FileOutputStream(dirName);
final ExecutionDataWriter localWriter = new ExecutionDataWriter(
localFile);
// Open a socket to the coverage agent:
final Socket socket = new Socket(InetAddress.getByName(ip), port);
final RemoteControlWriter writer = new RemoteControlWriter(
socket.getOutputStream());
final RemoteControlReader reader = new RemoteControlReader(
socket.getInputStream());
reader.setSessionInfoVisitor(localWriter);
reader.setExecutionDataVisitor(localWriter); // Send a dump command and read the response:
writer.visitDumpCommand(true, false);
if (!reader.read()) {
throw new IOException("Socket closed unexpectedly.");
} socket.close();
localFile.close();
System.out.println("Download file success....");
System.out.println("File path is : " + dirName);
flag ++;
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
if (flag != 0) {
return getDirName;
} else {
return "path";
}
} /**
*
* @param path
* @return
*/
private String getDirNum(String path){
File file = null;
String newPath = "";
for (int i = 0 ; ; i++) {
newPath = path + "/" + i;
file = new File(newPath);
System.out.println("new path = "+newPath);
if (! file.isDirectory()) {
System.out.println(newPath);
file.mkdirs();
break;
}
}
return newPath;
}
}

记录通过Jacoco 客户端,获取远端服务器上的dump文件。

java操作JacocClient下载dump文件的更多相关文章

  1. java操作Jacoco合并dump文件

    记录瞬间 import org.apache.maven.plugin.MojoExecutionException; import org.jacoco.core.tools.ExecFileLoa ...

  2. java操作Excel、PDF文件

    java操作Excel.PDF文件 分享者:Vashon 分享来源:CSDN博客 下面这些是在开发中用到的一些东西,有的代码贴的不是完整的,只是贴出了关于操作EXCEL的代码: jxl是一个*国人写的 ...

  3. Java读取并下载网络文件

      CreateTime--2017年8月21日10:11:07 Author:Marydon import java.io.ByteArrayOutputStream; import java.io ...

  4. java操作office和pdf文件java读取word,excel和pdf文档内容

    在平常应用程序中,对office和pdf文档进行读取数据是比较常见的功能,尤其在很多web应用程序中.所以今天我们就简单来看一下Java对word.excel.pdf文件的读取.本篇博客只是讲解简单应 ...

  5. JAVA代码实现下载单个文件,和下载打包文件

    //下载单个文件调用方法 /**     * response     * imgPath 下载图片地址    * fileName 保存下载文件名称    * @date 2015年4月14日 下午 ...

  6. 【转】Java生成plist下载ipa文件

    我们在上传ipa想要安装的时候必须要通过plist文件去下载,并且还要遵循 itms-services协议. 意思就是,第一步我们要生成一个plist文件, 第二步生成一个html文件,用来指向pli ...

  7. java操作FTP,实现文件上传下载删除操作

    上传文件到FTP服务器: /** * Description: 向FTP服务器上传文件 * @param url FTP服务器hostname * @param port FTP服务器端口,如果默认端 ...

  8. java操作office和pdf文件页面列表导出cvs,excel、pdf报表.

    在平常的开发中我们常常遇到不仅仅只是导出excel报表的情况.有时候也需要导出pdf或者CSV报 表.其实原理都差不多.刚开始本来不打算也这篇博客介绍这个的.感觉这篇博客和前面的博客有点雷同.原理基本 ...

  9. java web 怎么下载大文件(上百M)

    Java代码   ; ]; , )) != -) { , bytesRead); 13.               } 14.               toClient.write(buffer ...

随机推荐

  1. There is no getter for property named 'XXX' in 'class java.lang.String'解决方法

    <select id="ProjectHomePage" parameterType="string" resultType="java.uti ...

  2. golang map 读写锁与深度拷贝的坑

    0X01 golang中,map(字典)无法并发读写 简单来说,新建万条线程对同一个map又读又写,会报错. 为此,最好加锁,其实性能影响并不明显. type taskCache struct{ sy ...

  3. Spark环境搭建(三)-----------yarn环境搭建及测试作业提交

    配置好HDFS之后,接下来配置单节点的yarn环境 1,修改配置文件 文件 : /root/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop/yarn-site-xml 插入 ...

  4. Django 启动源码

    handler = self.get_handler(*args, **options) run(self.addr, int(self.port), handler,ipv6=self.use_ip ...

  5. docker备份mongodb数据,导入导出

    场景:服务器要升级,之前在linux部署的mongodb没有用docker,升级后,mongodb要用docker部署,并将原有的mongodb数据导入到docker部署的mongodb中. 1.在l ...

  6. Java课程课后作业之19学期之第一周博客作业

    作为一个大二的学生,自己已经不小了,没有大一那个时候的无忧无虑的可以放纵的时光,只剩下一年,我就该做出我人生的下一个重大决定了,这一次真的是我一个人的决定,从小到大,父母为我做过很多的决定,即使在小的 ...

  7. oralce 将浮点型字段,转为指定精度 并且四舍五入

    使用 Round()  函数,该函数有两个参数,第一个参数: 将要转换的字段,第二个参数:保留的小数点位数 1 代表保留1位 2 代表保留2位 例子: SELECT round(123.446,1) ...

  8. photoshop cc 2017安装

    https://jingyan.baidu.com/article/8ebacdf0700c0c49f65cd500.html

  9. 微信小程序计算经纬距离

    微信小程序计算经纬距离 微信小程序计算两点间的距离 getDistance: function (lat1, lng1, lat2, lng2) { lat1 = lat1 || 0; lng1 = ...

  10. F#周报2019年第16期

    新闻 Ionide试验版本 FSharp路线图介绍 Blazor官方预览 .NET Framework 4.8发布 .NET Core 3 Preview 4发布 需要来自FSharp.Data.Sq ...