本文整理汇总了Java中org.apache.commons.io.output.FileWriterWithEncoding.close方法的典型用法代码示例。如果您正苦于以下问题:Java FileWriterWithEncoding.close方法的具体用法?Java FileWriterWithEncoding.close怎么用?Java FileWriterWithEncoding.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.io.output.FileWriterWithEncoding
的用法示例。
在下文中一共展示了FileWriterWithEncoding.close方法的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: 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();
}
示例3: 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();
}
示例4: 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();
}
示例5: 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();
}
示例6: 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();
}
示例7: 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();
}
示例8: 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();
}
示例9: 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();
}
示例10: 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();
}
示例11: 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();
}
示例12: createBigStack
import org.apache.commons.io.output.FileWriterWithEncoding; //导入方法依赖的package包/类
private static File createBigStack(final String path, final int count, final Charset charset) throws Exception {
if (count < 0 || path == null || path.length() == 0) {
throw new IllegalArgumentException();
}
final File json = new File(path + "/" + "generated_benchmark_test_file_bigstack_" + charset.name() + "_" + count + ".json");
if (json.exists()) {
System.out.println("File already exists: " + json.getAbsolutePath());
return json;
}
final FileWriterWithEncoding sb = new FileWriterWithEncoding(json, charset);
for (int i = 0; i < count; i++) {
sb.append("{\"key\":");
sb.append("[true" + (i == count - 1 ? "" : ","));
}
for (int i = 0; i < count; i++) {
sb.append("]");
sb.append("}");
}
sb.close();
return json;
}
示例13: writeCompilerErrors
import org.apache.commons.io.output.FileWriterWithEncoding; //导入方法依赖的package包/类
/**
* Writes the compiler errors into the text 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("Compilerfehler\n");
for (String error : submission.getCheckingResult().getCompilerOutput()
.getCompilerErrors()) {
writer.append(error + "\n");
}
writer.close();
}
示例14: writePreamble
import org.apache.commons.io.output.FileWriterWithEncoding; //导入方法依赖的package包/类
/**
* Writes the preamble and title to the file.
*
* @param file
* the file
* @param exerciseName
* the name of the exercise
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static void writePreamble(File file, String exerciseName)
throws IOException {
FileWriterWithEncoding writer =
new FileWriterWithEncoding(file, "UTF-8", true);
writer.append("\\documentclass[a4paper,10pt,ngerman]{scrartcl} \n");
writer.append("\\usepackage[ngerman]{babel}\n");
writer.append("\\usepackage[utf8]{inputenc}");
writer.append("\\usepackage{pdfpages} \n");
writer.append("\\usepackage{grffile} \n");
writer.append("\\begin{document} \n");
writer.append("\\begin{titlepage}\n");
writer.append("\\begin{center}\n");
writer.append("\\textsc{\\LARGE Universität Konstanz}\\\\[1.5cm]\n\n");
writer.append("{\\large Korrektur\n\n");
writer.append("\\rule{\\linewidth}{0.5mm}\\\\[0.4cm]\n");
writer.append("{\\fontfamily{qhv}\\huge\\bfseries ")
.append(exerciseName).append(" \\\\[0.4cm]}\n\n");
writer.append("\\rule{\\linewidth}{0.5mm}\\\\[0.5cm]\n\n");
writer.append("\\vfill\n");
writer.append("{\\large\\today\n");
writer.append("\\end{center}\n");
writer.append("\\end{titlepage}\n");
writer.close();
}
示例15: writeClosing
import org.apache.commons.io.output.FileWriterWithEncoding; //导入方法依赖的package包/类
/**
* Writes the closing part of the file.
*
* @param file
* the file
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static void writeClosing(File file) throws IOException {
FileWriterWithEncoding writer =
new FileWriterWithEncoding(file, "UTF-8", true);
writer.append("\\label{lastpage}");
writer.append("\\end{document}\n");
writer.close();
}