根据流程部署ID来获取流程定义图片

使用下面的一串代码的前提:已知流程部署ID,中间可能会由于空指针异常而报错,使用时需个人进行优化

需要注意的是下面的这一串代码中,各种服务是通过ActivitiRule而创建的,而ActivitiRule这个是在测试环境下面才能使用的类,开发时可以使用自动注解来创建Activiti6的7大服务接口。

/**
 * 根据流程部署ID获取流程部署图片文件输入流,并将其写到指定的文件中
 */
public void viewImage() throws Exception{

    String deploymentId="流程部署ID";
    RepositoryService repositoryService=activitiRule.getRepositoryService();
    List<String> names=repositoryService.getDeploymentResourceNames(deploymentId);
    String imageName=null;
    for(String name:names){
       if(name.indexOf(".png")>=0){
            imageName=name;
       }
    }
    InputStream  in=null;
    File f=new File("d:/"+imageName);
    if(imageName!=null){
       in=repositoryService.getResourceAsStream(deploymentId,imageName);
    }
    OutputStream outputStream = new FileOutputStream(f);
    byte[] bytes = new byte[1024];
    int rc = 0;
    while ((rc = in.read(bytes, 0, 100)) > 0) {
        outputStream.write(bytes, 0, rc);
    }
    in.close();
    outputStream.close();
}

 将文件输入流写入到输出流中,在页面中以Image 标签的src属性接收就可以获取该输出流作为一个图片进行展示。 

OutputStream outputStream= response.getOutputStream();
for(int b=-1;(b=in.read())!=-1;){
    outputStream.write(b);
}
in.close();
outputStream.close();
<body>
    <image src="/demo/get"/>
</body>

 

  SpringBoot项目中,获取流程定义图并将其以图片形式在页面中进行展示

/**
 * 将输入流回显到输出流中
 */
@RequestMapping("/get")
public void getData(HttpServletRequest request, HttpServletResponse response) throws Exception{
        String deploymentId="7501";
        List<String> names=repositoryService.getDeploymentResourceNames(deploymentId);
        String imageName=null;
        for(String name:names){
            if(name.indexOf(".png")>=0){
                imageName=name;
            }
        }
        InputStream in=null;
        File f=new File("d:/"+imageName);
        if(imageName!=null){
            in=repositoryService.getResourceAsStream(deploymentId,imageName);
        }

        OutputStream outputStream= response.getOutputStream();
        for(int b=-1;(b=in.read())!=-1;){
            outputStream.write(b);
        }
        in.close();
        outputStream.close();
    }

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值