Java Code Examples for jodd.io.FileUtil#writeString()

The following examples show how to use jodd.io.FileUtil#writeString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EsRestSpecGen.java    From wES with MIT License 6 votes vote down vote up
public void writeJavaFile() {
	try {
		String pkg2 = pkg + ".actions";
		StringBuilder javaCodes = new StringBuilder();
		javaCodes.append("package " + pkg2 + ";\n\n");

		javaCodes.append("import okhttp3.HttpUrl;\n" +
				"import org.datasays.wes.core.RequestInfo;\n" +
				"import org.datasays.wes.types.*;\n");
		javaCodes.append(codes.toString());
		javaCodes.append("}\n");
		String filePath = sourceDir + pkg2.replace('.', File.separatorChar) + File.separatorChar;
		FileUtil.mkdirs(filePath);
		FileUtil.writeString(filePath + clsName + ".java", javaCodes.toString(), "utf-8");
		codes = new StringBuilder();
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example 2
Source File: EsRestSpecGen4Retrofit.java    From wES with MIT License 6 votes vote down vote up
public void writeToFile(String file) {
	StringBuilder javaCodes = new StringBuilder();
	javaCodes.append("package org.datasays.wes.client;\n\n");

	javaCodes.append("import retrofit2.Call;\n");
	javaCodes.append("import retrofit2.http.Body;\n");
	javaCodes.append("import retrofit2.http.DELETE;\n");
	javaCodes.append("import retrofit2.http.GET;\n");
	javaCodes.append("import retrofit2.http.HEAD;\n");
	javaCodes.append("import retrofit2.http.POST;\n");
	javaCodes.append("import retrofit2.http.PUT;\n");
	javaCodes.append("import retrofit2.http.Path;\n\n");

	javaCodes.append("public interface EsService {\n");
	javaCodes.append("	" + codes.toString() + "\n");

	javaCodes.append("}\n");
	try {
		FileUtil.writeString(file, javaCodes.toString(), "utf-8");
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example 3
Source File: VcfUtils.java    From DAFramework with MIT License 5 votes vote down vote up
public static void exportVcf(List<VcfBean> beans, File vcfFile) {
	try {
		StringBuffer sb = new StringBuffer();
		for (VcfBean bean : beans) {
			sb.append("BEGIN:VCARD\r\n");
			sb.append("VERSION:3.0\r\n");
			sb.append("N;CHARSET=UTF-8:;‭‬‭‬‭" + bean.getFullName() + ";;;\r\n");
			sb.append("FN;CHARSET=UTF-8: ‭‬‭‬‭" + bean.getFullName() + "\r\n");
			if ("" != bean.getOrg() && bean.getOrg() != null) {
				sb.append("ORG:" + bean.getOrg() + "\r\n");
			}
			if ("" != bean.getTitle() && bean.getTitle() != null) {
				sb.append("TITLE:" + bean.getTitle() + "\r\n");
			}
			if ("" != bean.getAddress() && bean.getAddress() != null) {
				sb.append("ADR;HOME:;;;" + bean.getAddress() + ";;;\r\n");
			}
			if ("" != bean.getNote() && bean.getNote() != null) {
				sb.append("NOTE:" + bean.getNote() + "\r\n");
			}
			if ("" != bean.getMobile() && bean.getMobile() != null) {
				sb.append("TEL;CELL:" + bean.getMobile() + "\r\n");
			}

			if ("" != bean.getTelePhone() && bean.getTelePhone() != null) {
				sb.append("TEL;HOME:" + bean.getTelePhone() + "\r\n");
			}
			if ("" != bean.getEmail() && bean.getEmail() != null) {
				sb.append("EMAIL:" + bean.getEmail() + "\r\n");
			}
			sb.append("END:VCARD\r\n");
		}
		FileUtil.writeString(vcfFile, sb.toString(), "utf-8");
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 4
Source File: WJsonUtils.java    From DAFramework with MIT License 5 votes vote down vote up
public static void writeJson(String file, Object obj) {
	try {
		FileUtil.writeString(file, getGsonBuilder().create().toJson(obj), "utf-8");
	} catch (IOException e) {
		LOG.error(e.getMessage(), e);
	}
}
 
Example 5
Source File: VcfUtils.java    From wES with MIT License 5 votes vote down vote up
public static void exportVcf(List<VcfBean> beans, File vcfFile) {
	try {
		StringBuffer sb = new StringBuffer();
		for (VcfBean bean : beans) {
			sb.append("BEGIN:VCARD\r\n");
			sb.append("VERSION:3.0\r\n");
			sb.append("N;CHARSET=UTF-8:;‭‬‭‬‭" + bean.getFullName() + ";;;\r\n");
			sb.append("FN;CHARSET=UTF-8: ‭‬‭‬‭" + bean.getFullName() + "\r\n");
			if ("" != bean.getOrg() && bean.getOrg() != null) {
				sb.append("ORG:" + bean.getOrg() + "\r\n");
			}
			if ("" != bean.getTitle() && bean.getTitle() != null) {
				sb.append("TITLE:" + bean.getTitle() + "\r\n");
			}
			if ("" != bean.getAddress() && bean.getAddress() != null) {
				sb.append("ADR;HOME:;;;" + bean.getAddress() + ";;;\r\n");
			}
			if ("" != bean.getNote() && bean.getNote() != null) {
				sb.append("NOTE:" + bean.getNote() + "\r\n");
			}
			if ("" != bean.getMobile() && bean.getMobile() != null) {
				sb.append("TEL;CELL:" + bean.getMobile() + "\r\n");
			}

			if ("" != bean.getTelePhone() && bean.getTelePhone() != null) {
				sb.append("TEL;HOME:" + bean.getTelePhone() + "\r\n");
			}
			if ("" != bean.getEmail() && bean.getEmail() != null) {
				sb.append("EMAIL:" + bean.getEmail() + "\r\n");
			}
			sb.append("END:VCARD\r\n");
		}
		FileUtil.writeString(vcfFile, sb.toString(), "utf-8");
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 6
Source File: WJsonUtils.java    From wES with MIT License 5 votes vote down vote up
public static void writeJson(String file, Object obj) {
	try {
		FileUtil.writeString(file, getGsonBuilder().create().toJson(obj), "utf-8");
	} catch (IOException e) {
		LOG.error(e.getMessage(), e);
	}
}
 
Example 7
Source File: EsRestSpecGen.java    From wES with MIT License 5 votes vote down vote up
public void writeEnumType(String type, List<String> options, String defaultValue, String description) {
	try {
		String pkg2 = pkg + ".types";
		StringBuilder javaCodes = new StringBuilder();
		javaCodes.append("package " + pkg2 + ";\n\n");

		javaCodes.append("//" + description + "\n");
		javaCodes.append("//default: " + defaultValue + "\n");
		javaCodes.append("public enum " + type + " {\n");
		String enumCodes = "";
		for (String option : options) {
			String enumName = option.toUpperCase();
			if (option.trim().length() <= 0) {
				enumName = "v";
			}
			enumCodes += "\t" + enumName + "(\"" + option + "\"),\n";
		}
		enumCodes = StringUtil.cutSuffix(enumCodes, ",\n");
		javaCodes.append(enumCodes + ";\n");

		javaCodes.append("\tprivate String name;\n");
		javaCodes.append("\t" + type + "(String name) {\n");
		javaCodes.append("\t\tthis.name = name;\n");
		javaCodes.append("\t}\n\n");
		javaCodes.append("\t@Override\n");
		javaCodes.append("\tpublic String toString() {\n");
		javaCodes.append("\treturn this.name;\n");
		javaCodes.append("\t}\n");
		javaCodes.append("}");
		String filePath = sourceDir + pkg2.replace('.', File.separatorChar) + File.separatorChar;
		FileUtil.mkdirs(filePath);
		FileUtil.writeString(filePath + type + ".java", javaCodes.toString(), "utf-8");
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example 8
Source File: EsRestSpecGen.java    From wES with MIT License 5 votes vote down vote up
public void writeEsHelper() {
	try {
		String pkg2 = pkg + ".client";
		StringBuilder javaCodes = new StringBuilder();
		javaCodes.append("package " + pkg2 + ";\n\n");

		javaCodes.append("import okhttp3.HttpUrl;\n");
		javaCodes.append("import okhttp3.OkHttpClient;\n");
		javaCodes.append("import org.datasays.wes.actions.*;\n");
		javaCodes.append("import org.datasays.wes.core.IConvert;\n");
		javaCodes.append("import org.datasays.wes.core.WHttpClient;\n\n");

		javaCodes.append("public class EsHelper extends WHttpClient {\n");
		javaCodes.append("\tprotected HttpUrl server;\n");
		javaCodes.append("\n");
		javaCodes.append("\tpublic EsHelper() {\n");
		javaCodes.append("\t\tsuper();\n");
		javaCodes.append("\t}\n\n");
		javaCodes.append("\tpublic void init(String server, OkHttpClient client, IConvert convert) {\n");
		javaCodes.append("\t\tif (server.trim().endsWith(\"/\")) {\n");
		javaCodes.append("\t\t\tserver = server.trim().substring(0, server.trim().length() - 1);\n");
		javaCodes.append("\t\t}\n");
		javaCodes.append("\t\tthis.server = HttpUrl.parse(server);\n");
		javaCodes.append("\t\tsuper.init(client, convert);\n");
		javaCodes.append("\t}\n\n");

		javaCodes.append(helperCodes.toString());

		javaCodes.append("}\n");

		String filePath = sourceDir + pkg2.replace('.', File.separatorChar) + File.separatorChar;
		FileUtil.mkdirs(filePath);
		FileUtil.writeString(filePath + "EsHelper.java", javaCodes.toString(), "utf-8");
	} catch (IOException e) {
		e.printStackTrace();
	}
}