Zipping without a file

Discussion in 'Java' started by Tyler Reed, Sep 16, 2004.

  1. Tyler Reed

    Tyler Reed Guest

    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
    Tyler Reed, Sep 16, 2004
    #1
    1. Advertising

  2. On Thu, 16 Sep 2004 14:47:59 GMT, Tyler Reed wrote:

    > 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
    Andrew Thompson, Sep 16, 2004
    #2
    1. Advertising

  3. Tyler Reed

    Rogan Dawes Guest

    Andrew Thompson wrote:

    > On Thu, 16 Sep 2004 14:47:59 GMT, Tyler Reed wrote:
    >
    >
    >>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
    >


    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
    --
    Rogan Dawes

    *ALL* messages to will be dropped, and added
    to my blacklist. Please respond to "nntp AT dawes DOT za DOT net"
    Rogan Dawes, Sep 16, 2004
    #3
  4. Tyler Reed wrote:
    > 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 ;)
    Stefan Schulz, Sep 16, 2004
    #4
  5. Tyler Reed

    Chris Uppal Guest

    Tyler Reed wrote:

    > 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
    Chris Uppal, Sep 16, 2004
    #5
  6. Tyler Reed wrote:
    > 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>
    Thomas Schodt, Sep 16, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kasper K

    Zipping a directory

    Kasper K, Dec 22, 2003, in forum: Java
    Replies:
    1
    Views:
    1,506
    Harald Hein
    Dec 22, 2003
  2. OriginalBrownster
    Replies:
    4
    Views:
    322
    Dennis Lee Bieber
    Aug 21, 2006
  3. Replies:
    1
    Views:
    633
  4. Arthur
    Replies:
    2
    Views:
    116
    Arthur
    Nov 30, 2003
  5. Mark
    Replies:
    1
    Views:
    139
    Paul Marquess
    Nov 12, 2007
Loading...

Share This Page