/*从数据库中读出BLOB对象
* @param outfile 输出的数据文件
*/
@Test
public void blobRead() throws Exception
{
ProcessEngine processEngine = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("act.conf.xml").buildProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
// 从仓库中找需要展示的文件
List<String> names =repositoryService.getDeploymentResourceNames("10001");
String imageName = null;
for (String name : names) {
if (name.indexOf(".png") >= 0) {
imageName = name;
break;
}
}
// 通过部署ID和文件名称得到文件的输入流
InputStream in = repositoryService.getResourceAsStream("10001", imageName);
// String image = Base64Convert.getBase64FromInputStream(in);
int count = 0;
while (count == 0) {
count = in.available();
}
byte[] b = new byte[count];
in.read(b);
in.close();
System.out.println(b.length);
File file = new File("C:\\ActivityLog\\a.png");
// if(!file.exists())
// {
// file.createNewFile(); //如果文件不存在,则创建
//
// }
FileImageOutputStream imageOutput = new FileImageOutputStream(file);//打开输入流
try{
imageOutput.write(b, 0, b.length);//将byte写入硬盘
imageOutput.close();
System.out.println("Make Picture success,Please find image in " + "C:\\ActivityLog\\a.png");
} catch(Exception ex) {
imageOutput.close();
System.out.println("Exception: " + ex);
ex.printStackTrace();
}
}
Activity工作流读取Blob图片资源保存本地
最新推荐文章于 2024-04-26 16:37:52 发布