g46905
asked on
InputStream java.util.zip.ZipFile.getInputStream(ZipEntry arg 0) throws IOException
I am getting
java.lang.NullPointerExcep tion
at java.util.zip.ZipFile.getI nputStream (ZipFile.j ava:191)
at LineCount.unzipAndGetEntri es(LineCou nt.java:64 2)
at LineCount.processFromAchiv esFolder(L ineCount.j ava:575)
at LineCount.main(LineCount.j ava(Compil ed 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
java.lang.NullPointerExcep
at java.util.zip.ZipFile.getI
at LineCount.unzipAndGetEntri
at LineCount.processFromAchiv
at LineCount.main(LineCount.j
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
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
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(".l og"))
{
iss = myzipfile.getInputStream(z e);
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).to String();
if (sFileInZip.indexOf("outbo und/proces sed")!=-1)
sZipDirection = "outbound";
if (sFileInZip.indexOf("inbou nd/process ed")!=-1)
sZipDirection = "inbound";
if(sFileInZip.endsWith(sFi leName) && (sFileInZip.indexOf("proce ssed")!=-1 )){
System.out.println("sFileI nZip : 1 " + sFileInZip );
System.out.println("sFileI nZip Size : " + sFileInZip.length() );
iss = myzipfile.getInputStream(z e);// here is the Zip exception <<<<<--------------------- ---------- ---------- -----
BufferedReader brZipFile = new BufferedReader(new InputStreamReader(iss));
updateLineCount(brZipFile, sProfile,s ZipDirecti on);
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
}
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(".l
{
iss = myzipfile.getInputStream(z
vFileName = processZipEntry(iss,fromDD
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).to
if (sFileInZip.indexOf("outbo
sZipDirection = "outbound";
if (sFileInZip.indexOf("inbou
sZipDirection = "inbound";
if(sFileInZip.endsWith(sFi
System.out.println("sFileI
System.out.println("sFileI
iss = myzipfile.getInputStream(z
BufferedReader brZipFile = new BufferedReader(new InputStreamReader(iss));
updateLineCount(brZipFile,
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>iss = myzipfile.getInputStream(z
You've actually already made that assignment earlier:
>>
for(Enumeration e = myzipfile.entries(); e.hasMoreElements();)
{
ze = (ZipEntry)e.nextElement();
iss = myzipfile.getInputStream(z
>>
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
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
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).to String();
if (sFileInZip.indexOf("outbo und/proces sed")!=-1)
sZipDirection = "outbound";
if (sFileInZip.indexOf("inbou nd/process ed")!=-1)
sZipDirection = "inbound";
if(sFileInZip.endsWith(sFi leName) && (sFileInZip.indexOf("proce ssed")!=-1 )){
System.out.println("sFileI nZip : 1 " + sFileInZip );
System.out.println("sFileI nZip Size : " + sFileInZip.length() );
iss = myzipfile.getInputStream(z e);// here is the Zip exception <<<<<--------------------- ---------- ---------- -----
BufferedReader brZipFile = new BufferedReader(new InputStreamReader(iss));
// updateLineCount(brZipFile, sProfile,s ZipDirecti on);
brZipFile.close();
brZipFile = null;
iss.close();
iss = null;
ze = null;
} // if
} // for */
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).to
if (sFileInZip.indexOf("outbo
sZipDirection = "outbound";
if (sFileInZip.indexOf("inbou
sZipDirection = "inbound";
if(sFileInZip.endsWith(sFi
System.out.println("sFileI
System.out.println("sFileI
iss = myzipfile.getInputStream(z
BufferedReader brZipFile = new BufferedReader(new InputStreamReader(iss));
// updateLineCount(brZipFile,
brZipFile.close();
brZipFile = null;
iss.close();
iss = null;
ze = null;
} // if
} // for */
ASKER
Could some one please help me with this issue where I am getting
java.lang.NullPointerExcep tion
at java.util.zip.ZipFile.getI nputStream (ZipFile.j ava:191)
at LineCount.unzipAndGetEntri es(LineCou nt.java:64 2)
at LineCount.processFromAchiv esFolder(L ineCount.j ava:575)
at LineCount.main(LineCount.j ava(Compil ed Code))
java.lang.NullPointerExcep
at java.util.zip.ZipFile.getI
at LineCount.unzipAndGetEntri
at LineCount.processFromAchiv
at LineCount.main(LineCount.j
Is the exception occurring where you marked it in your code - i.e. is that line 191?
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.
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?
That folder is not being held open by anything else at that time is it?
ASKER
No CEHJ.Could you please suggest me if I missed somthing?
Thanks,
Thanks,
ASKER
Here is the method where the unzipAndGetEntries(String zipfilename,String sProfile, Date fromDD, Date toDate) is being called.
public static void processFromAchivesFolder(V ector 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.el ementAt(y) ).getName( );
proName = ((ProfileObject)proList.el ementAt(y) ).getName( ).replace( ' ', '_');
proName = proName.replace('-', '_');
proName = proName.replace('(', '_');
proName = proName.replace(')', '_');
System.out.println("proNam e : " + proName);
System.out.println("fileli st[x].getN ame() " + filelist[x].getName());
if(filelist[x].getName().s tartsWith( proName))
unzipAndGetEntries(archive _path + "/" + filelist[x].getName(),sWan tedProfile ,fromD, toDate);
}
}
proName = null;
}
catch(Exception e) {
System.out.println(" processFromAchivesFolder.. ........") ;
e.printStackTrace(); } // end try/catch
} // end processFromAchivesFolder
public static void processFromAchivesFolder(V
{
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.el
proName = ((ProfileObject)proList.el
proName = proName.replace('-', '_');
proName = proName.replace('(', '_');
proName = proName.replace(')', '_');
System.out.println("proNam
System.out.println("fileli
if(filelist[x].getName().s
unzipAndGetEntries(archive
}
}
proName = null;
}
catch(Exception e) {
System.out.println(" processFromAchivesFolder..
e.printStackTrace(); } // end try/catch
} // end processFromAchivesFolder
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Could you please tell me what exactly you meant by saying " Check the integrity by other means?.Please explain.
Thanks,
Thanks,
Open with Winzip, Jar etc?
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)
ASKER
I will see if I can provide a link to the webspace and let you know.Thanks for your help!
Thanks again
Thanks again
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.
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.
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 ...
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 ...
ASKER
Sure.
Thanks
Thanks
ASKER
I feel that kiranhk also deserves points for the time he invested so I have increased the Point Value.
8-)
thanks :)