View Javadoc
1   package org.codehaus.plexus.compiler.csharp;
2   
3   import java.io.File;
4   import java.io.FileOutputStream;
5   import java.io.IOException;
6   import java.io.InputStream;
7   import java.util.Enumeration;
8   import java.util.jar.JarEntry;
9   import java.util.jar.JarFile;
10  
11  public class JarUtil {
12      public static void extract( File destDir, File jarFile ) throws IOException
13      {
14          JarFile jar = new JarFile( jarFile );
15          Enumeration enumEntries = jar.entries();
16          while ( enumEntries.hasMoreElements() ) {
17              JarEntry file = ( JarEntry ) enumEntries.nextElement();
18              File f = new File( destDir + File.separator + file.getName() );
19              if ( file.isDirectory() )
20              {
21                  f.mkdir();
22                  continue;
23              }
24              InputStream is = jar.getInputStream( file );
25              FileOutputStream fos = new FileOutputStream( f );
26              try
27              {
28                  while ( is.available() > 0 )
29                  {
30                      fos.write( is.read() );
31                  }
32              }
33              finally
34              {
35                  is.close();
36                  fos.close();
37              }
38          }
39      }
40  }