下面列出了java.io.Writer#append ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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");
}
}
}
}
}
/**
* @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>");
}
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();
}
}
@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(">");
}
}
/**
* 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());
}
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);
}
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();
}
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(";");
}
@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));
}
}
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);
}
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");
}
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());
}
}
/**
* 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();
}
}
private void generateAcceptorClass(final Writer acceptorOutput) throws IOException
{
acceptorOutput.append(fileHeader(packageName));
acceptorOutput.append(
"\n" +
"public interface " + DICTIONARY_ACCEPTOR + "\n" +
"{\n"
);
}
/**
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");
}
@Override
public void toSerializable(final LogEvent event, final Writer writer) throws IOException {
if (complete && eventCount > 0) {
writer.append(", ");
}
super.toSerializable(event, writer);
}
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);
}
}
@Override
public void toJson(Writer writable) throws IOException {
writable.append(toJson());
}
/**
* 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());
}
/**
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);
}