Example usage for java.io StringWriter write

List of usage examples for java.io StringWriter write

Introduction

In this page you can find the example usage for java.io StringWriter write.

Prototype

public void write(String str) 

Source Link

Document

Write a string.

Usage

From source file:com.signavio.warehouse.business.util.jpdl4.Arg.java

public String toJpdl() throws InvalidModelException {
    StringWriter jpdl = new StringWriter();
    jpdl.write("    <arg");
    if (a_type != null && a_type.length() > 0) {
        jpdl.write(" type=\"" + StringEscapeUtils.escapeXml(a_type) + "\">");
    } else {/*from   ww w.  java 2  s  . c o  m*/
        jpdl.write(">");
    }
    if (child != null) {
        jpdl.write(child.toJpdl());
    } else {
        throw new InvalidModelException("Invalid Arg. Object or String is missing");
    }
    jpdl.write("</arg>\n");
    return jpdl.toString();
}

From source file:com.signavio.warehouse.business.util.jpdl4.Hql.java

@Override
public String toJpdl() throws InvalidModelException {
    StringWriter jpdl = new StringWriter();
    jpdl.write("  <hql");

    jpdl.write(JsonToJpdl.transformAttribute("name", name));
    jpdl.write(JsonToJpdl.transformAttribute("var", var));
    if (unique != null)
        jpdl.write(JsonToJpdl.transformAttribute("unique", unique.toString()));

    if (bounds != null) {
        jpdl.write(bounds.toJpdl());//from   ww w  . j  ava2 s  .  c  o  m
    } else {
        throw new InvalidModelException("Invalid HQL activity. Bounds is missing.");
    }

    jpdl.write(" >\n");

    if (query != null) {
        jpdl.write("    <query>");
        jpdl.write(StringEscapeUtils.escapeXml(query));
        jpdl.write("</query>\n");
    } else {
        throw new InvalidModelException("Invalid HQL activity. Query is missing.");
    }

    if (parameters != null) {
        jpdl.write(parameters.toJpdl());
    }

    for (Transition t : outgoings) {
        jpdl.write(t.toJpdl());
    }

    jpdl.write("  </hql>\n");
    return jpdl.toString();
}

From source file:org.xwiki.icon.internal.DefaultIconRenderer.java

private String renderIcon(IconSet iconSet, String iconName, String renderer) throws IconException {
    // Get the icon
    Icon icon = iconSet.getIcon(iconName);

    // The icon may not exist
    if (icon == null) {
        // return an empty string. Idea: fallback on a different icon instead?
        return "";
    }/*from  ww  w . j  a v a 2s.  c om*/

    // Interpret the velocity command
    StringWriter contentToParse = new StringWriter();
    contentToParse.write("#set($icon = \"");
    contentToParse.write(icon.getValue());
    contentToParse.write("\")\n");
    contentToParse.write(renderer);

    return velocityRenderer.render(contentToParse.toString());
}

From source file:hivemall.UDFWithOptions.java

protected final CommandLine parseOptions(String optionValue) throws UDFArgumentException {
    String[] args = optionValue.split("\\s+");
    Options opts = getOptions();/* w ww  .  j  ava2  s. c  om*/
    opts.addOption("help", false, "Show function help");
    CommandLine cl = CommandLineUtils.parseOptions(args, opts);

    if (cl.hasOption("help")) {
        Description funcDesc = getClass().getAnnotation(Description.class);
        final String cmdLineSyntax;
        if (funcDesc == null) {
            cmdLineSyntax = getClass().getSimpleName();
        } else {
            String funcName = funcDesc.name();
            cmdLineSyntax = funcName == null ? getClass().getSimpleName()
                    : funcDesc.value().replace("_FUNC_", funcDesc.name());
        }
        StringWriter sw = new StringWriter();
        sw.write('\n');
        PrintWriter pw = new PrintWriter(sw);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(pw, HelpFormatter.DEFAULT_WIDTH, cmdLineSyntax, null, opts,
                HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null, true);
        pw.flush();
        String helpMsg = sw.toString();
        throw new UDFArgumentException(helpMsg);
    }

    return cl;
}

From source file:org.dhatim.javabean.dynamic.serialize.freemarker.WriteBeanDirective.java

public void execute(Environment environment, Map params, TemplateModel[] templateModels,
        TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException {
    Object bean = getBeanObject(environment, params, "writeBean");

    SimpleScalar indentScalar = (SimpleScalar) params.get("indent");
    int indent = 0;
    if (indentScalar != null) {
        String indentParamVal = indentScalar.getAsString().trim();
        try {/*from  w ww .  ja  va 2 s  .c  o  m*/
            indent = Integer.parseInt(indentParamVal);
            indent = Math.min(indent, 100);
        } catch (NumberFormatException e) {
            logger.debug("Invalid <@writeNamespaces> 'indent' parameter value '" + indentParamVal
                    + "'.  Must be a valid integer (<= 100).");
        }
    }

    BeanModel modelBeanModel = (BeanModel) environment.getDataModel().get(FreeMarkerBeanWriter.MODEL_CTX_KEY);
    Model model = (Model) modelBeanModel.getWrappedObject();
    BeanMetadata beanMetadata = model.getBeanMetadata(bean);

    if (beanMetadata == null) {
        BeanRegistrationException.throwUnregisteredBeanInstanceException(bean);
    }

    BeanWriter beanWriter = beanMetadata.getWriter();

    if (beanMetadata.getPreText() != null) {
        environment.getOut().write(beanMetadata.getPreText());
    }

    if (indent > 0) {
        StringWriter beanWriteBuffer = new StringWriter();

        beanWriteBuffer.write('\n');
        beanWriter.write(bean, beanWriteBuffer, model);

        environment.getOut().write(XmlUtil.indent(beanWriteBuffer.toString(), indent));
    } else {
        beanWriter.write(bean, environment.getOut(), model);
    }
}

From source file:hivemall.UDAFEvaluatorWithOptions.java

@Nonnull
protected final CommandLine parseOptions(@Nonnull String optionValue) throws UDFArgumentException {
    String[] args = optionValue.split("\\s+");
    Options opts = getOptions();/*from   w  ww .j a  va2s. c  om*/
    opts.addOption("help", false, "Show function help");
    CommandLine cl = CommandLineUtils.parseOptions(args, opts);

    if (cl.hasOption("help")) {
        Description funcDesc = getClass().getAnnotation(Description.class);
        final String cmdLineSyntax;
        if (funcDesc == null) {
            cmdLineSyntax = getClass().getSimpleName();
        } else {
            String funcName = funcDesc.name();
            cmdLineSyntax = funcName == null ? getClass().getSimpleName()
                    : funcDesc.value().replace("_FUNC_", funcDesc.name());
        }
        StringWriter sw = new StringWriter();
        sw.write('\n');
        PrintWriter pw = new PrintWriter(sw);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(pw, HelpFormatter.DEFAULT_WIDTH, cmdLineSyntax, null, opts,
                HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null, true);
        pw.flush();
        String helpMsg = sw.toString();
        throw new UDFArgumentException(helpMsg);
    }

    return cl;
}

From source file:org.nuxeo.ecm.platform.pictures.tiles.service.TiledImagePreviewer.java

private String getString() {
    StringWriter writer = new StringWriter();
    writer.write("<html><head></head><body>");
    writer.write("<script type=\"text/javascript\">");
    writer.write("var serverSetting = {");
    writer.write("repoId : '$repoId$' ,");
    writer.write("docId : '$docId$' ,");
    writer.write("contextPath : '" + VirtualHostHelper.getContextPathProperty() + "'");
    writer.write("};");
    writer.write("</script>");
    writer.write("<script type=\"text/javascript\"");
    writer.write("src=\"" + VirtualHostHelper.getContextPathProperty()
            + "/org.nuxeo.ecm.platform.pictures.tiles.gwt.TilingPreview/org.nuxeo.ecm.platform.pictures.tiles.gwt.TilingPreview.nocache.js\">");
    writer.write("</script>");
    appendPreviewSettings(writer);/*  ww w. j  a  v a  2s .  c o  m*/
    writer.write("<div id=\"display\"></div>");
    writer.write("</body></html>");
    return writer.toString();
}

From source file:com.espertech.esper.core.SchedulingServiceAudit.java

public void remove(ScheduleHandle handle, ScheduleSlot slot) throws ScheduleServiceException {
    if (auditLog.isInfoEnabled()) {
        StringWriter message = new StringWriter();
        message.write("Statement ");
        message.write(statementName);/*from w ww .j a  v a2s.  c om*/
        message.write(" schedule remove handle ");
        printHandle(message, handle);
        auditLog.info(message);
    }
    spi.remove(handle, slot);
}

From source file:com.ppcxy.cyfm.showcase.demos.utilities.io.IODemo.java

@Test
public void workWithStream() {
    InputStream in = null;/*from   w ww  .  ja  va 2s. c om*/
    try {
        String content = "Stream testing";

        // String - > InputStream.
        in = IOUtils.toInputStream(content, "UTF-8");

        // String - > OutputStream
        System.out.println("String to OutputStram:");
        IOUtils.write(content, System.out, "UTF-8");

        // //////////////////
        // InputStream/Reader -> String
        System.out.println("\nInputStram to String:");
        System.out.println(IOUtils.toString(in, "UTF-8"));

        // InputStream/Reader -> OutputStream/Writer ???.
        InputStream in2 = IOUtils.toInputStream(content); // ?inputSteam
        System.out.println("InputStream to OutputStream:");
        IOUtils.copy(in2, System.out);

        // /////////////////
        // InputStream ->Reader
        InputStreamReader reader = new InputStreamReader(in, Charsets.UTF_8);
        // Reader->InputStream
        ReaderInputStream in3 = new ReaderInputStream(reader, Charsets.UTF_8);

        // OutputStream ->Writer
        OutputStreamWriter writer = new OutputStreamWriter(System.out, Charsets.UTF_8);
        // Writer->OutputStream
        WriterOutputStream out2 = new WriterOutputStream(writer, Charsets.UTF_8);

        // ////////////////////
        // WriterString.
        StringWriter sw = new StringWriter();
        sw.write("I am String writer");
        System.out.println("\nCollect writer content:");
        System.out.println(sw.toString());

    } catch (IOException e) {
        Exceptions.unchecked(e);
    } finally {
        // ?Stream
        IOUtils.closeQuietly(in);
    }
}

From source file:com.espertech.esper.core.SchedulingServiceAudit.java

public void add(long afterMSec, ScheduleHandle handle, ScheduleSlot slot) throws ScheduleServiceException {
    if (auditLog.isInfoEnabled()) {
        StringWriter message = new StringWriter();
        message.write("Statement ");
        message.write(statementName);/* w  w  w.  j a  v a  2  s. c o  m*/
        message.write(" schedule after ");
        message.write(Long.toString(afterMSec));
        message.write(" handle ");
        printHandle(message, handle);
        auditLog.info(message);

        modifyCreateProxy(handle);
    }
    spi.add(afterMSec, handle, slot);
}