BZip2-Files & Java

  • Thread starter Christian Decker
  • Start date
C

Christian Decker

Ok two things:
I'm trying to get the Apache BZip2 Library to work, but I always get a
NullPointerException. My code looks like this:

Code:
void load(String filename) throws FileNotFoundException, IOException {
FileInputStream fis = new FileInputStream(filename);
CBZip2InputStream = new CBZip2InputStream(fis);
}

As soon as the creation of the CBZip2InputStream is reached, a
NullpointerException is thrown. Why?
Secondly: if the library is corrupted (e.g. doesn't work stable) is
there an alternative to it (Googleing did not help me very much)?

Snyke
 
S

Snyke

java.io.FileNotFoundException: PublicHubList.config.bz2 (No such file
or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at HubList.load(HubList.java:17)
at HubList.<init>(HubList.java:28)
at BlackPhoenix.main(BlackPhoenix.java:17)

Whereas HubList and BlackPhoenix my own classes are.
 
A

Andrey Kuznetsov

java.io.FileNotFoundException: PublicHubList.config.bz2 (No such file
or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at HubList.load(HubList.java:17)
at HubList.<init>(HubList.java:28)
at BlackPhoenix.main(BlackPhoenix.java:17)

Whereas HubList and BlackPhoenix my own classes are.
.... and PublicHubList.config.bz2 is file you want to decompress...
FileNotFoundException means that file was not found (deep thought :)
Hint: may be file name was wrong?
 
S

Snyke

Ah sorry, I moved PublicHubList.config.bz2 to another location so this
is the obvious error: I was looking for this one:

Exception in thread "main" java.lang.NullPointerException
at
org.apache.tools.bzip2.CBZip2InputStream.bsR(CBZip2InputStream.java:323)
at
org.apache.tools.bzip2.CBZip2InputStream.bsGetUChar(CBZip2InputStream.java:341)
at
org.apache.tools.bzip2.CBZip2InputStream.initBlock(CBZip2InputStream.java:230)
at
org.apache.tools.bzip2.CBZip2InputStream.<init>(CBZip2InputStream.java:178)
at HubList.load(HubList.java:19)
at HubList.<init>(HubList.java:28)
at BlackPhoenix.main(BlackPhoenix.java:17)
 
A

Andrey Kuznetsov

Exception in thread "main" java.lang.NullPointerException
at
org.apache.tools.bzip2.CBZip2InputStream.bsR(CBZip2InputStream.java:323)
at
org.apache.tools.bzip2.CBZip2InputStream.bsGetUChar(CBZip2InputStream.java:341)
at
org.apache.tools.bzip2.CBZip2InputStream.initBlock(CBZip2InputStream.java:230)
at
org.apache.tools.bzip2.CBZip2InputStream.<init>(CBZip2InputStream.java:178)
at HubList.load(HubList.java:19)
at HubList.<init>(HubList.java:28)
at BlackPhoenix.main(BlackPhoenix.java:17)

InputStream that you pass to CBZip2InputStream' constructor is null.
Check your code.
 
A

Andrey Kuznetsov

The debugger sais that fis is actually initialized.hmm, may be we have different source...

I have in CBZip2InputStream.java at line 323 following:
"thech = (char) bsStream.read();"
NullPointerException can only be here if bsStream is null.

Why don't you put a breakpoint in CBZip2InputStream.java at line 323 and
looks what's wrong?
 
S

Snyke

bStream is null but I don't get it: the InputStream I used to create
the CBZip2InputStream with is not null and is not null when the
Exception is thrown.
 
M

Melih Cetin via JavaKB.com

I had a similar problem due to the leading "BZ" stream identifiers in the
input file. When I removed these two characters from the input stream
before providing it to CBZip2InputStream constructor, the problem has been
sorted out. You may want to refer to http://www.kohsuke.org/bzip2/ for a
mention of this problem.

I hope this helps.
 

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,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top