java 处理 BLOB OutputStream(插入空的Blob字段到表中)
编程技术  /  houtizong 发布于 3年前   53
1.插入占位数据:
insert into TEST_CUICF(t1,t2) values(12,empty_blob())
2.获得占位数据:
select t1,t2 from TEST_CUICF t for update
BLOB oracleBlobMockIn = oracleBlobMockIn = control.createMock(BLOB.class);
...
oracleBlobMockIn.getBinaryStream();
expectLastCall().andReturn(new FileInputStream(inPdfFile)).times(1);
...
ResultSet rs = st.executeQuery(sql);
BLOB oracleBlobMockOut = null;
if (rs.next()) {
rs.getString("t1");
oracleBlobMockOut = (BLOB) rs.getBlob("t2");
}
...
control.replay();
Watermark.addPdfWatermark(oracleBlobMockIn, oracleBlobMockOut, markImagePath);
control.verify();
control.reset();
3.应用 输出流 (增加水印处理)
public static void addPdfWatermark(BLOB inputPdfFileBlob, BLOB outPdfFileBlob, String markImagePath) throws Exception {
if (null == WATERMARK_IMAGE) {
logger.info("watermark_image inital~~");
WATERMARK_IMAGE = Image.getInstance(markImagePath);
WATERMARK_IMAGE.setAbsolutePosition(10, 250);
}
PdfReader reader = null;
PdfStamper stamp = null;
try {
reader = new PdfReader(inputPdfFileBlob.getBinaryStream(), "PDF".getBytes());
stamp = new PdfStamper(reader, outPdfFileBlob.getBinaryOutputStream()); //获得输出流
int numberOfPages = reader.getNumberOfPages();
for (int i = 1; i <= numberOfPages; i++) {
PdfContentByte under = stamp.getUnderContent(i);
under.addImage(WATERMARK_IMAGE);
}
} finally {
stamp.close();
}
}
4.关闭连接
con.commit();
con.close();
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接