Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5991385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:22:44+00:00 2026-05-22T23:22:44+00:00

I am using the BZip2 compression library from Apache Ant. The documentation is given

  • 0

I am using the BZip2 compression library from Apache Ant. The documentation is given at –
http://javadoc.haefelinger.it/org.apache.ant/1.7.1/org/apache/tools/bzip2/CBZip2InputStream.html

I keep getting this error when I run the code –

   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 org.apache.tools.bzip2.bzipCompression.main(bzipCompression.java:37)

The error is at line –

**CBZip2InputStream cin = new CBZip2InputStream(fileInputStream);**

My source code is –

  public static void main(String[] args) throws IOException, NullPointerException {
    // TODO Auto-generated method stub

    FileReader inFile = new FileReader("alice29.txt");
    BufferedReader buff = new BufferedReader(inFile);

    FileOutputStream fout = new FileOutputStream("alicea.txt");
    fout.write("BZ".getBytes());


    CBZip2OutputStream czout = new CBZip2OutputStream (fout);

    String message = buff.readLine(); // read first line

    while(message!=null){
        byte[] input = message.getBytes();
        czout.write(input);
        message = buff.readLine();
    }
    czout.flush();
    czout.close();


    InputStream fileInputStream = new FileInputStream("alicea.txt");
    CBZip2InputStream cin = new CBZip2InputStream(fileInputStream);
    FileOutputStream decOut = new FileOutputStream("decompressedAlice.txt");


    byte[] buf = new byte[100000];
    int len;

    while((len = cin.read(buf))>0){
        decOut.write(buf, 0, len);
    }
    decOut.close();
    cin.close();

}

Thank you so much for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:22:45+00:00Added an answer on May 22, 2026 at 11:22 pm

    You are opening a FileOutputStream to alicea.txt

    FileOutputStream fout = new FileOutputStream("alicea.txt");
    

    This OutputStream is never closed in your code, but in the error-Line you open a FileInputStream on the same file:

    InputStream fileInputStream = new FileInputStream("alicea.txt");
    CBZip2InputStream cin = new CBZip2InputStream(fileInputStream);
    

    IMHO while you have an open FileOutputStream on a file, you can not open a file InputStream on the same file. That may be the reason, why your FileInputStream is NULL and the exception is thrown.

    Update:
    There is a known bug in the CBZip2InputStream and a solution described in the year 2002 (still can be found at MarkMail), which still exists. You have to download the java-classes and may not use a ready build .jar archive. Change the following lines in the initialize() method of CBZip2InputStream.java:

    Original code (starting at line 213):

    private void initialize() {
        char magic3, magic4;
        magic3 = bsGetUChar();
        magic4 = bsGetUChar();
        if (magic3 != 'h' || magic4 < '1' || magic4 > '9') {
            bsFinishedWithStream();
            streamEnd = true;
            return;
        }
        setDecompressStructureSizes(magic4 - '0');
        computedCombinedCRC = 0;
    }
    

    Change this to:

    private void initialize() {
        char magic1, magic2; 
        char magic3, magic4; 
        magic1 = bsGetUChar(); 
        magic2 = bsGetUChar(); 
        magic3 = bsGetUChar(); 
        magic4 = bsGetUChar(); 
        if (magic1 != 'B' || magic2 != 'Z' | magic3 != 'h' || magic4 < '1' || magic4 > '9') {   
            bsFinishedWithStream();
            streamEnd = true;
            return;
        }
        setDecompressStructureSizes(magic4 - '0');
        computedCombinedCRC = 0;
    }
    

    Last Update:
    I just reviewed the svn of apache ant; the bug in trunk is fixed. But despite that fact, there are many, many downloads still containing this bug. I also downloaded just an old version accidently to test your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using online interfaces to a version control system is a nice way to have
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
Using VS2008, C#, .Net 2 and Winforms how can I make a regular Button
Using JDeveloper , I started developing a set of web pages for a project
Using C#, I need a class called User that has a username, password, active
Using preview 4 of ASP.NET MVC Code like: <%= Html.CheckBox( myCheckBox, Click Here, True,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.