Reputation: 87
I am trying to find the size of uncompressed bz2 files using the following code. However,after running the code, I get the size as 0 bytes. Don't know what is wrong. Could someone please point out.
try{
FileInputStream fin = new FileInputStream("/users/praveen/data1/00.json.bz2");
BufferedInputStream in = new BufferedInputStream(fin);
BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(in);
long size = 0;
while (bzIn.available() > 0)
{
byte[] buf = new byte[1024];
int read = bzIn.read(buf);
if (read > 0) size += read;
}
System.out.println("File Size: " + size + "bytes");
bzIn.close();
//bzIn.close();
}
catch (Exception e) {
throw new Error(e.getMessage());
}
Upvotes: 0
Views: 304
Reputation: 35011
It is very probable that BZip2CompressorInputStream
does not fully implement the available()
method. It probably just returns 0. Instead, you should try using InputStream#read(byte[])
and checking for a -1 return.
Upvotes: 2