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:com.googlecode.jsfFlex.phaseListener.ArrayServiceRequestDataRetrieverFlusher.java

@Override
void retrieveFlushData(FacesContext context, String componentId, String methodToInvoke)
        throws ServletException, IOException {

    JSONArray methodResult = null;/*  w w w .j  a  v a2 s. c  om*/

    try {
        methodResult = JSONArray.class
                .cast(invokeResourceMethod(context, componentId, methodToInvoke, null, null));
    } catch (Exception methodInvocationException) {
        throw new ServletException(methodInvocationException);
    }

    HttpServletResponse response = HttpServletResponse.class.cast(context.getExternalContext().getResponse());
    response.setContentType(XML_CONTENT_TYPE);

    StringBuilder responseContent = new StringBuilder();
    responseContent.append(XML_HEAD);
    responseContent.append(XML_RESULT_ROOT_START_TAG);

    try {
        responseContent.append(JSONConverter.convertJSONArrayToXMLString(methodResult));
    } catch (JSONException jsonException) {
        throw new ServletException(ERROR_CONVERTING_JSON_ARRAY_TO_XML, jsonException.getCause());
    }

    responseContent.append(XML_RESULT_ROOT_END_TAG);

    _log.info("Flushing content : " + responseContent.toString());

    Writer writer = response.getWriter();
    writer.write(responseContent.toString());
    writer.flush();

}

From source file:com.cloudera.lib.wsrs.JSONMapProvider.java

@Override
public void writeTo(Map map, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType,
        MultivaluedMap<String, Object> stringObjectMultivaluedMap, OutputStream outputStream)
        throws IOException, WebApplicationException {
    Writer writer = new OutputStreamWriter(outputStream);
    JSONObject.writeJSONString(map, writer);
    writer.write(ENTER);
    writer.flush();//from   w  w w.java  2s  .co  m
}

From source file:com.cloudera.lib.wsrs.JSONProvider.java

@Override
public void writeTo(JSONStreamAware jsonStreamAware, Class<?> aClass, Type type, Annotation[] annotations,
        MediaType mediaType, MultivaluedMap<String, Object> stringObjectMultivaluedMap,
        OutputStream outputStream) throws IOException, WebApplicationException {
    Writer writer = new OutputStreamWriter(outputStream);
    jsonStreamAware.writeJSONString(writer);
    writer.write(ENTER);
    writer.flush();//www.  j  a v  a2 s  . com
}

From source file:org.cbio.portal.pipelines.foundation.FusionDataWriter.java

@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
    String stagingFile = outputDirectory + "data_fusions.txt";

    PassThroughLineAggregator aggr = new PassThroughLineAggregator();
    flatFileItemWriter.setLineAggregator(aggr);
    flatFileItemWriter.setHeaderCallback(new FlatFileHeaderCallback() {
        @Override//w w w . java 2s . c o  m
        public void writeHeader(Writer writer) throws IOException {
            writer.write(getHeader());
        }
    });
    flatFileItemWriter.setResource(new FileSystemResource(stagingFile));
    flatFileItemWriter.open(executionContext);
}

From source file:com.cloudera.cli.validator.components.DescriptorRunner.java

/**
 * Run the validation against a byte array.
 *
 * @param name The name of the target that was loaded into the byte array.
 * @param data The byte array//from   ww w  .  j av a2s.c om
 * @param writer to write validation errors to
 * @return true if validation passed, false otherwise
 * @throws IOException if we can't write to the outputStream
 */
public boolean run(String name, byte[] data, Writer writer) throws IOException {
    try {
        writer.write("Validating: " + name + "\n");
        T descriptor = parser.parse(data);
        Set<String> errors = validator.validate(descriptor);
        for (String error : errors) {
            writer.write(String.format("==> %s\n", error));
        }
        return errors.isEmpty();
    } catch (UnrecognizedPropertyException e) {
        List<String> elements = Lists.newArrayList();
        for (Reference r : e.getPath()) {
            elements.add(r.getFieldName());
        }
        writer.write(String.format("==> Unrecognized field \"%s\". Recognized fields are \"%s\"\n",
                Joiner.on('.').join(elements), e.getKnownPropertyIds().toString()));
        return false;
    } catch (Exception e) {
        writer.write(String.format("==> %s\n", e.getMessage()));
        return false;
    }
}

From source file:com.icesoft.faces.async.common.PushServerAdaptingServlet.java

public void service(final Request request) throws Exception {
    request.respondWith(new StreamingContentHandler("text/plain", "UTF-8") {
        public void writeTo(Writer writer) throws IOException {
            writer.write("Push Server is enabled.\n");
            writer.write("Check your server configuration.\n");
        }/*w w  w .  ja va 2  s .  c o  m*/
    });
}

From source file:com.joliciel.talismane.languageDetector.DefaultLanguageDetectorProcessor.java

@Override
public void onNextText(String text, List<WeightedOutcome<Locale>> results, Writer writer) {
    try {//from  w  w  w .  j a  va 2  s .  c o  m
        if (writer == null)
            writer = out;

        writer.write(text + "\n");
        for (WeightedOutcome<Locale> result : results) {
            writer.write(result.getOutcome().toLanguageTag() + "\t" + result.getWeight() + "\n");
        }
        writer.flush();
    } catch (IOException e) {
        LogUtils.logError(LOG, e);
        throw new RuntimeException(e);
    }
}

From source file:IOUtils.java

/**
 * Writes bytes from a <code>byte[]</code> to chars on a <code>Writer</code>
 * using the default character encoding of the platform.
 * <p>/* ww w  .j av  a  2 s . c  o  m*/
 * This method uses {@link String#String(byte[])}.
 * 
 * @param data  the byte array to write, do not modify during output,
 * null ignored
 * @param output  the <code>Writer</code> to write to
 * @throws NullPointerException if output is null
 * @throws IOException if an I/O error occurs
 * @since Commons IO 1.1
 */
public static void write(byte[] data, Writer output) throws IOException {
    if (data != null) {
        output.write(new String(data));
    }
}

From source file:IOUtils.java

/**
 * Writes chars from a <code>char[]</code> to a <code>Writer</code>
 * using the default character encoding of the platform.
 * /*w  w w.j  a  va2  s.c om*/
 * @param data  the char array to write, do not modify during output,
 * null ignored
 * @param output  the <code>Writer</code> to write to
 * @throws NullPointerException if output is null
 * @throws IOException if an I/O error occurs
 * @since Commons IO 1.1
 */
public static void write(char[] data, Writer output) throws IOException {
    if (data != null) {
        output.write(data);
    }
}

From source file:IOUtils.java

/**
 * Writes chars from a <code>String</code> to a <code>Writer</code>.
 * //  ww  w  . j  a v  a2s .co m
 * @param data  the <code>String</code> to write, null ignored
 * @param output  the <code>Writer</code> to write to
 * @throws NullPointerException if output is null
 * @throws IOException if an I/O error occurs
 * @since Commons IO 1.1
 */
public static void write(String data, Writer output) throws IOException {
    if (data != null) {
        output.write(data);
    }
}