java 处理 BLOB OutputStream(插入空的Blob字段到表中)

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();

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值