[英]How to Zip Blob value(PDF) in Java
I have a PDF stored in Database as blob. 我有一个PDF以blob格式存储在数据库中。 I have a usecase to retrieve the blob file(PDF) and zip it using java. 我有一个用例来检索blob文件(PDF)并使用java将其压缩。 Could anybody help me out here? 有人可以帮我吗?
Below is my sample code. 以下是我的示例代码。 Where I get my pdf from database as BLobDomain I want it inside a blobfolder and i have given the representation below 807.pdf and 1285.pdf . 我从数据库中以BLobDomain的形式获取pdf,我希望将其保存在blobfolder中,并给出了下面的表示形式807.pdf和1285.pdf。 Thats how i want my blobdomain values to be 那就是我希望我的blobdomain值是
BlobDomain doc1=(BlobDomain)rowshis[0].getAttribute("Document");
BlobDomain doc2=(BlobDomain)rowshis[1].getAttribute("Document");
StringBuilder sb = new StringBuilder();
sb.append("Test Date");
System.out.println("check----1");
File f = new File("/customer/scratch/HDLtest.zip");
ZipOutputStream out = new ZipOutputStream(newFileOutputStream(f));
System.out.println("check----2");
ZipEntry e = new ZipEntry("BlobFiles/807.pdf");
out.putNextEntry(e);
ZipEntry e11 = new ZipEntry("BlobFiles/1285.pdf");
out.putNextEntry(e11);
System.out.println("check----3");
ZipEntry e1 = new ZipEntry("Test.dat");
out.putNextEntry(e1);
System.out.println("check----4");
byte[] data = sb.toString().getBytes();
out.write(data, 0, data.length);
out.closeEntry();
out.close();
You need to write the content of a zip entry before adding the next zip entry. 在添加下一个zip条目之前,您需要编写zip条目的内容。
Call sequence should be: 呼叫顺序应为:
putNextEntry()
- Begins writing a new ZIP file entry and positions the stream to the start of the entry data. putNextEntry()
- 开始写入新的ZIP文件条目,并将流定位到条目数据的开头。 Closes the current entry if still active. 如果仍处于活动状态,则关闭当前条目。 write()
- Writes an array of bytes to the current ZIP entry data. write()
- 将字节数组写入当前的ZIP条目数据。 closeEntry()
- Closes the current ZIP entry and positions the stream for writing the next entry. closeEntry()
- 关闭当前的ZIP条目并放置流以写入下一个条目。 putNextEntry()
for the next entry automatically closes the current entry if still active. 该调用是可选的,因为调用下一个条目的putNextEntry()
自动关闭当前条目(如果仍处于活动状态)。 Repeat above for each entry you want to add to the zip file. 对要添加到zip文件中的每个条目重复上述步骤。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.