Example usage for java.io Writer write

List of usage examples for java.io Writer write

Introduction

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

Prototype

public void write(String str) throws IOException 

Source Link

Document

Writes a string.

Usage

From source file:io.sqp.core.jackson.JacksonMessageEncoder.java

public void encode(Writer writer, SqpMessage message) throws IOException {
    MessageType type = message.getType();
    try {/* w  w w .  ja  v a  2 s  .  co  m*/
        writer.write(type.getId());
    } catch (IOException e) {
        writer.close();
        throw e;
    }

    if (!type.hasContent()) {
        writer.close();
        return;
    }

    ObjectMapper mapper = JacksonObjectMapperFactory.objectMapper(DataFormat.Text);
    mapper.writeValue(writer, message);
}

From source file:com.fhc25.percepcion.osiris.mapviewer.common.geojson.GeoJSONParser.java

/**
 * Parses a PointDTO to GeoJSON format and writes it into the output stream
 *
 * @param point//from  w w w. j  av a 2  s. com
 * @param output
 */
public void writePointDTO(PointDTO point, Writer output) {
    try {
        output.write(pointDTO2JSON(point).toString());
    } catch (IOException e) {
        Lgr.e(TAG, e);
    }
}

From source file:com.fhc25.percepcion.osiris.mapviewer.common.geojson.GeoJSONParser.java

/**
 * Parses a LineDTO to GeoJSON format and writes it into the output stream
 *
 * @param lineString/*ww  w . ja va  2s . co  m*/
 * @param output
 */
public void writeLineStringDTO(LineStringDTO lineString, Writer output) {
    try {
        output.write(lineString2JSON(lineString).toString());
    } catch (IOException e) {
        Lgr.e(TAG, e);
    }
}

From source file:com.fhc25.percepcion.osiris.mapviewer.common.geojson.GeoJSONParser.java

/**
 * Parses a Polygon to GeoJSON format and writes it into the output stream
 *
 * @param polygon// www .  ja  v a 2s . c  o m
 * @param output
 */
public void writePolygonDTO(PolygonDTO polygon, Writer output) {
    try {
        output.write(polygonDTO2JSON(polygon).toString());
    } catch (IOException e) {
        Lgr.e(TAG, e);
    }
}

From source file:au.edu.uq.cmm.benny.Benny.java

private void respond(HttpServletResponse resp, int status, String msg) throws IOException {
    resp.setContentType("text/plain");
    resp.setStatus(status);//  w ww .jav  a  2s .c  o m
    Writer w = resp.getWriter();
    try {
        w.write(msg + "\r\n");
    } finally {
        w.close();
    }
}

From source file:com.centeractive.ws.server.endpoint.GenericSoapMessage.java

@Override
public void writeTo(OutputStream outputStream) throws IOException {
    Writer writer = new OutputStreamWriter(outputStream, Charset.forName("UTF-8"));
    String message = XmlUtils.sourceToXmlString(source);
    writer.write(message);
    writer.flush();/*from ww  w  .  j  a va  2  s  . c o  m*/
    writer.close();
}

From source file:grails.plugin.errorpagesfix.PatchedErrorHandlingServlet.java

private void renderDefaultResponse(HttpServletResponse response, int statusCode, String title, String text)
        throws IOException {
    response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    response.setContentType(TEXT_HTML);

    Writer writer = response.getWriter();

    writer.write("<HTML>\n<HEAD>\n<TITLE>Error " + statusCode + " - " + title);
    writer.write("</TITLE>\n<BODY>\n<H2>Error " + statusCode + " - " + title + ".</H2>\n");
    writer.write(text + "<BR/>");

    for (int i = 0; i < 20; i++) {
        writer.write("\n<!-- Padding for IE                  -->");
    }/*from  ww w .  j a  va2s  .  c o m*/

    writer.write("\n</BODY>\n</HTML>\n");
    writer.flush();
}

From source file:org.craftercms.core.util.template.impl.spel.SpElCompiledTemplate.java

@Override
public void process(Object model, Writer output) throws TemplateException {
    try {//w  w w . j a  v  a  2  s .c o m
        String result = expression.getValue(evaluationContext, model, String.class);

        output.write(result);
        output.flush();
    } catch (IOException e) {
        throw new TemplateException("An I/O error occurred while writing to output", e);
    } catch (Exception e) {
        throw new TemplateException("Unable to process SpEL template:\n" + expression.getExpressionString(), e);
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.web.directives.WidgetDirective.java

@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
        throws TemplateException, IOException {

    if (loopVars.length != 0) {
        throw new TemplateModelException("The dump directive doesn't allow loop variables.");
    }/*from  w  w w.j  av  a2 s  .  co m*/
    if (body != null) {
        throw new TemplateModelException("The dump directive doesn't allow nested content.");
    }

    Object nameParam = params.get("name");
    if (!(nameParam instanceof SimpleScalar)) {
        throw new TemplateModelException("Value of parameter 'name' must be a string.");
    }
    String widgetName = nameParam.toString();

    // Optional param
    Object includeParam = params.get("include");
    String methodName;
    // If include param is missing, or something other than "assets", 
    // assign default value "markup"
    if (includeParam == null) {
        methodName = "markup";
    } else {
        methodName = includeParam.toString();
        if (!("assets".equals(methodName))) {
            methodName = "markup";
        }
    }
    methodName = "do" + StringUtils.capitalize(methodName);

    try {
        String widgetClassName = WIDGET_PACKAGE + "." + StringUtils.capitalize(widgetName) + "Widget";
        Class<?> widgetClass = Class.forName(widgetClassName);
        Widget widget = (Widget) widgetClass.newInstance();
        Method method = widgetClass.getMethod(methodName, Environment.class, Map.class);

        // Right now it seems to me that we will always be producing a string for the widget calls. If we need greater
        // flexibility, we can return a ResponseValues object and deal with different types here.
        String output = (String) method.invoke(widget, env, params);

        // If we're in the body template, automatically invoke the doAssets() method, so it
        // doesn't need to be called explicitly from the enclosing template.
        String templateType = env.getDataModel().get("templateType").toString();
        if ("doMarkup".equals(methodName) && FreemarkerHttpServlet.BODY_TEMPLATE_TYPE.equals(templateType)) {
            output += widgetClass.getMethod("doAssets", Environment.class, Map.class).invoke(widget, env,
                    params);
        }

        Writer out = env.getOut();
        out.write(output);

    } catch (ClassNotFoundException e) {
        log.error("Widget " + widgetName + " not found.");
    } catch (IOException e) {
        log.error("Error writing output for widget " + widgetName, e);
    } catch (Exception e) {
        log.error("Error invoking widget " + widgetName, e);
    }

}

From source file:com.bstek.dorado.view.ViewOutputter.java

/**
 * ?DataType//from  w  w  w.java2  s . c  om
 */
protected void outputIncludeDataTypes(View view, OutputContext context) throws Exception {
    Writer writer = context.getWriter();
    writer.write("view.get(\"dataTypeRepository\").parseJsonData(");
    viewDataTypesOutputter.output(view, context);
    writer.write(");\n");
}