BZip2 Compression with Apache Ant's BZip2 tools.....problem

Discussion in 'Java' started by TSchultz55, Jul 26, 2005.

  1. TSchultz55

    TSchultz55 Guest

    All,

    I'm having some problems with Apache Ant's BZip2 classes.
    Hopefully someone can help me out. Every time I open a *.bz2 file that
    my class generates, it says "Invalid Archive" (using 7-Zip). 7-Zip can
    open *.bz2 files, as I have successfully done many times. Here's the
    code (all variables have been defined):

    byte[] fileBytes = new byte[1024];
    ...............
    public File compress(File currentChunkFile) throws IOException
    {
    File compressedFile = new File(currentChunkFile.getParent(),
    currentChunkFile.getName() + ".bz2");
    fileIn = new FileInputStream(currentChunkFile);
    bzip2Out = new CBZip2OutputStream(new
    FileOutputStream(compressedFile));
    int readBytes = 0;

    while((readBytes = fileIn.read(fileBytes, 0, fileBytes.length)) > -1)
    {
    bzip2Out.write(fileBytes, 0, readBytes);
    }

    // Cleanup
    bzip2Out.flush();
    fileIn.close();
    bzip2Out.close();

    return compressedFile;
    }
    .......................
    I use the same exact logic for GZip compression and that works fine. A
    *.bz2 file generated by my class is always a few bytes smaller than on
    generated by bzip2.exe. Why is this? Is there an issue with this
    Apache library? Is there some dumb error in the code I don't see? Can
    anyone point me in the direction of a better BZip2 compression library?
    Any help would be greatly appreciated. Thanks!

    Cheers,

    Tim
     
    TSchultz55, Jul 26, 2005
    #1
    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. Christian  Decker

    BZip2-Files & Java

    Christian Decker, Feb 2, 2005, in forum: Java
    Replies:
    9
    Views:
    3,003
    Melih Cetin via JavaKB.com
    Feb 20, 2005
  2. Errol Smith
    Replies:
    12
    Views:
    1,383
    Errol Smith
    Sep 24, 2004
  3. itzel

    ReadError, "not a bzip2 file"

    itzel, Sep 13, 2006, in forum: Python
    Replies:
    0
    Views:
    392
    itzel
    Sep 13, 2006
  4. guest

    fgets bzip2

    guest, Feb 2, 2007, in forum: C Programming
    Replies:
    7
    Views:
    443
    Christopher Layne
    Feb 2, 2007
  5. Chetan  Patil
    Replies:
    5
    Views:
    205
    Roman Ziak
    Apr 1, 2006
Loading...

Share This Page