Reputation: 41
I'm trying to compress the file in java before I upload the file with GZIPOutputStream
. Is there a way to just store the gzipped file in memory for the upload and not have it generate a gzipped file on the local computer?
Thanks!
Upvotes: 4
Views: 1355
Reputation: 310840
Just connect the GZipOutputStream directly to the output stream and write. No file necessary.
Upvotes: 2
Reputation: 41
Solved this problem by writing to a temp file and doing a .deleteonexit on the temp file once the gzip uploading was done.
Thanks for the help!
Upvotes: 0
Reputation: 27518
Decorate content entity with 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();
}
Upvotes: 0