[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

InputStream java.util.zip.ZipFile.getInputStream(ZipEntry arg 0) throws IOException

Posted on 2004-10-27
27
Medium Priority
?
1,326 Views
Last Modified: 2009-12-16
I am getting

java.lang.NullPointerException
      at java.util.zip.ZipFile.getInputStream(ZipFile.java:191)
      at LineCount.unzipAndGetEntries(LineCount.java:642)
      at LineCount.processFromAchivesFolder(LineCount.java:575)
      at LineCount.main(LineCount.java(Compiled Code))

This is happening when I am trying to open a particular file. Can you please tell me what I am supposed to check?

Thanks a lot
0
Comment
Question by:g46905
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 13
  • 9
  • 4
27 Comments
 
LVL 8

Expert Comment

by:kiranhk
ID: 12427138
you need to tell what you r trying to do and when/where u r getting this exception. Better still you can post the code here
0
 

Author Comment

by:g46905
ID: 12427243
Here is the method where I am having this error.I commented the line where this exception is being thrown.Please let me know if I can help you with some more information.Please search for <<<< so that it will be easier for you to search for the line.Thanks.

public static void unzipAndGetEntries(String zipfilename,String sProfile, Date fromDD, Date toDate) {
   System.out.println(" Zip File Name : "  + zipfilename);
                            
    try {
       ZipFile myzipfile = new ZipFile(zipfilename);
       ZipEntry ze = null;
      InputStream iss = null;
                String sFileInZip = null;
       Vector vFileName = null;
       String sZipDirection = null;;
       for(Enumeration e = myzipfile.entries(); e.hasMoreElements();)
       {
          ze = (ZipEntry)e.nextElement();
          sFileInZip = ze.getName();
          if(sFileInZip.endsWith(".log"))
            {
              iss = myzipfile.getInputStream(ze);
              vFileName = processZipEntry(iss,fromDD, toDate);
              iss.close();
              iss = null;
              } // if
           ze = null;
           sFileInZip = null;
      }  // for
                  
   for(Enumeration e = myzipfile.entries(); e.hasMoreElements();)
  {
      ze = (ZipEntry)e.nextElement();
      sFileInZip = ze.getName();
      for (int vf = 0;vf<vFileName.size();vf++){
       String sFileName = vFileName.elementAt(vf).toString();
                                              
      if (sFileInZip.indexOf("outbound/processed")!=-1)
      sZipDirection = "outbound";
       if (sFileInZip.indexOf("inbound/processed")!=-1)
                 sZipDirection = "inbound";
                             
                             
                                                    
      if(sFileInZip.endsWith(sFileName) && (sFileInZip.indexOf("processed")!=-1)){
      System.out.println("sFileInZip : 1 " + sFileInZip );
      System.out.println("sFileInZip Size : " + sFileInZip.length() );
                iss = myzipfile.getInputStream(ze);// here is the Zip exception <<<<<----------------------------------------------
      
                BufferedReader brZipFile = new BufferedReader(new InputStreamReader(iss));
       updateLineCount(brZipFile,sProfile,sZipDirection);
      brZipFile.close();
      brZipFile = null;
       iss.close();
       iss = null;
        ze = null;
                              
       } // if
   } // for  
      sFileInZip = null;              
      } // for
                     
               myzipfile.close();
               myzipfile = null;
              String sFileName = null;              
             
      } catch(OutOfMemoryError ex) { System.out.println(" Memory Exception........ " + ex.toString());
   } // try/catch
    catch(IOException e) {System.out.println( " unzipAndGetEntries.....");
     e.printStackTrace(); } // try/catch
 }
0
 
LVL 8

Assisted Solution

by:kiranhk
kiranhk earned 150 total points
ID: 12427421
This is what i tested out. it is working fine over here. if u have the problem again maybe u need to post all the methods getting called from this method to check why it is throwing error

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Date;
import java.util.Enumeration;
import java.util.Vector;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

/*
 * Created on Oct 27, 2004
 * @author ZJNRSHA (kiran.k.krishnamurthy@verizon.com)
 *
 */

/**
 * @author ZJNRSHA
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class TestZip {

    public static void main(String[] args) {
        TestZip tz = new TestZip();
        tz.unzipAndGetEntries("startup.jar","kiran",new Date(),new Date());
    }
   
    public void unzipAndGetEntries(String zipfilename,String sProfile, Date fromDD, Date toDate) {
        System.out.println(" Zip File Name : "  + zipfilename);
                             
         try {
           ZipFile myzipfile = new ZipFile(zipfilename);
           ZipEntry ze = null;
          InputStream iss = null;
                     String sFileInZip = null;
           Vector vFileName = null;
           String sZipDirection = null;;

           for(Enumeration e = myzipfile.entries(); e.hasMoreElements();)
           {
              ze = (ZipEntry)e.nextElement();
              sFileInZip = ze.getName();
              if(sFileInZip.endsWith(".log"))
                {
                  iss = myzipfile.getInputStream(ze);
             //     vFileName = processZipEntry(iss,fromDD, toDate);
                  iss.close();
                  iss = null;
                  } // if
               ze = null;
               sFileInZip = null;
          }  // for
 
        for(Enumeration e = myzipfile.entries(); e.hasMoreElements();)
       {
          ze = (ZipEntry)e.nextElement();
          iss =  myzipfile.getInputStream(ze);
          System.out.println("InputStream available size is " + iss.available());        
          /*sFileInZip = ze.getName();
          for (int vf = 0;vf<vFileName.size();vf++){
           String sFileName = vFileName.elementAt(vf).toString();
                                           
          if (sFileInZip.indexOf("outbound/processed")!=-1)
          sZipDirection = "outbound";
           if (sFileInZip.indexOf("inbound/processed")!=-1)
                      sZipDirection = "inbound";
                             
                             
                                                 
           if(sFileInZip.endsWith(sFileName) && (sFileInZip.indexOf("processed")!=-1)){
          System.out.println("sFileInZip : 1 " + sFileInZip );
          System.out.println("sFileInZip Size : " + sFileInZip.length() );
                     iss = myzipfile.getInputStream(ze);// here is the Zip exception <<<<<----------------------------------------------
         
                     BufferedReader brZipFile = new BufferedReader(new InputStreamReader(iss));
         //  updateLineCount(brZipFile,sProfile,sZipDirection);
          brZipFile.close();
          brZipFile = null;
           iss.close();
           iss = null;
            ze = null;
                             
            } // if
        } // for */
          iss.close();
          iss = null;
           ze = null;
         
          sFileInZip = null;            
          } // for
                       
                    myzipfile.close();
                    myzipfile = null;
                   String sFileName = null;            
               
           } catch(OutOfMemoryError ex) { System.out.println(" Memory Exception........ " + ex.toString());
        } // try/catch
         catch(IOException e) {System.out.println( " unzipAndGetEntries.....");
          e.printStackTrace(); } // try/catch
      }
}
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 86

Expert Comment

by:CEHJ
ID: 12427697

>>iss = myzipfile.getInputStream(ze);// here is the Zip exception <<<<<-

You've actually already made that assignment earlier:

>>
for(Enumeration e = myzipfile.entries(); e.hasMoreElements();)
      {
         ze = (ZipEntry)e.nextElement();
         iss =  myzipfile.getInputStream(ze);
>>
0
 
LVL 8

Expert Comment

by:kiranhk
ID: 12427718
CEHJ,
that is my code which i posted after modifying. I have commented the earlier code which g46905 had posted as throwing exception.

Check out my comment
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12427796
Oh OK. I'll wait to see what g46905 says
0
 

Author Comment

by:g46905
ID: 12428267
kiranhk,
            Could you please explain me why you have commented the code below.Thanks

 /*sFileInZip = ze.getName();
          for (int vf = 0;vf<vFileName.size();vf++){
           String sFileName = vFileName.elementAt(vf).toString();
                                           
          if (sFileInZip.indexOf("outbound/processed")!=-1)
          sZipDirection = "outbound";
           if (sFileInZip.indexOf("inbound/processed")!=-1)
                      sZipDirection = "inbound";
                             
                             
                                                 
           if(sFileInZip.endsWith(sFileName) && (sFileInZip.indexOf("processed")!=-1)){
          System.out.println("sFileInZip : 1 " + sFileInZip );
          System.out.println("sFileInZip Size : " + sFileInZip.length() );
                     iss = myzipfile.getInputStream(ze);// here is the Zip exception <<<<<----------------------------------------------
         
                     BufferedReader brZipFile = new BufferedReader(new InputStreamReader(iss));
         //  updateLineCount(brZipFile,sProfile,sZipDirection);
          brZipFile.close();
          brZipFile = null;
           iss.close();
           iss = null;
            ze = null;
                             
            } // if
        } // for */
0
 

Author Comment

by:g46905
ID: 12432677
Could some one please help me with this issue where I am getting

java.lang.NullPointerException
     at java.util.zip.ZipFile.getInputStream(ZipFile.java:191)
     at LineCount.unzipAndGetEntries(LineCount.java:642)
     at LineCount.processFromAchivesFolder(LineCount.java:575)
     at LineCount.main(LineCount.java(Compiled Code))
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12432696
Is the exception occurring where you marked it in your code - i.e. is that line 191?
0
 

Author Comment

by:g46905
ID: 12432738
Yes sir. It happens when it tries to open a particular .zip folder. It is able to open the .zip file aand the access the files withing it.Could you please tell me if I am missing something?

Thanks a lot for your interest.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12432751
>>It happens when it tries to open a particular .zip folder.

That folder is not being held open by anything else at that time is it?
0
 

Author Comment

by:g46905
ID: 12432779
No CEHJ.Could you please suggest me if I missed somthing?

Thanks,
0
 

Author Comment

by:g46905
ID: 12432885
Here is the method where the unzipAndGetEntries(String zipfilename,String sProfile, Date fromDD, Date toDate) is being called.

public static void processFromAchivesFolder(Vector proList, Date fromD, Date toDate)
        {
                                     
              try
              {
                    String proName = "";
                    File in_dir = new File(archive_path);
                    File filelist[] = in_dir.listFiles();
                    for(int x = 0; x < filelist.length; x++)
                    {
                          for(int y = 0; y < proList.size(); y++)
                          {
                                  String sWantedProfile = ((ProfileObject)proList.elementAt(y)).getName();
                                proName = ((ProfileObject)proList.elementAt(y)).getName().replace(' ', '_');
                                proName = proName.replace('-', '_');
                                proName = proName.replace('(', '_');
                                proName = proName.replace(')', '_');
                                
                                System.out.println("proName : " + proName);
                                System.out.println("filelist[x].getName() " + filelist[x].getName());
                                
                                if(filelist[x].getName().startsWith(proName))
                                      unzipAndGetEntries(archive_path + "/" + filelist[x].getName(),sWantedProfile,fromD, toDate);
                          }

                    }

                    proName = null;
                  
              }
              catch(Exception e) {
                    System.out.println(" processFromAchivesFolder..........");
                    e.printStackTrace(); } // end try/catch
} // end processFromAchivesFolder
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 150 total points
ID: 12436362
Check the integrity of the zip file by other means first
0
 

Author Comment

by:g46905
ID: 12436424
Could you please tell me what exactly you meant by saying " Check the integrity by other means?.Please explain.

Thanks,
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12436441
Open with Winzip, Jar etc?
0
 

Author Comment

by:g46905
ID: 12436482
I have done all possible testing.I personally feel that I am doing something incorrect in my logic and is going out of boundry.Do we have any method where I can post the .zip file that I am trying to access so that you will be able to test it in your environment? .Please suggest me if there is an alternative.Thanks a lot

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12436555
I could take a look if you post it somewhere public (webspace etc)
0
 

Author Comment

by:g46905
ID: 12436612
I will see if I can provide a link to the webspace and let you know.Thanks for your help!

Thanks again
0
 

Author Comment

by:g46905
ID: 12437752
CEHJ,
        I was able to rectify the problem as I found that it was not exiting out of the loop correctly.Thanks for you time and help.
0
 

Author Comment

by:g46905
ID: 12437777
how do I split the points between you and me. Please suggest
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12438569
>>how do I split the points between you and me

I don't think you can. I think i might be able to lower them though. I'll see if i can get a mod over. Do nothing in the meantime ...
0
 

Author Comment

by:g46905
ID: 12438633
Sure.

Thanks
0
 

Author Comment

by:g46905
ID: 12462428
I feel that kiranhk  also deserves points for the time he invested so I have increased the Point Value.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12462800
8-)
0
 
LVL 8

Expert Comment

by:kiranhk
ID: 12463766
thanks  :)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question