簡體   English   中英

使用GZIPOutputStream壓縮上傳而不在本地創建gzip文件

[英]compressing with GZIPOutputStream to upload without creating a gzip file locally

在使用GZIPOutputStream上傳文件之前,我正在嘗試在java中壓縮文件。 有沒有辦法將gzip壓縮文件存儲在內存中以便上傳,而不是在本地計算機上生成gzip壓縮文件?

謝謝!

只需將GZipOutputStream直接連接到輸出流並寫入即可。 沒有必要的文件。

使用GzipCompressingEntity裝飾內容實體

HttpPost httpPost = new HttpPost("https://host/stuff");
httpPost.setEntity(new GzipCompressingEntity(new FileEntity(new File("my.stuff"))));
CloseableHttpResponse response = httpclient.execute(httpPost);
try {
    EntityUtils.consume(response.getEntity());
} finally {
    response.close();
}

通過寫入臨時文件並在完成gzip上傳后對臨時文件執行.deleteonexit解決了這個問題。

謝謝您的幫助!

暫無
暫無

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

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