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

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

Introduction

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

Prototype

public void write(String str) throws IOException 

Source Link

Document

Write the characters from a string.

Usage

From source file:com.nts.alphamale.data.Settings.java

public static void loadSettings() {
    if (new File(SETTINGS).exists()) {
        Properties prop = new Properties();
        try {/* w w w  .  j a  v  a2s .c o  m*/
            prop.load(new FileReader(SETTINGS));
            if (prop.getProperty("command_timeout") != null)
                EXECUTOR_TIMEOUT = Long.parseLong(prop.getProperty("command_timeout"));
            if (prop.getProperty("double_tap_threshold") != null)
                DOUBLE_TAP_THRESHOLD = Double.parseDouble(prop.getProperty("double_tap_threshold"));
            if (prop.getProperty("long_tap_threshold") != null)
                LONG_TAP_THRESHOLD = Double.parseDouble(prop.getProperty("long_tap_threshold"));
            if (prop.getProperty("swipe_area_threshold") != null)
                SWIPE_AREA_THRESHOLD = Integer.parseInt(prop.getProperty("swipe_area_threshold"));
            if (prop.getProperty("swipe_angle_threshold") != null)
                SWIPE_ANGLE_THRESHOLD = Integer.parseInt(prop.getProperty("swipe_angle_threshold"));
            if (prop.getProperty("find_timeout") != null)
                FIND_ELEMENT_TIMEOUT = Long.parseLong(prop.getProperty("find_timeout"));
            if (prop.getProperty("idle_timeout") != null)
                WAIT_FOR_IDLE_TIMEOUT = Integer.parseInt(prop.getProperty("idle_timeout"));
            if (prop.getProperty("orientation_schedule") != null)
                ORIENTATION_SCHEDULE = Long.parseLong(prop.getProperty("orientation_schedule"));
            if (prop.getProperty("keypad_schedule") != null)
                KEYPAD_SCHEDULE = Long.parseLong(prop.getProperty("keypad_schedule"));
            if (prop.getProperty("event_interval") != null)
                EVENT_INTERVAL = Integer.parseInt(prop.getProperty("event_interval"));
            if (prop.getProperty("touchscreen_device") != null)
                TOUCH_DEVICE = prop.getProperty("touchscreen_device");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        FileWriterWithEncoding fw = null;
        String lineSeparator = System.getProperty("line.separator");
        try {
            fw = new FileWriterWithEncoding(SETTINGS, "UTF-8");
            fw.write("# command timeout(ms)" + lineSeparator);
            fw.write("command_timeout = 5000" + lineSeparator);
            fw.write(lineSeparator);
            fw.write("# double tap threshold(sec)" + lineSeparator);
            fw.write("double_tap_threshold = 0.7" + lineSeparator);
            fw.write(lineSeparator);
            fw.write("# long tap threshold(sec)" + lineSeparator);
            fw.write("long_tap_threshold = 0.7" + lineSeparator);
            fw.write(lineSeparator);
            fw.write("# swipe area threshold(px)" + lineSeparator);
            fw.write("swipe_area_threshold = 100" + lineSeparator);
            fw.write(lineSeparator);
            fw.write("# swipe angle threshold" + lineSeparator);
            fw.write("swipe_angle_threshold = 45" + lineSeparator);
            fw.write(lineSeparator);
            fw.write("# find element threshold(ms)" + lineSeparator);
            fw.write("find_timeout = 2000" + lineSeparator);
            fw.write(lineSeparator);
            fw.write("# idle threshold(ms)" + lineSeparator);
            fw.write("idle_timeout = 2000" + lineSeparator);
            fw.write(lineSeparator);
            fw.write("# orientation recognition schedule" + lineSeparator);
            fw.write("orientation_schedule = 500" + lineSeparator);
            fw.write(lineSeparator);
            fw.write("# keypad recognition schedule" + lineSeparator);
            fw.write("keypad_schedule = 500" + lineSeparator);
            fw.write(lineSeparator);
            fw.write("# follower event injection interval(ms)" + lineSeparator);
            fw.write("event_interval = 500" + lineSeparator);
            fw.write(lineSeparator);
            fw.write("# touch screen device" + lineSeparator);
            fw.write(
                    "touchscreen_device = _touchscreen,touch_dev,clearpad,sensor00,atmel_mxt_540s,synaptics_rmi,mtk-tpd");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fw.close();
            } catch (IOException e) {
            }
        }
    }
}

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

@Override
protected StatusStep process() {

    try {// w  w w  .jav  a  2  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.axelor.web.service.HtmlToPdf.java

@GET
public File htmlToPdf(@QueryParam("html") String html, @QueryParam("fileName") String fileName,
        @QueryParam("printPageNo") String printPageNo) {
    try {/*from  www. jav  a2s  . c  om*/
        InputStream io = this.getClass().getClassLoader().getResourceAsStream("css/studio.css");
        StringWriter writer = new StringWriter();
        IOUtils.copy(io, writer, "utf-8");

        String css = writer.toString();
        html = "<div class=\"content\">" + html + "</div>";
        if (printPageNo != null) {
            html = "<div class=\"pageno\"> <span id=\"pagenumber\"></span> / <span id=\"pagecount\"></span></div>"
                    + html;
        }
        html = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><style type=\"text/css\">"
                + css + "</style></head><body>" + html + "</body></html>";

        html = formatHtml(html);
        File htmlfile = File.createTempFile(fileName, ".html");
        FileWriterWithEncoding fw = new FileWriterWithEncoding(htmlfile, "utf-8");
        fw.write(html);
        fw.close();

        File pdfFile = File.createTempFile(fileName, "");
        PDFRenderer.renderToPDF(htmlfile, pdfFile.getAbsolutePath());
        return pdfFile;
    } catch (IOException | DocumentException e) {
        e.printStackTrace();
    }

    return null;
}

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

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

    // 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:elaborate.editor.publish.PublishTask.java

private void exportJson(File jsonFile, Object data) {
    FileWriterWithEncoding fw = null;
    try {//from   w w  w .  j  a  va  2  s.  c o m
        fw = new FileWriterWithEncoding(jsonFile, Charsets.UTF_8);
        fw.write(toJson(data));
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (fw != null) {
            try {
                fw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:nl.imvertor.common.file.AnyFile.java

public void setContent(String s, boolean append) throws IOException {
    FileWriterWithEncoding out = new FileWriterWithEncoding(this, "UTF-8", append);
    out.write(s);
    out.flush();/*from   w w w.  j av  a 2 s .  com*/
    out.close();
}

From source file:org.apache.hadoop.tools.HadoopArchiveLogs.java

@VisibleForTesting
void generateScript(File localScript, Path workingDir, Path remoteRootLogDir, String suffix)
        throws IOException {
    if (verbose) {
        LOG.info("Generating script at: " + localScript.getAbsolutePath());
    }/*  www .  j a  va  2s . c o  m*/
    String halrJarPath = HadoopArchiveLogsRunner.class.getProtectionDomain().getCodeSource().getLocation()
            .getPath();
    String harJarPath = HadoopArchives.class.getProtectionDomain().getCodeSource().getLocation().getPath();
    String classpath = halrJarPath + File.pathSeparator + harJarPath;
    FileWriterWithEncoding fw = null;
    try {
        fw = new FileWriterWithEncoding(localScript, "UTF-8");
        fw.write("#!/bin/bash\nset -e\nset -x\n");
        int containerCount = 1;
        for (AppInfo app : eligibleApplications) {
            fw.write("if [ \"$YARN_SHELL_ID\" == \"");
            fw.write(Integer.toString(containerCount));
            fw.write("\" ]; then\n\tappId=\"");
            fw.write(app.getAppId());
            fw.write("\"\n\tuser=\"");
            fw.write(app.getUser());
            fw.write("\"\nel");
            containerCount++;
        }
        fw.write("se\n\techo \"Unknown Mapping!\"\n\texit 1\nfi\n");
        fw.write("export HADOOP_CLIENT_OPTS=\"-Xmx");
        fw.write(Long.toString(memory));
        fw.write("m\"\n");
        fw.write("export HADOOP_CLASSPATH=");
        fw.write(classpath);
        fw.write("\n\"$HADOOP_PREFIX\"/bin/hadoop ");
        fw.write(HadoopArchiveLogsRunner.class.getName());
        fw.write(" -appId \"$appId\" -user \"$user\" -workingDir ");
        fw.write(workingDir.toString());
        fw.write(" -remoteRootLogDir ");
        fw.write(remoteRootLogDir.toString());
        fw.write(" -suffix ");
        fw.write(suffix);
        if (!proxy) {
            fw.write(" -noProxy\n");
        }
        fw.write("\n");
    } finally {
        if (fw != null) {
            fw.close();
        }
    }
}

From source file:org.apache.http.nio.client.methods.TestZeroCopy.java

@BeforeClass
public static void createSrcFile() throws Exception {
    final File tmpdir = FileUtils.getTempDirectory();
    TEST_FILE = new File(tmpdir, "src.test");
    final FileWriterWithEncoding out = new FileWriterWithEncoding(TEST_FILE, ASCII);
    try {/*  w  ww  .j av  a 2s . c  om*/
        for (int i = 0; i < 500; i++) {
            for (final String line : TEXT) {
                out.write(line);
                out.write("\r\n");
            }
        }
    } finally {
        out.close();
    }
}

From source file:org.pac4j.saml.client.PostSaml2ClientIT.java

@Override
protected HtmlPage getRedirectionPage(final WebClient webClient, final Client<?, ?> client,
        final MockWebContext context) throws Exception {
    // force immediate redirection for tests
    client.redirect(context, true, false);
    File redirectFile = File.createTempFile("pac4j-saml2", ".html");
    FileWriterWithEncoding writer = new FileWriterWithEncoding(redirectFile, "UTF-8");
    writer.write(context.getResponseContent());
    writer.close();//from w  ww. j ava2s  . c  o m
    logger.debug("redirectPage path : {}", redirectFile.getPath());
    final HtmlPage redirectPage = webClient.getPage(redirectFile.toURI().toURL());
    final HtmlForm form = redirectPage.getForms().get(0);
    final HtmlSubmitInput submit = (HtmlSubmitInput) form.getElementsByAttribute("input", "type", "submit")
            .get(0);
    return submit.click();
}

From source file:org.pac4j.saml.client.TestSaml2Client.java

@Override
protected HtmlPage getRedirectionPage(final WebClient webClient, final Client client,
        final MockWebContext context) throws Exception {
    final BaseClient baseClient = (BaseClient) client;
    // force immediate redirection for tests
    baseClient.redirect(context, true, false);
    File redirectFile = File.createTempFile("pac4j-saml2", ".html");
    FileWriterWithEncoding writer = new FileWriterWithEncoding(redirectFile, "UTF-8");
    writer.write(context.getResponseContent());
    writer.close();/*w w  w . j  av a2 s  .c  o  m*/
    logger.debug("redirectPage path : {}", redirectFile.getPath());
    final HtmlPage redirectPage = webClient.getPage(redirectFile.toURI().toURL());
    final HtmlForm form = redirectPage.getForms().get(0);
    final HtmlSubmitInput submit = (HtmlSubmitInput) form.getElementsByAttribute("input", "type", "submit")
            .get(0);
    return submit.click();
}