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.espertech.esper.core.SchedulingServiceAudit.java

public void add(ScheduleSpec scheduleSpec, ScheduleHandle handle, ScheduleSlot slot)
        throws ScheduleServiceException {
    if (auditLog.isInfoEnabled()) {
        StringWriter message = new StringWriter();
        message.write("Statement ");
        message.write(statementName);//www. j av a2s .co m
        message.write(" schedule add ");
        message.write(scheduleSpec.toString());
        message.write(" handle ");
        printHandle(message, handle);
        auditLog.info(message);

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

From source file:org.powertac.common.OrderbookTests.java

@Test
public void xmlSerializationTestEmpty() {
    Orderbook ob1 = new Orderbook(timeslot, 22.1, now);
    XStream xstream = new XStream();
    xstream.processAnnotations(Orderbook.class);
    xstream.processAnnotations(Timeslot.class);
    StringWriter serialized = new StringWriter();
    serialized.write(xstream.toXML(ob1));
    //System.out.println(serialized.toString());

    Orderbook xob1 = (Orderbook) xstream.fromXML(serialized.toString());
    assertNotNull("deserialized something", xob1);
    assertEquals("correct timeslot", timeslot, xob1.getTimeslot());
    assertEquals("correct clearing price", 22.1, xob1.getClearingPrice(), 1e-6);
    assertNotNull("bids", xob1.getBids().size());
    assertNotNull("asks", xob1.getAsks().size());
}

From source file:org.powertac.common.OrderbookTests.java

@Test
public void xmlSerializationTest() {
    Orderbook ob1 = new Orderbook(timeslot, 22.1, now).addBid(new OrderbookOrder(3.3, -20.0))
            .addBid(new OrderbookOrder(2.1, -18.2)).addBid(new OrderbookOrder(5.6, -19.4))
            .addBid(new OrderbookOrder(6.2, null)).addAsk(new OrderbookOrder(-3.1, 23.4));
    XStream xstream = new XStream();
    xstream.processAnnotations(Orderbook.class);
    xstream.processAnnotations(Timeslot.class);
    StringWriter serialized = new StringWriter();
    serialized.write(xstream.toXML(ob1));
    //System.out.println(serialized.toString());

    Orderbook xob1 = (Orderbook) xstream.fromXML(serialized.toString());
    assertNotNull("deserialized something", xob1);
    assertEquals("correct timeslot", timeslot, xob1.getTimeslot());
    assertEquals("correct clearing price", 22.1, xob1.getClearingPrice(), 1e-6);
    assertEquals("four bids", 4, xob1.getBids().size());
    assertEquals("one ask", 1, xob1.getAsks().size());
}

From source file:com.espertech.esper.epl.expression.ExprNewNode.java

public String toExpressionString() {
    StringWriter writer = new StringWriter();
    writer.write("new { ");
    String delimiter = "";
    for (int i = 0; i < this.getChildNodes().length; i++) {
        writer.append(delimiter);/*from ww  w . j  a  va 2s.  co  m*/
        writer.append(columnNames[i]);
        ExprNode expr = this.getChildNodes()[i];

        boolean outputexpr = true;
        if (expr instanceof ExprIdentNode) {
            ExprIdentNode prop = (ExprIdentNode) expr;
            if (prop.getResolvedPropertyName().equals(columnNames[i])) {
                outputexpr = false;
            }
        }

        if (outputexpr) {
            writer.append(" = ");
            writer.append(expr.toExpressionString());
        }
        delimiter = ", ";
    }
    writer.write(" }");
    return writer.toString();
}

From source file:hivemall.UDTFWithOptions.java

@Nonnull
protected final CommandLine parseOptions(String optionValue) throws UDFArgumentException {
    String[] args = optionValue.split("\\s+");
    Options opts = getOptions();/*  w  w w .  j  a  v a  2  s. c o  m*/
    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.syncope.core.scheduling.AbstractTaskJob.java

@Override
public final void execute(final JobExecutionContext context) throws JobExecutionException {

    task = taskDAO.find(taskId);/*from   w w  w  .  j  av a2s.  co  m*/
    if (task == null) {
        throw new JobExecutionException("Task " + taskId + " not found");
    }

    TaskExec execution = new TaskExec();
    execution.setStartDate(new Date());
    execution.setTask(task);

    try {
        execution.setMessage(doExecute(context.getMergedJobDataMap().getBoolean(DRY_RUN_JOBDETAIL_KEY)));

        execution.setStatus(Status.SUCCESS.name());
    } catch (JobExecutionException e) {
        LOG.error("While executing task " + taskId, e);

        StringWriter exceptionWriter = new StringWriter();
        exceptionWriter.write(e.getMessage() + "\n\n");
        e.printStackTrace(new PrintWriter(exceptionWriter));
        execution.setMessage(exceptionWriter.toString());

        execution.setStatus(Status.FAILURE.name());
    }
    execution.setEndDate(new Date());
    if (hasToBeRegistered(execution)) {
        taskExecDAO.save(execution);
    }
}

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

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

    jpdl.write(JsonToJpdl.transformAttribute("name", name));
    jpdl.write(JsonToJpdl.transformAttribute("expr", expression));
    jpdl.write(JsonToJpdl.transformAttribute("lang", language));
    jpdl.write(JsonToJpdl.transformAttribute("var", variable));

    if (bounds != null) {
        jpdl.write(bounds.toJpdl());//  w w  w .j a va  2s . c om
    } else {
        throw new InvalidModelException("Invalid Script activity. Bounds is missing.");
    }

    jpdl.write(" >\n");

    if (text != null && text.length() > 0) {
        jpdl.write("    <text>");
        jpdl.write(StringEscapeUtils.escapeXml(text));
        jpdl.write("</text>\n");
    }

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

    jpdl.write("  </script>\n\n");

    return jpdl.toString();
}

From source file:org.gradle.api.tasks.wrapper.internal.WrapperScriptGenerator.java

private String transformIntoWindowsNewLines(String s) {
    StringWriter writer = new StringWriter();
    for (char c : s.toCharArray()) {
        if (c == '\n') {
            writer.write('\r');
            writer.write('\n');
        } else if (c != '\r') {
            writer.write(c);/* ww  w  .  j a v  a2 s  . c  om*/
        }
    }
    return writer.toString();
}

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

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

    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 w ww  . j a v  a  2 s.c o m
    } else {
        throw new InvalidModelException("Invalid SQL 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 SQL activity. Query is missing.");
    }

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

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

    jpdl.write("  </sql>\n\n");

    return jpdl.toString();
}

From source file:org.jcurl.core.swing.CurvePainter.java

/**
 * Paint the segments of one curve. Delegate to
 * {@link #doPaint(Graphics2D, R1RNFunction, double[], float, double[], double[], double[], double[])}.
 * //from   w  ww. j  a  va2s .co  m
 * @param g2
 *            where to draw
 * @param path
 * @param sections
 * @param zoom
 *            TODO Remove factor - typically 1.
 * @param t1
 *            save instanciations calling
 *            {@link R1RNFunction#at(double, int, double[])}.
 * @param t2
 *            save instanciations calling
 *            {@link R1RNFunction#at(double, int, double[])}.
 * @param t3
 *            save instanciations calling
 *            {@link R1RNFunction#at(double, int, double[])}.
 * @param t4
 *            save instanciations calling
 *            {@link R1RNFunction#at(double, int, double[])}.
 * @see #doSections(double[], double, double)
 * @see #doPaint(Graphics2D, R1RNFunction, double[], float, double[],
 *      double[], double[], double[])
 */
public void doPaint(final Graphics2D g2, final Iterator<Entry<Double, R1RNFunction>> path,
        final double[] sections, final float zoom, final double[] t1, final double[] t2, final double[] t3,
        final double[] t4) {
    if (!path.hasNext())
        return;
    Entry<Double, R1RNFunction> curr = path.next();
    while (path.hasNext()) {
        final Entry<Double, R1RNFunction> next = path.next();
        // doSections(sections, curr.getKey(), next.getKey());
        if (log.isDebugEnabled()) {
            final StringWriter wri = new StringWriter();
            wri.write("t=");
            toString(wri, sections);
            wri.write(" c=" + curr.getValue());
            log.debug(wri.getBuffer());
        }
        doPaint(g2, curr.getValue(), sections, zoom, t1, t2, t3, t4);
        // step:
        curr = next;
    }
}