0

I am trying to modify web.xml using ZipInputStream. File to read is web.xml which is inside ear/war file

C:/XX.ear/YY.war/WEB-INF/web.xml

ZipFile zipFile = new ZipFile("C:/XX.ear");
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    while(entries.hasMoreElements()){
        ZipEntry entry = entries.nextElement();
        if(entry.getName().equalsIgnoreCase("YY.war")){
            ZipInputStream inputStream = new ZipInputStream(zipFile.getInputStream(entry));
            ZipEntry zipEntry;
            while(( zipEntry  = inputStream.getNextEntry())!=null)
            {
                System.out.println(zipEntry.getName());// Prints WEB-INF/web.xml
                if (zipEntry.getName().endsWith(".xml")) {
                    ZipInputStream iStream = new ZipInputStream(zipFile.getInputStream(zipEntry)); 
                      // throws NullPointerException here

                }                   
            }                   
        }                       
    }

new ZipInputStream(zipFile.getInputStream(zipEntry)) I couldn't point to inner zip file to get input stream of inner war file

Is it possible to read the inner zipentry as inputstream ??

Karthigeyan Vellasamy
  • 2,038
  • 6
  • 33
  • 50

1 Answers1

0

Java 7 nio2 package has a new file system interface and a new Zip File System provider. The interface and provider allow to traverse the zip tree in a visitor pattern style This should provide a more clear and efficient way to get to the inner zip file

Edit: I tried to traverse a zip-inside-zip and got an exception. according to this thread, you have to extract the inner zip in order to traverse it.

Community
  • 1
  • 1
Sharon Ben Asher
  • 13,849
  • 5
  • 33
  • 47