Link to home
Start Free TrialLog in
Avatar of g46905
g46905

asked on

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

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
Avatar of kiranhk
kiranhk

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
Avatar of g46905

ASKER

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
 }
SOLUTION
Avatar of kiranhk
kiranhk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CEHJ

>>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);
>>
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
Oh OK. I'll wait to see what g46905 says
Avatar of g46905

ASKER

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 */
Avatar of g46905

ASKER

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))
Is the exception occurring where you marked it in your code - i.e. is that line 191?
Avatar of g46905

ASKER

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.
>>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?
Avatar of g46905

ASKER

No CEHJ.Could you please suggest me if I missed somthing?

Thanks,
Avatar of g46905

ASKER

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
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of g46905

ASKER

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

Thanks,
Open with Winzip, Jar etc?
Avatar of g46905

ASKER

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

I could take a look if you post it somewhere public (webspace etc)
Avatar of g46905

ASKER

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

Thanks again
Avatar of g46905

ASKER

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.
Avatar of g46905

ASKER

how do I split the points between you and me. Please suggest
>>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 ...
Avatar of g46905

ASKER

Sure.

Thanks
Avatar of g46905

ASKER

I feel that kiranhk  also deserves points for the time he invested so I have increased the Point Value.
8-)
thanks  :)