Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.simpligility.maven.plugins.androidndk.common;
 
 
 import java.io.File;
Helper class to deal with jar files.

Author(s):
Johan Lindquist
public class JarHelper
{

    
Listener for jar extraction.
    public interface UnjarListener
    {
       boolean includeJarEntry jarEntry );
    }

    
Unjars the specified jar file into the the specified directory

Parameters:
jarFile
outputDirectory
unjarListener
Throws:
java.io.IOException
    public static void unjarJarFile jarFileFile outputDirectoryUnjarListener unjarListener ) throws IOException
    {
        for ( Enumeration en = jarFile.entries(); en.hasMoreElements(); )
        {
            JarEntry entry = ( JarEntry ) en.nextElement();
            File entryFile = new FileoutputDirectoryentry.getName() );
            if ( unjarListener.includeentry ) )
            {
                // Create the output directory if need be
                if ( ! entryFile.getParentFile().exists() )
                {
                    if ( ! entryFile.getParentFile().mkdirs() )
                    {
                        throw new IOException"Error creating output directory: " + entryFile.getParentFile() );
                    }
                }
                // If the entry is an actual file, unzip that too
                if ( ! entry.isDirectory() )
                {
                    final InputStream in = jarFile.getInputStreamentry );
                    try
                    {
                        final OutputStream out = new FileOutputStreamentryFile );
                        try
                        {
                            IOUtil.copyinout );
                        }
                        finally
                        {
                            IOUtils.closeQuietlyout );
                        }
                    }
                    finally
                    {
                        IOUtils.closeQuietlyin );
                    }
                }
            }
        }
    }
New to GrepCode? Check out our FAQ X