public void unjar ( InputStream in , File destDir ) throws IOException { BufferedOutputStream dest = null ; JarInputStream jis = new JarInputStream ( in ) ; JarEntry entry ; while ( ( entry = jis . getNextJarEntry ( ) ) != null ) { if ( entry . isDirectory ( ) ) { File dir = new File ( destDir , entry . getName ( ) ) ; dir . mkdir ( ) ; if ( entry . getTime ( ) != - 1 ) { dir . setLastModified ( entry . getTime ( ) ) ; } continue ; } int count ; byte [ ] data = new byte [ BUFFER_SIZE ] ; File destFile = new File ( destDir , entry . getName ( ) ) ; if ( mVerbose ) { System . out . println ( "unjarring " + destFile + " from " + entry . getName ( ) ) ; } FileOutputStream fos = new FileOutputStream ( destFile ) ; dest = new BufferedOutputStream ( fos , BUFFER_SIZE ) ; try { while ( ( count = jis . read ( data , 0 , BUFFER_SIZE ) ) != - 1 ) { dest . write ( data , 0 , count ) ; } dest . flush ( ) ; } finally { dest . close ( ) ; } if ( entry . getTime ( ) != - 1 ) { destFile . setLastModified ( entry . getTime ( ) ) ; } } jis . close ( ) ; }
Given an InputStream on a jar file unjars the contents into the given directory .