Java 类org.apache.commons.io.output.FileWriterWithEncoding 实例源码

项目:-Spring-SpringMVC-Mybatis-    文件:VelocityUtil.java   
/**
 * 根据模板生成文件
 * @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;
    }
}
项目:rent    文件:VelocityUtil.java   
/**
 * 根据模板生成文件
 * @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;
    }
}
项目:zheng-lite    文件:VelocityUtil.java   
/**
 * 根据模板生成文件
 * @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;
    }
}
项目:lambo    文件:VelocityUtil.java   
/**
 * 根据模板生成文件
 * @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;
    }
}
项目:rure    文件:VelocityUtil.java   
/**
 * 根据模板生成文件
 * @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;
    }
}
项目:shuzheng    文件:VelocityUtil.java   
/**
 * 根据模板生成文件
 * @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;
    }
}
项目:zheng    文件:VelocityUtil.java   
/**
 * 根据模板生成文件
 * @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;
    }
}
项目:GemFireLite    文件:BatchGenenator.java   
/***
 * 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);
  }
}
项目:GemFireLite    文件:SqlWriter.java   
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;
    }
}
项目:CEC-Automatic-Annotation    文件:WriteToXMLUtil.java   
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;
}
项目:grit    文件:BootHelpers.java   
/**
 * 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();
}
项目:grit    文件:PlainGenerator.java   
/**
 * 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();

}
项目:grit    文件:PlainGenerator.java   
/**
 * 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();
}
项目:grit    文件:PlainGenerator.java   
/**
 * 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();
}
项目:grit    文件:PlainGenerator.java   
/**
 * 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();
}
项目:grit    文件:PdfConcatenator.java   
/**
 * 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();
}
项目:grit    文件:TexGenerator.java   
/**
 * 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();
}
项目:grit    文件:TexGenerator.java   
/**
 * 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();
}
项目:grit    文件:TexGenerator.java   
/**
 * 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();
}
项目:grit    文件:TexGenerator.java   
/**
 * 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();
}
项目:occurrence    文件:CitationsFileWriter.java   
/**
 * 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);
    }
  }
}
项目:Blizcord    文件:Save.java   
@Override
public void execute(String arg, User author, MessageChannel channel, Guild guild) {
    // arg = playlist name
    if(arg == null) {
        channel.sendMessage(author.getAsMention() + " ``Please specify a playlist name. Put it behind this command.``").queue();
        return;
    }
    if(!AudioPlayerThread.isPlaying()) {
        channel.sendMessage(author.getAsMention() + " ``The playlist is empty, nothing to save.``").queue();
        return;
    }
    File playlistsFolder = new File(Config.getAppDir(), "playlists");
    if(!playlistsFolder.exists()) {
        if(!playlistsFolder.mkdir()) {
            channel.sendMessage(author.getAsMention() + " ``Failed to create playlists folder.``").queue();
            return;
        }
    }
    try {
        BufferedWriter writer = new BufferedWriter(new FileWriterWithEncoding(new File(playlistsFolder, arg), StandardCharsets.UTF_8, false));
        // Write currently playing track
        writer.write(AudioPlayerThread.getMusicManager().player.getPlayingTrack().getInfo().uri);
        writer.newLine();
        // Write upcoming tracks
        ArrayList<AudioTrack> upcoming = AudioPlayerThread.getMusicManager().scheduler.getList();
        if(!upcoming.isEmpty()) {
            for(int i = 0; i < upcoming.size(); i++) {
                writer.write(upcoming.get(i).getInfo().uri);
                writer.newLine();
            }
        }
        // Save
        writer.close();

        channel.sendMessage(author.getAsMention() + " Playlist saved: ``" + arg + "``").queue();
    } catch (Exception e) {
        channel.sendMessage(author.getAsMention() + " ``Failed to save playlist.``").queue();
    }
}
项目:DolphinNG    文件:IOUtil.java   
/**
 * Writes 'content' into 'fileName'.
 *
 * @param fileName
 * @param content
 * @param charSet         ex: UTF-8, UTF-16
 * @param append
 * @param newLineRequired
 * @throws IOException
 */
public static void writeFile(String fileName, String content, String charSet, boolean append, boolean
        newLineRequired) throws IOException
{
    File file = new File(fileName);
    if (!file.exists())
    {
        if (fileName.contains("/"))
        {
            int directoryIndex = fileName.lastIndexOf("/");
            String directory = fileName.substring(0, directoryIndex);
            File dir = new File(directory);
            dir.mkdirs();
        }
        file.createNewFile();
    }
    if (!StringUtils.isNotBlank(charSet))
    {
        charSet = "UTF-8";
    }
    BufferedWriter writer = new BufferedWriter(new FileWriterWithEncoding(file, charSet, append));
    writer.write(content);
    if (newLineRequired)
    {
        writer.write('\n');
    }
    writer.flush();
    writer.close();
}
项目:InspiringWorld    文件:LanguageReporter.java   
public void end()
{
    try
    {
        for (File lang : fileLang)
        {
            BufferedWriter writer = new BufferedWriter(new FileWriterWithEncoding(lang, "UTF-8"));
            Collections.sort(langNodes);
            char last = 0;
            boolean init = false;
            for (String name : langNodes)
            {
                if (init && name.charAt(0) != last)
                    writer.write("\n");
                last = name.charAt(0);
                init = true;
                writer.write(name);
                writer.newLine();
            }
            writer.flush();
            writer.close();
        }
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
    this.langNodes.clear();
    this.fileLang.clear();
}
项目:triquetrum    文件:WorkflowRepositoryServiceImpl.java   
/**
 * @param flowCode
 * @param flowMetaDataProps
 * @throws IOException
 */
private void writeMetaData(String flowCode, Properties flowMetaDataProps) throws IOException {
  File flowRootFolder = new File(rootFolder, flowCode);
  File metaDataFile = new File(flowRootFolder, ".metadata");
  Writer metaDataWriter = new FileWriterWithEncoding(metaDataFile, StandardCharsets.UTF_8);
  try {
    flowMetaDataProps.store(metaDataWriter, flowCode);
  } finally {
    metaDataWriter.close();
  }
}
项目:baleen    文件:EntityCount.java   
@Override
public void doProcess(JCas jCas) throws AnalysisEngineProcessException {
    DocumentAnnotation da = getDocumentAnnotation(jCas);

    try( PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriterWithEncoding(output, StandardCharsets.UTF_8, true))) ) {
        int count = JCasUtil.select(jCas, Entity.class).size();
        pw.println(da.getSourceUri()+"\t"+count);
    } catch (IOException e) {
        getMonitor().warn("Unable to write to output", e);
    }
}
项目:GemFireLite    文件:ResultWriter.java   
public ResultWriter(String tableName, String indexName, boolean bIndex)
{
    String nodeName = ServerConfigHelper.getConfig(ITEMS.NODE_NAME);
    if (nodeName==null || nodeName.equals(""))
        nodeName="basic";

    String path = "test/" + nodeName + "/result";
    String fileName = "";
    if (bIndex)
        fileName = tableName + "_" + indexName + ".txt";
    else
        fileName = tableName + ".txt";
    WorkPathHelper.verifyPath(path);
    File f = new File(ServerConfigHelper.getConfig(ITEMS.GS_HOME) + "/"
            + path + "/" + fileName);
    try
    {
        fw = new FileWriterWithEncoding(f, TEST_FILE_ENCODING);
        fullFilePath = ServerConfigHelper.getConfig(ITEMS.GS_HOME) + "/"
                + path + "/" + fileName;
    } catch (IOException e)
    {
        e.printStackTrace();
        fw = null;
        fullFilePath = null;
    }
}
项目:repoindexer    文件:WebHandler.java   
public static void createWebpage(File input, File output,String title, List<ResolvedArtifact> artifactList, String projectName) {
    try {
        MustacheFactory mf = new DefaultMustacheFactory();
        Mustache mustache = mf.compile(new StringReader(FileUtils.readFileToString(input)), "example");
        //mustache.execute(new PrintWriter(System.out), new MustacheData(title, artifactList)).flush();
        mustache.execute(new FileWriterWithEncoding(output, Charsets.UTF_8), new MustacheData(title, artifactList)).flush();

    } catch (Exception e) {
        e.printStackTrace();
    }

}
项目:hops    文件:CGenerator.java   
/**
 * Generate C code. This method only creates the requested file(s)
 * and spits-out file-level elements (such as include statements etc.)
 * record-level code is generated by JRecord.
 */
@Override
void genCode(String name, ArrayList<JFile> ilist,
             ArrayList<JRecord> rlist, String destDir, ArrayList<String> options)
  throws IOException {
  name = new File(destDir, (new File(name)).getName()).getAbsolutePath();
  try (Writer cc = new FileWriterWithEncoding(name+".c", Charsets.UTF_8);
       Writer hh = new FileWriterWithEncoding(name+".h", Charsets.UTF_8)) {
    hh.write("#ifndef __"+
        StringUtils.toUpperCase(name).replace('.','_')+"__\n");
    hh.write("#define __"+
        StringUtils.toUpperCase(name).replace('.','_')+"__\n");
    hh.write("#include \"recordio.h\"\n");
    for (Iterator<JFile> iter = ilist.iterator(); iter.hasNext();) {
      hh.write("#include \""+iter.next().getName()+".h\"\n");
    }

    cc.write("#include \""+name+".h\"\n");

    /*
    for (Iterator<JRecord> iter = rlist.iterator(); iter.hasNext();) {
    iter.next().genCppCode(hh, cc);
    }
     */

    hh.write("#endif //"+
        StringUtils.toUpperCase(name).replace('.','_')+"__\n");
  }
}
项目:hops    文件:CppGenerator.java   
/**
 * Generate C++ code. This method only creates the requested file(s)
 * and spits-out file-level elements (such as include statements etc.)
 * record-level code is generated by JRecord.
 */
@Override
void genCode(String name, ArrayList<JFile> ilist,
             ArrayList<JRecord> rlist, String destDir, ArrayList<String> options)
  throws IOException {
  name = new File(destDir, (new File(name)).getName()).getAbsolutePath();

  try (Writer cc = new FileWriterWithEncoding(name+".cc", Charsets.UTF_8);
       Writer hh = new FileWriterWithEncoding(name+".hh", Charsets.UTF_8)) {
    String fileName = (new File(name)).getName();
    hh.write("#ifndef __"+
        StringUtils.toUpperCase(fileName).replace('.','_')+"__\n");
    hh.write("#define __"+
        StringUtils.toUpperCase(fileName).replace('.','_')+"__\n");
    hh.write("#include \"recordio.hh\"\n");
    hh.write("#include \"recordTypeInfo.hh\"\n");
    for (Iterator<JFile> iter = ilist.iterator(); iter.hasNext();) {
      hh.write("#include \""+iter.next().getName()+".hh\"\n");
    }

    cc.write("#include \""+fileName+".hh\"\n");
    cc.write("#include \"utils.hh\"\n");

    for (Iterator<JRecord> iter = rlist.iterator(); iter.hasNext();) {
      iter.next().genCppCode(hh, cc, options);
    }

    hh.write("#endif //"+
        StringUtils.toUpperCase(fileName).replace('.','_')+"__\n");
  }
}
项目:jsr353-benchmark    文件:CreateJsonTestFiles.java   
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;

    }
项目:sahagin-java    文件:YamlUtils.java   
public static void dump(Map<String, Object> yamlObj, File dumpFile) {
    if (dumpFile.getParentFile() != null) {
        dumpFile.getParentFile().mkdirs();
    }
    try (FileWriterWithEncoding writer = new FileWriterWithEncoding(dumpFile, StandardCharsets.UTF_8)) {
        Yaml yaml = new Yaml();
        yaml.dump(yamlObj, writer);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
项目:sahagin-java    文件:HtmlReport.java   
private void generateVelocityOutput(
        VelocityContext context, String templateResourcePath, File outputFile) {
    if (outputFile.getParentFile() != null) {
        outputFile.getParentFile().mkdirs();
    }
    try (InputStream stream = this.getClass().getResourceAsStream(templateResourcePath);
            Reader streamReader = new InputStreamReader(stream, StandardCharsets.UTF_8);
            Reader bfReader = new BufferedReader(streamReader);
            FileWriterWithEncoding writer = new FileWriterWithEncoding(outputFile, StandardCharsets.UTF_8)) {
        Velocity.evaluate(context, writer, this.getClass().getSimpleName(), bfReader);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
项目:grit    文件:PlainGenerator.java   
/**
 * 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();
}
项目:grit    文件:PdfConcatenator.java   
/**
 * 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();
}
项目:grit    文件:PdfConcatenator.java   
/**
 * 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();
}
项目:grit    文件:PdfConcatenator.java   
/**
 * Writes the names of the students that didn't hand in a submission.
 *
 * @param file
 *            the file that gets written into.
 * @param studentWithoutSubmissions
 *            a list with students who did not submit any solution.
 * @throws IOException
 *             If something goes wrong when writing.
 */
private static void writeMissingStudents(
        File file, List<Student> studentWithoutSubmissions)
        throws IOException {

    // // the list of students who didn't hand in a submission
    // List<Student> missing = context.getPreprocessor()
    // .getStudentsWithoutSubmission();

    // only write if there are any missing submissions
    if (!(studentWithoutSubmissions == null)
            && !(studentWithoutSubmissions.isEmpty())) {
        FileWriterWithEncoding writer =
                new FileWriterWithEncoding(file, "UTF-8", true);

        writer.append("{\\LARGE\\bf Studenten welche nicht abgegeben haben:}\\\\\n\\\\");
        writer.append("\\begin{minipage}{.5\\textwidth}\n");
        writer.append("\\begin{itemize}\n");
        for (int i = 0; i < studentWithoutSubmissions.size(); i += 2) {
            writer.append("\\item ")
                    .append(studentWithoutSubmissions.get(i).getName())
                    .append("\n");
        }
        writer.append("\\end{itemize}\n");
        writer.append("\\end{minipage}");

        writer.append("\\begin{minipage}{.5\\textwidth}\\raggedright\n");
        writer.append("\\begin{itemize}\n");
        for (int i = 1; i < studentWithoutSubmissions.size(); i += 2) {
            writer.append("\\item ")
                    .append(studentWithoutSubmissions.get(i).getName())
                    .append("\n");
        }
        writer.append("\\end{itemize}\n");
        writer.append("\\end{minipage}\n");
        writer.close();
    }
}
项目:grit    文件:TexGenerator.java   
/**
 * Writes the closing into the TeX file.
 * 
 * @param file
 *            File the closing gets written into.
 * @throws IOException
 *             If something goes wrong when writing.
 */
private static void writeClosing(File file) throws IOException {
    FileWriterWithEncoding writer = new FileWriterWithEncoding(file,
            "UTF-8", true);

    writer.append("\\end{student}\n");
    writer.append("\\label{lastpage}");
    writer.append("\\end{document}\n");

    writer.close();
}
项目:grit    文件:TexGenerator.java   
/**
 * Writes the failed tests into the TeX 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);
    if (submission.getCheckingResult().getTestResults().getDidTest()) {
        writer.append("\\paragraph{Fehlerhafte Tests}~\\\\\n");
        writer.append("\\begin{itemize}\n");

        for (int i = 0; i < submission.getCheckingResult().getTestResults()
                .getResults().size(); i++) {
            if (!(submission.getCheckingResult().getTestResults()
                    .getResults().get(i).wasSuccessful())) {
                writer.append("\\item{Test" + i + "}\\\n");
                writer.append("\\begin{lstlisting}[language=bash, "
                        + "breaklines=true, basicstyle=\\color{red}"
                        + "\\footnotesize\\ttfamily,numberstyle"
                        + "=\\tiny\\color{black}]{Fehler}\n");
                for (Failure fail : submission.getCheckingResult()
                        .getTestResults().getResults().get(i).getFailures()) {
                    writer.append(fail.toString() + "\n");
                }
                writer.append("\\end{lstlisting}\n");
            }
        }
    }

    writer.close();
}
项目:grit    文件:TexGenerator.java   
/**
 * Writes the Preamble into the .tex file.
 * 
 * @param file
 *            File the Preamble gets written into.
 * @throws IOException
 *             If something goes wrong when writing.
 */
private static void writePreamble(File file) throws IOException {
    final File preamble = new File(Paths.get(
            System.getProperty("user.dir"), "res", "tex",
            "report_preamble.tex").toUri());

    String preambleToString = FileUtils.readFileToString(preamble, "UTF-8");

    FileWriterWithEncoding writer = new FileWriterWithEncoding(file,
            "UTF-8", true);
    writer.append(preambleToString);
    writer.append("\n\n");

    writer.close();
}