Example usage for org.apache.commons.io.output FileWriterWithEncoding FileWriterWithEncoding

List of usage examples for org.apache.commons.io.output FileWriterWithEncoding FileWriterWithEncoding

Introduction

In this page you can find the example usage for org.apache.commons.io.output FileWriterWithEncoding FileWriterWithEncoding.

Prototype

public FileWriterWithEncoding(File file, CharsetEncoder encoding) throws IOException 

Source Link

Document

Constructs a FileWriterWithEncoding with a file encoding.

Usage

From source file:com.bsb.cms.moss.controller.utils.TemplateFileManager.java

public void createFreemarkFile(String dirPath, String fileName, String fileContent) {
    FileWriterWithEncoding fw = null;/*from w  ww . j  a va2  s.  c  om*/
    File dirFile = new File(dirPath);
    if (!dirFile.exists()) {
        dirFile.mkdirs();
    }

    // FileOutputStream out = new FileOutputStream(dirPath + fileName +
    // ".ftl");
    try {
        String filePath = dirPath + fileName + ".ftl";
        fw = new FileWriterWithEncoding(filePath, "UTF-8");
        fw.write(fileContent);
        log.info("template created:" + filePath);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (fw != null)
            try {
                fw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }

}

From source file:eu.annocultor.data.destinations.SolrDocumentsFile.java

@Override
public void startRdf() throws Exception {
    super.startRdf();
    writer = new PrintWriter(new FileWriterWithEncoding(getFinalFile(getVolume()), "UTF-8"));
    writer.println("<add>");
}

From source file:com.bluexml.side.util.documentation.LogSave.java

public static void toXml(SIDELog log, String fileName, File folder) throws Exception {
    folder.mkdirs();/*from  www. j a v a2s.  c  om*/
    FileWriterWithEncoding fos;
    File file = new File(folder, fileName);
    file.createNewFile();
    fos = new FileWriterWithEncoding(file, "UTF-8");
    toXml(log, fos);
    fos.close();

}

From source file:net.ageto.gyrex.impex.common.steps.impl.writers.FileWriter.java

@Override
protected StatusStep process() {

    try {/*from  w ww .j  av  a2 s. c  o  m*/
        String filename = (String) getInputParam(FileWriterDefinition.InputParamNames.OUTPUT_FILENAME.name());

        if (StringUtils.isBlank(filename)) {
            processError("{0} missing input.", ID);
            return StatusStep.ERROR;
        }

        StringBuffer content = (StringBuffer) getInputParam(
                FileWriterDefinition.InputParamNames.INPUT_CONTENT.name());

        FileWriterWithEncoding fw = new FileWriterWithEncoding(new File(filename), CharEncoding.UTF_8);
        fw.write(content.toString());
        fw.flush();

    } catch (IOException e) {
        processError("File could not be created.");
    }

    processInfo("{0} has been completed successfully.", ID);

    return StatusStep.OK;
}

From source file:com.mgmtp.perfload.agent.AgentLogger.java

@Override
public void open() throws IOException {
    writer = new PrintWriter(
            new DecoratingWriter(new FileWriterWithEncoding(agentLogFile, Charset.forName("UTF-8"))));
}

From source file:de.saly.json.jsr353.benchmark.data.CreateJsonTestFiles.java

private static File create(final String path, final int count, final Charset charset) throws Exception {

    if (count < 0 || path == null || path.length() == 0) {
        throw new IllegalArgumentException();
    }//  w  w  w  . j a v a2  s . c  o m

    final File json = new File(
            path + "/" + "generated_benchmark_test_file_" + charset.name() + "_" + count + ".json");

    if (json.exists()) {
        System.out.println("File already exists: " + json.getAbsolutePath());
        return json;
    }

    final FileWriterWithEncoding sb = new FileWriterWithEncoding(json, charset);

    sb.append("{\n");

    for (int i = 0; i < count; i++) {

        sb.append("\t\"special-" + i + "\":" + "\"" + "\\\\f\\n\\r\\t\\u6532\uDC00\uD800" + "\",\n");
        sb.append("\t\"unicode-\\u0000- " + i + "\":\"\\u5656\uDC00\uD800\",\n");
        sb.append("\t\"\u6532bigdecimal" + i + "\":7817265.00000111,\n");
        sb.append("\t\"bigdecimal-2-" + i + "\":127655512123456.761009E-123,\n");
        sb.append("\t\"string-" + i
                + "\":\"lorem ipsum, ????????????.-,<!$%&/()9876543XXddddJJJJJJhhhhhhhh\uDC00\uD800\",\n");
        sb.append("\t\t\t\t\"int" + i + "\":[1,-4543,112,0,1,10,100,87,34112, true, false, null],\n");
        sb.append("\t\"\u6532ints" + i + "\":0,\n");
        sb.append("\t\"\u6532false" + i + "\":false,\n");
        sb.append("\t\"\u6532nil" + i + "\":false,\n");
        sb.append("\t\"\u6532n" + i + "\":      null                ,\n");
        sb.append("\t\"obj" + i + "\":\n");

        sb.append("\t\t{\n");

        sb.append("\t\t\t\"special-" + i + "\":" + "\"" + "\\\\f\\n\\r\\t\\u6532" + "\",\n");
        sb.append("\t\t\t\"unicode-\\u0000- " + i + "\":\"\\u5656\",\n");
        sb.append(" \"bigdecimal" + i + "\":7817265.00000111,\n");
        sb.append("\t\t\t\"bigdecimal-2-" + i + "\":127655512123456.761009E-123,\n");
        sb.append("\t\t\t\"string-" + i
                + "\":\"lorem ipsum, ????????????.-,<!$%&/()9876543XXddddJJJJJJhhhhhhhh\",\n");
        sb.append("\t\t\t\t\"int" + i + "\":[1,-4543,112,0,1,10,100,87,34112, true, false, null],\n");
        sb.append("\t\t\t\"ints" + i + "\":0,\n");
        sb.append("\t\t\t\"false" + i + "\":false,\n");
        sb.append("\t\t\t\"nil" + i + "\":false,\n");
        sb.append("\t\t\t\"obj" + i + "\":      null                ,\n");
        sb.append("\t\t\t\"obj" + i + "\":\n");
        sb.append("\t\t\t\t[    true, \"normal string ascii only normal string ascii only\"    ,\n");

        sb.append("\t\t\t\t{\n");

        sb.append("\t\t\t\t\"special-" + i + "\":" + "\"" + "\\\\f\\n\\r\\t\\u6532" + "\",\n");
        sb.append("\t\t\t\t\"unicode-\\u0000- " + i + "\":\"\\u5656\",\n");
        sb.append("\t\t\t\t\"bigdecimal" + i + "\":7817265.00000111,\n");
        sb.append("\t\t\t\t\"bigdecimal-2-" + i + "\":127655512123456.761009E-123,\n");
        sb.append("\t\t\t\t\"string-" + i
                + "\":\"lorem ipsum, ????????????.-,<!$%&/()9876543XXddddJJJJJJhhhhhhhh\",\n");
        sb.append("\t\t\t\t\"int" + i + "\":[1,-4543,112,0,1,10,100,87,34112, true, false, null],\n");
        sb.append("\t\t\t\t\"ints" + i + "\":0,\n");
        sb.append("\t\t\t\t\"false" + i + "\":false,\n");
        sb.append("\t\t\t\t\"nil" + i + "\":false,\n");
        sb.append("\t\t\t\t\"obj" + i + "\":      null                \n");
        sb.append("\t\t\t\t\n}\n");

        sb.append("\t\t\t]\n");

        sb.append("\t\t\n}\n\n\n\n                 \t\r                                                      ");

        if (i < count - 1) {
            sb.append(",\n");
        } else {
            sb.append("\n");
        }
    }

    sb.append("\n}\n");

    sb.close();

    return json;

}

From source file:de.awtools.grooocle.inout.GFileWriter.java

public GFileWriter(final File _file, final String _encoding) throws IOException {

    fileWriter = new FileWriterWithEncoding(_file, _encoding);
}

From source file:com.evolveum.midpoint.repo.sql.util.OrgStructGenerator.java

@Test(enabled = false)
public void generateOrgStructure() throws Exception {
    List<OrgType> orgs = generateOrgStructure(0, new int[] { 1, 20, 25, 2 }, "Org", null);

    System.out.println(orgs.size());

    Collections.shuffle(orgs);// w w w  .j a  v a  2s  . co m

    File file = new File("./target/orgs.xml");
    if (file.exists()) {
        file.delete();
    }
    file.createNewFile();
    try (Writer writer = new FileWriterWithEncoding(file, StandardCharsets.UTF_8)) {
        writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
        writer.write("<objects xmlns=\"http://midpoint.evolveum.com/xml/ns/public/common/common-3\">\n");

        for (OrgType org : orgs) {
            writer.write(PrismTestUtil.serializeObjectToString(org.asPrismObject()));
        }

        writer.write("</objects>");
    }
}

From source file:gemlite.core.internal.testing.generator.writer.impl.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);/*from  www.  j a  v a 2 s .c  om*/
    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;
    }
}

From source file:com.bluexml.side.util.documentation.LogSave.java

/**
 * Render a SIDELog to a xml file using the given fileName in the given
 * folderName/*from   w w  w .  j a  v a2 s . c om*/
 * 
 * @param log
 * @param fileName
 * @param folderName
 * @throws Exception
 */
public static void toXml(SIDELog log, String fileName, String folderName) throws Exception {
    IFolder folder = IFileHelper.createFolder(folderName);
    File f = IFileHelper.getFile(folder);
    FileWriterWithEncoding fos;
    File file = new File(f, fileName);
    file.createNewFile();
    fos = new FileWriterWithEncoding(file, "UTF-8");
    toXml(log, fos);
    IFileHelper.refreshFolder(folder);
    fos.close();
}