簡體   English   中英

如何用Java壓縮Blob值(PDF)

[英]How to Zip Blob value(PDF) in Java

我有一個PDF以blob格式存儲在數據庫中。 我有一個用例來檢索blob文件(PDF)並使用java將其壓縮。 有人可以幫我嗎?

以下是我的示例代碼。 我從數據庫中以BLobDomain的形式獲取pdf,我希望將其保存在blobfolder中,並給出了下面的表示形式807.pdf和1285.pdf。 那就是我希望我的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();

在添加下一個zip條目之前,您需要編寫zip條目的內容。

呼叫順序應為:

  • putNextEntry() - 開始寫入新的ZIP文件條目,並將流定位到條目數據的開頭。 如果仍處於活動狀態,則關閉當前條目。
  • write() - 將字節數組寫入當前的ZIP條目數據。
  • closeEntry() - 關閉當前的ZIP條目並放置流以寫入下一個條目。
    該調用是可選的,因為調用下一個條目的putNextEntry()自動關閉當前條目(如果仍處於活動狀態)。

對要添加到zip文件中的每個條目重復上述步驟。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM