Zipping without a file

T

Tyler Reed

I'd like to compress a stream. However, the incoming data is not a file and,
more importantly, the outgoing data is not a file, it's just another
stream. What can I use to compress the data? I've been playing around with
util.zip but it wants me to create a Zip Entry and I can't be injecting
irrelevant info like that into the data stream. Any ideas?

Thanks,
Tyler Reed
(e-mail address removed)
 
A

Andrew Thompson

I'd like to compress a stream. However, the incoming data is not a file and,
more importantly, the outgoing data is not a file, it's just another
stream.

Is the incoming data already compressed?

AFAIU, the zip compression algorithm can only
be applied to data once all the data is known,
so if your incoming stream is uncompressed,
you need to wait until you have a complete
file before you can compress it and write
to the output stream.

HTH

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
 
R

Rogan Dawes

Andrew said:
Is the incoming data already compressed?

AFAIU, the zip compression algorithm can only
be applied to data once all the data is known,
so if your incoming stream is uncompressed,
you need to wait until you have a complete
file before you can compress it and write
to the output stream.

HTH

Maybe the GZIPOutputStream is closer to what the OP was looking for?

You can use that to compress a single file, and tools such as WinZip and
other archivers will be able to uncompress it.

If it has to be a ZIP archive for some reason, you could try writing
your zip to a ByteArrayOutputStream, and then sending the contents of
the BAOS to the user. This will involve buffering the entire compressed
file in memory, which may or may not be acceptable.

Regards,

Rogan
 
S

Stefan Schulz

Tyler said:
I'd like to compress a stream. However, the incoming data is not a file and,
more importantly, the outgoing data is not a file, it's just another
stream. What can I use to compress the data? I've been playing around with
util.zip but it wants me to create a Zip Entry and I can't be injecting
irrelevant info like that into the data stream. Any ideas?

java.util.zip.GZIPInputStream, and java.util.zip.GZIPOutputStream come
to mind. For any further details, ask your friendly neighbourhood javadoc ;)
 
C

Chris Uppal

Tyler said:
I'd like to compress a stream.

Then java.util.zip.GZIPOutputStream is exactly the man for the job. Think of
it as a "compressing decorator" (because that's what it is ;-)

-- chris
 
T

Thomas Schodt

Tyler said:
I'd like to compress a stream. However, the incoming data is not a file and,
more importantly, the outgoing data is not a file, it's just another
stream. What can I use to compress the data? I've been playing around with
util.zip but it wants me to create a Zip Entry and I can't be injecting
irrelevant info like that into the data stream. Any ideas?

The first thing I thought of was STAC, but that seems to require a license.

Google found me this site
<http://datacompression.info/Lossless.shtml>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top