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

T

TSchultz55

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
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top