Java FileOutputStream Write saveProxyClass(String path, String proxyClassName, Class[] interfaces)

Here you can find the source of saveProxyClass(String path, String proxyClassName, Class[] interfaces)

Description

Save proxy class to path

License

Apache License

Parameter

Parameter Description
path path to save proxy class
proxyClassName name of proxy class
interfaces interfaces of proxy class

Declaration

public static boolean saveProxyClass(String path, String proxyClassName, Class[] interfaces) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.FileOutputStream;
import java.io.IOException;
import sun.misc.ProxyGenerator;

public class Main {
    /**/*from  ww w .  java2s .  c  om*/
     * Save proxy class to path
     * 
     * @param path path to save proxy class
     * @param proxyClassName name of proxy class
     * @param interfaces interfaces of proxy class
     * @return
     */
    public static boolean saveProxyClass(String path, String proxyClassName, Class[] interfaces) {
        if (proxyClassName == null || path == null) {
            return false;
        }

        // get byte of proxy class
        byte[] classFile = ProxyGenerator.generateProxyClass(proxyClassName, interfaces);
        FileOutputStream out = null;
        try {
            out = new FileOutputStream(path);
            out.write(classFile);
            out.flush();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return false;
    }
}

Related

  1. saveInputStream(InputStream is, String filePath)
  2. saveInt16bit(String filename, int[] intData)
  3. saveIntArrayToFile(int[] array, File file)
  4. saveKeyToFile(String key)
  5. saveLongList(String file, Collection c, boolean append)
  6. saveResouce(String resourceName, String outputFile)
  7. saveStream(InputStream is, File output)
  8. saveStream(InputStream stream, File targetFile)
  9. saveStreamToFile(InputStream in, File outFile)