private void jarDir ( File dirOrFile2jar , JarOutputStream jos , String path ) throws IOException { if ( mVerbose ) { System . out . println ( "checking " + dirOrFile2jar ) ; } if ( dirOrFile2jar . isDirectory ( ) ) { String [ ] dirList = dirOrFile2jar . list ( ) ; String subPath = ( path == null ) ? "" : ( path + dirOrFile2jar . getName ( ) + SEP ) ; if ( path != null ) { JarEntry je = new JarEntry ( subPath ) ; je . setTime ( dirOrFile2jar . lastModified ( ) ) ; jos . putNextEntry ( je ) ; jos . flush ( ) ; jos . closeEntry ( ) ; } for ( int i = 0 ; i < dirList . length ; i ++ ) { File f = new File ( dirOrFile2jar , dirList [ i ] ) ; jarDir ( f , jos , subPath ) ; } } else if ( dirOrFile2jar . exists ( ) ) { if ( dirOrFile2jar . getCanonicalPath ( ) . equals ( mDestJarName ) ) { if ( mVerbose ) { System . out . println ( "skipping " + dirOrFile2jar . getPath ( ) ) ; } return ; } if ( mVerbose ) { System . out . println ( "adding " + dirOrFile2jar . getPath ( ) ) ; } FileInputStream fis = new FileInputStream ( dirOrFile2jar ) ; try { JarEntry entry = new JarEntry ( path + dirOrFile2jar . getName ( ) ) ; entry . setTime ( dirOrFile2jar . lastModified ( ) ) ; jos . putNextEntry ( entry ) ; while ( ( mByteCount = fis . read ( mBuffer ) ) != - 1 ) { jos . write ( mBuffer , 0 , mByteCount ) ; if ( mVerbose ) { System . out . println ( "wrote " + mByteCount + " bytes" ) ; } } jos . flush ( ) ; jos . closeEntry ( ) ; } catch ( IOException ioe ) { throw ioe ; } finally { fis . close ( ) ; } } }
Recursively jars up the given path under the given directory .