Java FileWriter Write saveMetaClassToFile(File baseDir, String clazzDef, String metaPackageName, Class fromClazz)

Here you can find the source of saveMetaClassToFile(File baseDir, String clazzDef, String metaPackageName, Class fromClazz)

Description

save Meta Class To File

License

Open Source License

Declaration

public static void saveMetaClassToFile(File baseDir, String clazzDef, String metaPackageName,
            Class<?> fromClazz) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.io.FileWriter;

public class Main {
    public static void saveMetaClassToFile(File baseDir, String clazzDef, String metaPackageName,
            Class<?> fromClazz) throws Exception {
        String clazzPcg = packageNameHelper(fromClazz, metaPackageName);

        String[] pcg = clazzPcg.split("\\.");
        File dest = baseDir;//from  ww  w  .ja  v a 2  s . com
        for (String p : pcg) {
            dest = new File(dest, p);
            if (!dest.exists())
                dest.mkdir();
        }

        dest = new File(dest, classNameHelper(fromClazz) + ".java");

        FileWriter write = new FileWriter(dest);
        write.write(clazzDef);
        write.close();
    }

    protected static String packageNameHelper(Class<?> from, String metaPackageName) {
        String pcgName = "";

        if (metaPackageName != null) {
            pcgName = from.getPackage().getName() + "." + metaPackageName;
        } else {
            pcgName = from.getPackage().getName();
        }

        return pcgName;
    }

    protected static String classNameHelper(Class<?> from) {
        return from.getSimpleName() + "_";
    }
}

Related

  1. saveListToFile(ArrayList list, String filePath)
  2. saveMap(Map map, String filePath)
  3. saveMap(String filename, Map map)
  4. saveMappingFile(File mappingFile, Map messageMap)
  5. saveMeasures(String appDirPath, String fileName, double[] measures)
  6. saveMetadata(Map metadata, File file)
  7. saveModelInFile(final String model, final String filename)
  8. savePValue2File(double[] pValue, String fileName)
  9. saveSeqAln(String[] alnSequences, String filePath)