本文整理汇总了Java中org.apache.commons.io.output.FileWriterWithEncoding类的典型用法代码示例。如果您正苦于以下问题:Java FileWriterWithEncoding类的具体用法?Java FileWriterWithEncoding怎么用?Java FileWriterWithEncoding使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileWriterWithEncoding类属于org.apache.commons.io.output包,在下文中一共展示了FileWriterWithEncoding类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generate
import org.apache.commons.io.output.FileWriterWithEncoding; //导入依赖的package包/类
/**
* 根据模板生成文件
* @param inputVmFilePath 模板路径
* @param outputFilePath 输出文件路径
* @param context
* @throws Exception
*/
public static void generate(String inputVmFilePath, String outputFilePath, VelocityContext context) throws Exception {
try {
Properties properties = new Properties();
properties.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, getPath(inputVmFilePath));
Velocity.init(properties);
//VelocityEngine engine = new VelocityEngine();
Template template = Velocity.getTemplate(getFile(inputVmFilePath), "utf-8");
File outputFile = new File(outputFilePath);
FileWriterWithEncoding writer = new FileWriterWithEncoding(outputFile, "utf-8");
template.merge(context, writer);
writer.close();
} catch (Exception ex) {
throw ex;
}
}
示例2: writeOneFile
import org.apache.commons.io.output.FileWriterWithEncoding; //导入依赖的package包/类
/***
* create xml file at GS_HOME/batchFile
*
* @param fileName
* @param content
* @return
*/
private String writeOneFile(String fileName, String content)
{
try
{
File f = new File(batchFilePath, fileName);
BufferedWriter bw = new BufferedWriter(new FileWriterWithEncoding(f, "utf-8"));
bw.write(content);
bw.close();
LogUtil.getCoreLog().info("Batch file created at " +f.getAbsolutePath());
return f.toURI().toString();
}
catch (Exception e)
{
throw new GemliteException(e);
}
}
示例3: SqlWriter
import org.apache.commons.io.output.FileWriterWithEncoding; //导入依赖的package包/类
public SqlWriter(String tableName)
{
String nodeName = ServerConfigHelper.getConfig(ITEMS.NODE_NAME);
if (nodeName==null || nodeName.equals(""))
nodeName="basic";
String path = "test/" + nodeName;
WorkPathHelper.verifyPath(path);
File f = new File(ServerConfigHelper.getConfig(ITEMS.GS_HOME) + "/"
+ path + "/" + tableName + ".sql");
try
{
fw = new FileWriterWithEncoding(f, TEST_FILE_ENCODING);
fullFilePath = ServerConfigHelper.getConfig(ITEMS.GS_HOME) + "/"
+ path + "/" + tableName + ".sql";
} catch (IOException e)
{
e.printStackTrace();
fw = null;
fullFilePath = null;
}
}
示例4: writeToXML
import org.apache.commons.io.output.FileWriterWithEncoding; //导入依赖的package包/类
public static boolean writeToXML(Document document, String tempPath) {
try {
// 使用XMLWriter写入,可以控制格式,经过调试,发现这种方式会出现乱码,主要是因为Eclipse中xml文件和JFrame中文件编码不一致造成的
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding(EncodingUtil.CHARSET_UTF8);
// format.setSuppressDeclaration(true);//这句话会压制xml文件的声明,如果为true,就不打印出声明语句
format.setIndent(true);// 设置缩进
format.setIndent(" ");// 空行方式缩进
format.setNewlines(true);// 设置换行
XMLWriter writer = new XMLWriter(new FileWriterWithEncoding(new File(tempPath), EncodingUtil.CHARSET_UTF8), format);
writer.write(document);
writer.close();
} catch (IOException e) {
e.printStackTrace();
MyLogger.logger.error("写入xml文件出错!");
return false;
}
return true;
}
示例5: createNewStateFile
import org.apache.commons.io.output.FileWriterWithEncoding; //导入依赖的package包/类
/**
* Creates an empty state file.
*
* @param state
* the path to the state file
* @throws IOException
* if the file can't be created
*/
static void createNewStateFile(Path state) throws IOException {
File file = state.toFile();
file.createNewFile();
if (Files.exists(file.toPath(), LinkOption.NOFOLLOW_LINKS)) {
Files.delete(file.toPath());
}
FileWriterWithEncoding writer =
new FileWriterWithEncoding(file, "UTF-8", true);
writer.append("<?xml version=\"1.0\" "
+ "encoding=\"UTF-8\" standalone=\"no\"?>");
writer.append("<state>");
writer.append("<courses>");
writer.append("</courses>");
writer.append("<connections>");
writer.append("</connections>");
writer.append("</state>");
writer.close();
}
示例6: writeCompilerOutput
import org.apache.commons.io.output.FileWriterWithEncoding; //导入依赖的package包/类
/**
* Writes the compiler output into the text file.
*
* @param file
* File the compiler output gets written into.
* @param submission
* SubmissionObj the needed information gets taken from.
* @throws IOException
* If something goes wrong when writing.
*/
private static void writeCompilerOutput(File file, Submission submission)
throws IOException {
FileWriterWithEncoding writer = new FileWriterWithEncoding(file,
"UTF-8", true);
writer.append("Compilerausgabe:\n");
for (String warning : submission.getCheckingResult()
.getCompilerOutput().getCompilerWarnings()) {
writer.append(warning + "\n");
}
for (String info : submission.getCheckingResult().getCompilerOutput()
.getCompilerInfos()) {
writer.append(info + "\n");
}
writer.append("\n");
writer.close();
}
示例7: writeFailedTests
import org.apache.commons.io.output.FileWriterWithEncoding; //导入依赖的package包/类
/**
* Writes the failed tests into the text file.
*
* @param file
* File the failed tests get written into.
* @param submission
* SubmissionObj the needed information gets taken from.
* @throws IOException
* If something goes wrong when writing.
*/
private static void writeFailedTests(File file, Submission submission)
throws IOException {
FileWriterWithEncoding writer = new FileWriterWithEncoding(file,
"UTF-8", true);
writer.append("Fehlerhafte Tests\n");
for (int i = 0; i < submission.getCheckingResult().getTestResults()
.getResults().size(); i++) {
if (!(submission.getCheckingResult().getTestResults().getResults()
.get(i).wasSuccessful())) {
writer.append("- Test" + i + "\n");
for (Failure fail : submission.getCheckingResult()
.getTestResults().getResults().get(i).getFailures()) {
writer.append(fail.toString() + "\n");
}
}
}
writer.close();
}
示例8: writeOverview
import org.apache.commons.io.output.FileWriterWithEncoding; //导入依赖的package包/类
/**
* Writes the Overview into the text file.
*
* @param file
* File the overview gets written into.
* @param submission
* SubmissionObj the needed information gets taken from.
* @throws IOException
* If something goes wrong when writing.
*/
private static void writeOverview(File file, Submission submission)
throws IOException {
FileWriterWithEncoding writer = new FileWriterWithEncoding(file,
"UTF-8", true);
writer.append("Übersicht\n");
if (submission.getCheckingResult().getCompilerOutput().isCleanCompile()) {
writer.append("Abgabe kompiliert\n");
} else {
writer.append("Abgabe kompiliert nicht\n");
}
writer.append("Testergebnis: "
+ submission.getCheckingResult().getTestResults()
.getPassedTestCount()
+ " von "
+ submission.getCheckingResult().getTestResults()
.getTestCount() + " Tests bestanden\n");
writer.close();
}
示例9: writeTestResult
import org.apache.commons.io.output.FileWriterWithEncoding; //导入依赖的package包/类
/**
* Writes the test result into the text file.
*
* @param file
* File the test results get written into.
* @param submission
* SubmissionObj the needed information gets taken from.
* @throws IOException
* If something goes wrong when writing.
*/
private static void writeTestResult(File file, Submission submission)
throws IOException {
FileWriterWithEncoding writer = new FileWriterWithEncoding(file,
"UTF-8", true);
writer.append("Testergebnis\n");
if (submission.getCheckingResult().getTestResults().getDidTest()) {
for (int i = 0; i < submission.getCheckingResult().getTestResults()
.getResults().size(); i++) {
if (submission.getCheckingResult().getTestResults()
.getResults().get(i).wasSuccessful()) {
writer.append("Test " + i + "\tpassed\n");
} else {
writer.append("Test " + i + "\tfailed\n");
}
}
} else {
writer.append("Keine Tests vorhanden.\n");
}
writer.close();
}
示例10: writeFiles
import org.apache.commons.io.output.FileWriterWithEncoding; //导入依赖的package包/类
/**
* Write the pdfs to the file.
*
* @param outFile
* the out file
* @param folderWithPdfs
* the folder with pdfs
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static void writeFiles(File outFile, Path folderWithPdfs)
throws IOException {
FileWriterWithEncoding writer =
new FileWriterWithEncoding(outFile, "UTF-8", true);
File[] files = folderWithPdfs.toFile().listFiles();
if(files.length > 0){
for (File file : files) {
// We only want the the PDFs as input
if ("pdf".equals(FilenameUtils.getExtension(file.getName()))) {
writer.append("\\includepdf[pages={1-}]{")
.append(file.getAbsolutePath()).append("} \n");
}
} } else {
LOGGER.warning("No Reports available in the specified folder: " + folderWithPdfs.toString());
}
writer.close();
}
示例11: writeCompilerErrors
import org.apache.commons.io.output.FileWriterWithEncoding; //导入依赖的package包/类
/**
* Writes the compiler errors into the TeX file.
*
* @param file
* File the compiler errors get written into.
* @param submission
* SubmissionObj the needed information gets taken from.
* @throws IOException
* If something goes wrong when writing.
*/
private static void writeCompilerErrors(File file, Submission submission)
throws IOException {
FileWriterWithEncoding writer = new FileWriterWithEncoding(file,
"UTF-8", true);
writer.append("\\paragraph{Compilerfehler}~\\\\\n");
writer.append("\\begin{lstlisting}[language=bash, breaklines=true, "
+ "basicstyle=\\color{black}\\footnotesize\\ttfamily,numberstyle"
+ "=\\tiny\\color{black}]\n");
for (String error : submission.getCheckingResult().getCompilerOutput()
.getCompilerErrors()) {
writer.append(error + "\n");
}
writer.append("\\end{lstlisting}\n");
writer.close();
}
示例12: writeCompilerOutput
import org.apache.commons.io.output.FileWriterWithEncoding; //导入依赖的package包/类
/**
* Writes the compiler output into the TeX file.
*
* @param file
* File the compiler output gets written into.
* @param submission
* SubmissionObj the needed information gets taken from.
* @throws IOException
* If something goes wrong when writing.
*/
private static void writeCompilerOutput(File file, Submission submission)
throws IOException {
FileWriterWithEncoding writer = new FileWriterWithEncoding(file,
"UTF-8", true);
writer.append("\\paragraph{Compilerausgabe}~\\\\\n");
writer.append("\\color{black}\n");
writer.append("\\begin{lstlisting}[language=bash, "
+ "breaklines=true]{Warnings}\n");
for (String warning : submission.getCheckingResult()
.getCompilerOutput().getCompilerWarnings()) {
writer.append(warning + "\n");
}
writer.append("\\end{lstlisting}\n");
writer.append("\\begin{lstlisting}[language=bash, "
+ "breaklines=true]{Infos}\n");
for (String info : submission.getCheckingResult().getCompilerOutput()
.getCompilerInfos()) {
writer.append(info + "\n");
}
writer.append("\\end{lstlisting}\n");
writer.close();
}
示例13: writeHeader
import org.apache.commons.io.output.FileWriterWithEncoding; //导入依赖的package包/类
/**
* Writes the header into the TeX file.
*
* @param file
* File the overhead gets written into.
* @param submission
* SubmissionObj the needed information gets taken from.
* @param courseName
* the name of the course the exercise belongs to
* @param exerciseName
* the name of the exercise
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static void writeHeader(File file, Submission submission,
final String courseName, final String exerciseName)
throws IOException {
FileWriterWithEncoding writer = new FileWriterWithEncoding(file,
"UTF-8", true);
writer.append("\\newcommand{\\studycourse}{" + courseName + "}\n");
writer.append("\\newcommand{\\assignmentnumber}{" + exerciseName
+ "}\n");
writer.append("\\begin{document}\n");
writer.append("\\begin{student}{" + submission.getStudent().getName()
+ "}\n");
writer.close();
}
示例14: writeOverview
import org.apache.commons.io.output.FileWriterWithEncoding; //导入依赖的package包/类
/**
* Writes the Overview into the .tex file.
*
* @param file
* File the overview gets written into.
* @param submission
* SubmissionObj the needed information gets taken from.
* @throws IOException
* If something goes wrong when writing.
*/
private static void writeOverview(File file, Submission submission)
throws IOException {
FileWriterWithEncoding writer = new FileWriterWithEncoding(file,
"UTF-8", true);
writer.append("\\paragraph{Übersicht}~\\\\\n");
CheckingResult checkingResult = submission.getCheckingResult();
if (checkingResult.getCompilerOutput().isCleanCompile()) {
writer.append("Abgabe kompiliert \\hfill \\textcolor{green}{JA}\\\\");
} else {
writer.append("Abgabe kompiliert \\hfill \\textcolor{red}{NEIN}\\\\ \n");
}
writer.append("Testergebnis \\hfill "
+ checkingResult.getTestResults().getPassedTestCount()
+ " von " + checkingResult.getTestResults().getTestCount()
+ " Tests bestanden\n");
writer.close();
}
示例15: createCitationFile
import org.apache.commons.io.output.FileWriterWithEncoding; //导入依赖的package包/类
/**
* Creates the dataset citation file using the the Solr query response.
*
* @param datasetUsages record count per dataset
* @param citationFileName output file name
* @param datasetOccUsageService usage service
* @param downloadKey download key
*/
public static void createCitationFile(Map<UUID, Long> datasetUsages, String citationFileName,
DatasetOccurrenceDownloadUsageService datasetOccUsageService,
DatasetService datasetService, String downloadKey) {
if (datasetUsages != null && !datasetUsages.isEmpty()) {
try (ICsvBeanWriter beanWriter = new CsvBeanWriter(new FileWriterWithEncoding(citationFileName, Charsets.UTF_8),
CsvPreference.TAB_PREFERENCE)) {
for (Entry<UUID, Long> entry : datasetUsages.entrySet()) {
if (entry.getKey() != null) {
beanWriter.write(new Facet.Count(entry.getKey().toString(), entry.getValue()), HEADER, PROCESSORS);
persistDatasetUsage(entry, downloadKey, datasetOccUsageService, datasetService);
}
}
beanWriter.flush();
} catch (IOException e) {
LOG.error("Error creating citations file", e);
throw Throwables.propagate(e);
}
}
}