Example usage for java.io Writer append

List of usage examples for java.io Writer append

Introduction

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

Prototype

public Writer append(char c) throws IOException 

Source Link

Document

Appends the specified character to this writer.

Usage

From source file:org.inaetics.remote.EndpointDescriptorWriter.java

private static void appendMultiValueProperty(Writer writer, String key, Object value) throws IOException {

    Class<?> componentType = determineComponentType(value);
    if (ValueTypes.get(componentType) == null) {
        throw new IllegalStateException();
    }//from  www . j  av  a2s .com
    if (componentType.equals(String.class)) {
        writer.append("   <property name=\"").append(escapeXml(key)).append("\">\n");
    } else {
        writer.append("   <property name=\"").append(escapeXml(key)).append("\" value-type=\"")
                .append(componentType.getSimpleName()).append("\">\n");
    }
    if (value.getClass().isArray()) {
        List<Object> objectList = new ArrayList<Object>();
        int length = Array.getLength(value);
        for (int i = 0; i < length; i++) {
            objectList.add(Array.get(value, i));
        }
        writer.append("      <array>").append("\n");
        appendMultiValues(writer, objectList);
        writer.append("      </array>\n");
    } else if (value instanceof List<?>) {
        writer.append("      <list>").append("\n");
        appendMultiValues(writer, (List<?>) value);
        writer.append("      </list>\n");
    } else if (value instanceof Set<?>) {
        writer.append("      <set>").append("\n");
        appendMultiValues(writer, (Set<?>) value);
        writer.append("      </set>\n");
    }
    writer.append("   </property>\n");
}

From source file:com.android.email.mail.transport.Rfc822Output.java

/**
 * Write a single header with no wrapping or encoding
 *
 * @param writer the output writer/*  w  ww .j  a v a2s. c o m*/
 * @param name the header name
 * @param value the header value
 */
private static void writeHeader(Writer writer, String name, String value) throws IOException {
    if (value != null && value.length() > 0) {
        writer.append(name);
        writer.append(": ");
        writer.append(value);
        writer.append("\r\n");
    }
}

From source file:com.android.email.mail.transport.Rfc822Output.java

/**
 * Write a single header using appropriate folding & encoding
 *
 * @param writer the output writer//www.  j a  v  a2  s.co m
 * @param name the header name
 * @param value the header value
 */
private static void writeEncodedHeader(Writer writer, String name, String value) throws IOException {
    if (value != null && value.length() > 0) {
        writer.append(name);
        writer.append(": ");
        writer.append(MimeUtility.foldAndEncode2(value, name.length() + 2));
        writer.append("\r\n");
    }
}

From source file:com.android.email.mail.transport.Rfc822Output.java

/**
 * Unpack, encode, and fold address(es) into a header
 *
 * @param writer the output writer//from   w w w. java 2  s  .  c  om
 * @param name the header name
 * @param value the header value (a packed list of addresses)
 */
private static void writeAddressHeader(Writer writer, String name, String value) throws IOException {
    if (value != null && value.length() > 0) {
        writer.append(name);
        writer.append(": ");
        writer.append(MimeUtility.fold(Address.packedToHeader(value), name.length() + 2));
        writer.append("\r\n");
    }
}

From source file:org.azyva.dragom.test.integration.IntegrationTestSuite.java

/**
 * Appends content to a text file.//from  w w w.j  ava  2s.  c  o m
 *
 * @param pathFile Path to the file.
 * @param content Content.
 */
public static void appendToFile(Path pathFile, String content) {
    Writer writerFile;

    try {
        writerFile = new FileWriter(pathFile.toFile(), true);
        writerFile.append(content);
        writerFile.close();
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}

From source file:org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor.java

/**
 * Writes a nodes file to disk.//from   w w  w  . j a  v a 2  s. co m
 *
 * @param taskContext The task taskContext from which to extract the nodes file from.
 * @return The absolute path of the nodes file.
 * @throws IOException
 */
private static String writeNodesFile(TaskContext taskContext) throws IOException {
    List<String> nodesHosts = taskContext.getNodesHosts();

    if (nodesHosts.isEmpty()) {
        return "";
    } else {
        File directory;
        if (taskContext.getNodeDataSpaceURIs().getScratchURI() == null
                || taskContext.getNodeDataSpaceURIs().getScratchURI().isEmpty()) {
            directory = new File(".");
        } else {
            directory = new File(taskContext.getNodeDataSpaceURIs().getScratchURI());
        }
        File nodesFile = new File(directory, NODES_FILE_DIRECTORY_NAME + "_" + taskContext.getTaskId());

        Writer outputWriter = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(nodesFile), PAProperties.getFileEncoding()));
        for (String nodeHost : nodesHosts) {
            outputWriter.append(nodeHost).append(System.lineSeparator());
        }
        outputWriter.close();

        return nodesFile.getAbsolutePath();
    }
}

From source file:org.inaetics.remote.EndpointDescriptorWriter.java

private static void appendSingleValueProperty(Writer writer, String key, Object value) throws IOException {
    if (ValueTypes.get(value.getClass()) == null) {
        throw new IllegalStateException("Unsupported type : " + value.getClass());
    }/* ww w  .  j av  a2 s  . c o m*/
    if (value instanceof String) {
        String string = (String) value;
        if (string.trim().startsWith("<") && isWellFormedXml(string)) {
            writer.append("    <property name=\"").append(escapeXml(key)).append("\">\n").append("      <xml>")
                    .append((String) value).append("</xml>\n").append("    </property>\n");
        } else {
            writer.append("   <property name=\"").append(escapeXml(key)).append("\" value=\"")
                    .append(escapeXml(string)).append("\"/>\n");
        }
    } else {
        writer.append("   <property name=\"").append(escapeXml(key))
                .append("\" value-type=\"" + value.getClass().getSimpleName() + "\" value=\"")
                .append(escapeXml(value.toString())).append("\"/>\n");
    }
}

From source file:org.jboss.windup.reporting.html.freemarker.PieSerializer.java

public static void drawPie(Writer writer, String archiveName, Map<String, Integer> data) throws IOException {
    if (data.size() == 0) {
        // writer.append("<!--No pie.-->");
        return;//ww  w. j  a  va2s  .c  om
    }

    List<PieSort> pieList = topX(data, 9);
    String id = generateId(archiveName);

    String dataId = "data_" + id;
    String pieId = id + "_Pie";
    writer.append("<div id='" + pieId + "' class='windupPieGraph'></div>");
    writer.append("<script type='text/javascript'>");
    writer.append(NL).append("$(function () {");
    writer.append(NL).append("   var " + dataId + " = [];");

    int i = 0;
    for (PieSort p : pieList) {
        writer.append(NL)
                .append("   data_" + id + "[" + i + "] = { label: '" + p.key + "', data: " + p.value + " };");
        i++;
    }
    writer.append(NL).append("   $.plot($('#" + pieId + "'), " + dataId + ", {");
    writer.append(NL).append("      series: {");
    writer.append(NL).append("         pie: {");
    writer.append(NL).append("            show: true");
    writer.append(NL).append("         }");
    writer.append(NL).append("      }");
    writer.append(NL).append("   });");
    writer.append(NL).append("});");

    writer.append(NL).append("</script>");
}

From source file:com.tct.emailcommon.internet.Rfc822Output.java

/**
 * Unpack, encode, and fold address(es) into a header
 *
 * @param writer the output writer/*from   w  w  w.ja va  2  s  .co m*/
 * @param name the header name
 * @param value the header value (a packed list of addresses)
 */
private static void writeAddressHeader(Writer writer, String name, String value) throws IOException {
    if (value != null && value.length() > 0) {
        writer.append(name);
        writer.append(": ");
        writer.append(MimeUtility.fold(Address.reformatToHeader(value), name.length() + 2));
        writer.append("\r\n");
    }
}

From source file:org.trend.hgraph.util.FindCandidateEntities.java

private static void printOutTargets(Graph g, String id, long mn, String vf, String ef) throws IOException {
    Writer vw = null;/*w  ww .j a  v  a  2  s. c  om*/
    Writer ew = null;

    try {
        vw = new FileWriter(vf, true);
        ew = new FileWriter(ef, true);

        final Writer fvw = vw;
        final Writer few = ew;
        doBreadthFirstSearch(g, id, mn, new SearchStrategy() {

            @Override
            public void processV(Vertex v) throws IOException {
                String id = v.getId() + "";
                try {
                    fvw.append(id + "\n");
                } catch (IOException e) {
                    String msg = "write vertex id to file failed, id:" + id;
                    System.err.println(msg);
                    throw new IOException(msg, e);
                }
            }

            @Override
            public void processE(Edge e) throws IOException {
                String id = e.getId() + "";
                try {
                    few.append(id + "\n");
                } catch (IOException ex) {
                    String msg = "write edge id to file failed, id:" + id;
                    System.err.println(msg);
                    throw new IOException(msg, ex);
                }
            }
        });
    } finally {
        IOUtils.closeQuietly(vw);
        IOUtils.closeQuietly(ew);
    }
}