Java Code Examples for java.io.Writer#append()

The following examples show how to use java.io.Writer#append() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: gemfirexd-oss   File: PluckStacks.java    License: Apache License 2.0 6 votes vote down vote up
public void writeTo(Writer w) throws IOException {
  if (DEBUG) {
    w.append("stack.name='"+getThreadName()+"' runnable="+this.runnable + " lines=" + lines.size());
    w.append("\n");
  }
  boolean first = true;
  for (String line: lines) {
    w.append(line);
    w.append("\n");
    if (first) {
      first = false;
      if (breadcrumbs != null) {
        for (String bline: breadcrumbs) {
          w.append(bline).append("\n");
        }
      }
    }
  }
}
 
Example 2
Source Project: trader   File: DisplayMessage.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	String encodedMessage = request.getParameter("message");
	String message = URLDecoder.decode(encodedMessage, "UTF-8");
	Writer writer = response.getWriter();
	writer.append("<!DOCTYPE html>");
	writer.append("<html>");
	writer.append("  <head>");
	writer.append("    <title>Stock Trader</title>");
	writer.append("    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />");
	writer.append("  </head>");
	writer.append("  <body>");
	writer.append("    <img src=\"header.jpg\" width=\"534\" height=\"200\"/>");
	writer.append("    <p/>");
	writer.append("    "+message);
	writer.append("    <p/>");
	writer.append("    <form method=\"post\"/>");
	writer.append("      <input type=\"submit\" name=\"submit\" value=\"OK\" style=\"font-family: sans-serif; font-size: 16px;\" />");
	writer.append("    </form>");
	writer.append("    <br/>");
	writer.append("    <a href=\"https://github.com/IBMStockTrader\">");
	writer.append("      <img src=\"footer.jpg\"/>");
	writer.append("    </a>");
	writer.append("  </body>");
	writer.append("</html>");
}
 
Example 3
public void persist(List<FileSupplier> fileSuppliers, Writer writer) throws IOException {
    Gson gson = new Gson();
    ImmutableList.Builder<Record> records = ImmutableList.builder();
    for (FileSupplier fileSupplier : fileSuppliers) {
        if (fileSupplier instanceof SplitFileSupplier) {
            records.add(new Record(
                    ((SplitFileSupplier) fileSupplier).getFilterData().getFilterType(),
                    ((SplitFileSupplier) fileSupplier).getFilterData().getIdentifier(),
                    fileSupplier.get().getName()));
        }
    }
    String recordsAsString = gson.toJson(records.build());
    try {
        writer.append(recordsAsString);
    } finally {
        writer.close();
    }
}
 
Example 4
@Override
public void toXml(Writer result) throws IOException {
    if (seriesInstanceUID != null) {
        result.append("\n<");
        result.append(Xml.Level.SERIES.getTagName());
        result.append(" ");
        Xml.addXmlAttribute(Tag.SeriesInstanceUID, seriesInstanceUID, result);
        Xml.addXmlAttribute(Tag.SeriesDescription, seriesDescription, result);
        Xml.addXmlAttribute(Tag.SeriesNumber, seriesNumber, result);
        Xml.addXmlAttribute(Tag.Modality, modality, result);
        Xml.addXmlAttribute("DirectDownloadThumbnail", thumbnail, result);
        Xml.addXmlAttribute("WadoTransferSyntaxUID", wadoTransferSyntaxUID, result);
        Xml.addXmlAttribute("WadoCompressionRate",
            wadoCompression < 1 ? null : Integer.toString(wadoCompression), result);
        result.append(">");

        List<SopInstance> list = new ArrayList<>(sopInstanceMap.values());
        Collections.sort(list);
        for (SopInstance s : list) {
            s.toXml(result);
        }
        result.append("\n</");
        result.append(Xml.Level.SERIES.getTagName());
        result.append(">");
    }
}
 
Example 5
/**
 * Appends metadata to a Writer. Does not flush the Writer.
 */
protected void appendGetMetadata(HttpServletRequest request, HttpServletResponse response, Writer responseWriter, IFileStore file) throws IOException,
		NoSuchAlgorithmException, JSONException, CoreException {
	JSONObject metadata = getMetadata(request, file);
	response.setHeader(ProtocolConstants.KEY_ETAG, metadata.getString(ProtocolConstants.KEY_ETAG));
	response.setHeader("Cache-Control", "no-cache"); //$NON-NLS-1$ //$NON-NLS-2$
	OrionServlet.decorateResponse(request, metadata, JsonURIUnqualificationStrategy.ALL);
	responseWriter.append(metadata.toString());
}
 
Example 6
Source Project: sumk   File: HttpMonitor.java    License: Apache License 2.0 5 votes vote down vote up
private void outputActs(HttpServletRequest req, Writer writer) throws IOException {
	if (!"1".equals(req.getParameter("acts"))) {
		return;
	}
	writer.append(Arrays.toString(HttpActions.acts()));
	writer.append(TYPE_SPLIT);
}
 
Example 7
Source Project: gama   File: TestProcessor.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void writeTests(final ProcessorContext context, final Writer sb) throws IOException {
	sb.append("experiment ").append(toJavaString("Tests for " + context.currentPlugin)).append(" type: test {");
	for (final StringBuilder tests : serializedElements.values()) {
		sb.append(ln);
		sb.append(tests);
	}
	sb.append(ln).append('}');
	namesAlreadyUsed.clear();
}
 
Example 8
Source Project: sundrio   File: FieldDirective.java    License: Apache License 2.0 5 votes vote down vote up
private void writeField(Writer writer, Property field, String block) throws IOException {
    if (field != null) {
        writer.append(field.toString());

        if (field.getAttribute(INIT) != null) {
            writer.append(" = ").append(getDefaultValue(field));
        }
    }
    writer.append(";");
}
 
Example 9
Source Project: Elasticsearch   File: Joda.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void printTo(Writer out, long instant, Chronology chrono, int displayOffset, DateTimeZone displayZone, Locale locale) throws IOException {
    if (hasMilliSecondPrecision) {
        out.write(String.valueOf(instant));
    } else {
        out.append(String.valueOf(instant / 1000));
    }
}
 
Example 10
Source Project: anno4j   File: DiskBlobStoreTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testAbandon() throws Exception {
	BlobVersion trx1 = store.newVersion("urn:test:trx1");
	Writer file = trx1.open("urn:test:file").openWriter();
	file.append("test1");
	trx1.commit();
	assertEquals(Arrays.asList(), Arrays.asList(store.getRecentModifications()));
	store.erase();
	assertEmpty(dir);
}
 
Example 11
Source Project: netbeans   File: HTMLDialogProcessor.java    License: Apache License 2.0 5 votes vote down vote up
private void generateTechIds(Writer w, String[] techIds) throws IOException {
    if (techIds.length == 0) {
        return;
    }
    w.append("addTechIds(");
    String sep = "";
    for (String id : techIds) {
        w.append(sep);
        w.append('"');
        w.append(id);
        w.append('"');
        sep = ", ";
    }
    w.append(").\n");
}
 
Example 12
Source Project: super-cloudops   File: TextNode.java    License: Apache License 2.0 5 votes vote down vote up
public void writeAll(Writer writer, IHTMLFilter htmlFilter, boolean convertIntoValidXML, boolean filterText)
		throws IOException {

	if (filterText) {
		return;
	}

	if (htmlFilter != null) {
		String newText = htmlFilter.modifyNodeText(tagName, getText());
		writer.append(newText);
	} else {
		writer.append(getText());
	}
}
 
Example 13
/**
 * Saves the models to the file.
 * @param context the color context to be used for the generation
 * @throws IOException if any IO error happens during opening, writing or closing the file
 */
public void saveToFile(IColorGenerationContext context) throws IOException {
	Writer writer = new FileWriter(file);
	try {
		for (IModel model : models) {
			writer.append(model.toScad(context).getScad());
		}
	}
	finally {
		writer.close();
	}
}
 
Example 14
Source Project: artio   File: AcceptorGenerator.java    License: Apache License 2.0 5 votes vote down vote up
private void generateAcceptorClass(final Writer acceptorOutput) throws IOException
{
    acceptorOutput.append(fileHeader(packageName));
    acceptorOutput.append(
        "\n" +
        "public interface " + DICTIONARY_ACCEPTOR + "\n" +
        "{\n"
    );
}
 
Example 15
/**
 Writes the header of the R script (e.g., import libraries)

 @param writer is the output where the header will be written to
 @param engine is the engine to export
 @throws IOException if any error occurs upon writing on the writer

 */
protected void writeScriptHeader(Writer writer, Engine engine) throws IOException {
    writer.append("#Code automatically generated with " + FuzzyLite.LIBRARY + ".\n\n");
    writer.append("library(ggplot2);\n");
    writer.append("\n");
    writer.append("engine.name = \"" + engine.getName() + "\"\n");
    if (!Op.isEmpty(engine.getDescription())) {
        writer.append(String.format(
                "engine.description = \"%s\"\n", engine.getDescription()));
    }
    writer.append("engine.fll = \"" + new FllExporter().toString(engine) + "\"\n\n");
}
 
Example 16
@Override
public void toSerializable(final LogEvent event, final Writer writer) throws IOException {
    if (complete && eventCount > 0) {
        writer.append(", ");
    }
    super.toSerializable(event, writer);
}
 
Example 17
Source Project: ipst   File: EventsHelper.java    License: Mozilla Public License 2.0 5 votes vote down vote up
public static void    addLine(Writer writer, String line) {
    try {
        writer.append(line);
        writer.append(StaticData.NEW_LINE);
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    }
}
 
Example 18
Source Project: shipkit   File: DefaultReleaseNotesData.java    License: MIT License 4 votes vote down vote up
@Override
public void toJson(Writer writable) throws IOException {
    writable.append(toJson());
}
 
Example 19
Source Project: groovy   File: YamlBuilder.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * The YAML builder implements the <code>Writable</code> interface,
 * so that you can have the builder serialize itself the YAML payload to a writer.
 * <p>
 * Example:
 * <pre><code class="groovyTestCase">
 * def yaml = new groovy.yaml.YamlBuilder()
 * yaml { temperature 37 }
 *
 * def out = new StringWriter()
 * out {@code <<} yaml
 *
 * assert out.toString() == '''---
 * temperature: 37
 * '''
 * </code></pre>
 *
 * @param out a writer on which to serialize the YAML payload
 * @return the writer
 */
@Override
public Writer writeTo(Writer out) throws IOException {
    return out.append(toString());
}
 
Example 20
/**
 Writes an R script plotting multiple surfaces based on a data frame
 generated with the given number of values and scope for the two input
 variables on the output variables.

 @param engine is the engine to export
 @param writer is the output where the engine will be written to
 @param a is the first input variable
 @param b is the second input variable
 @param reader is an input stream of data whose lines contain
 space-separated input values
 @param outputVariables are the output variables to create the surface for
 @throws IOException if any error occurs upon writing on the writer

 */
public void writeScriptExportingDataFrame(Engine engine, Writer writer,
        InputVariable a, InputVariable b, Reader reader,
        List<OutputVariable> outputVariables) throws IOException {
    writeScriptHeader(writer, engine);

    writer.append("engine.fldFile = \"");
    new FldExporter().write(engine, writer, reader);
    writer.append("\"\n\n");

    writer.append("engine.df = read.delim(textConnection(engine.fld), header=TRUE, "
            + "sep=\" \", strip.white=TRUE)\n\n");

    writeScriptPlots(writer, a, b, outputVariables);
}