Mycat class diagram research and JarLoader for source code reading

JarLoader for Mycat source code reading 

package io.mycat.config.classloader;

import java.util.jar. *;

import java.lang.reflect.*;

import java.net.URL;

import java.net.URLClassLoader;

import java.io. *;

 

import java.util. *;

public class JarLoader {

 

   /** Unpack a jar file into a directory. */

    public static void unJar(File jarFile, File toDir) throws IOException {

           JarFile jar = new JarFile(jarFile);

        try {

              Enumeration entries = jar.entries();

             while (entries.hasMoreElements()) {

             JarEntry entry = (JarEntry)entries.nextElement();

       if (!entry.isDirectory()) {

                   InputStream in = jar.getInputStream(entry);

         try {

                   File file = new File(toDir, entry.getName());

                     if (!file.getParentFile().mkdirs() && !file.getParentFile().isDirectory()) {

 

               throw new IOException("Mkdirs failed to create " + 

                                     file.getParentFile().toString());

 

           }

           OutputStream out = new FileOutputStream(file);

           try {

             byte[] buffer = new byte[8192];

             int i;

             while ((i = in.read(buffer)) != -1) {

               out.write(buffer, 0, i);

             }

           } finally {

             out.close();

           }

         } finally {

           in.close();

         }

       }

     }

   } finally {

     jar.close();

   }

 }

}



 

Test code:

public class JarDemo {

 

/**

* @param args

* @throws IOException 

*/

public static void main(String[] args) throws IOException {

 

File  jarFile = new File("C:/Intel/joda-time-2.3.jar");

File  toDir = new File("C:/Intel");

JarLoader.unJar(jarFile, toDir);

 

}

 

}



 

unzipped folder



 

 

Mycat class diagram research



 

 



 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326797386&siteId=291194637