Example usage for java.io StringWriter append

List of usage examples for java.io StringWriter append

Introduction

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

Prototype

public StringWriter append(char c) 

Source Link

Document

Appends the specified character to this writer.

Usage

From source file:nz.govt.natlib.ndha.manualdeposit.bulkupload.BulkUploadForm.java

public void showError(final String header, final String message, final Exception ex) {
    final StringWriter prompt = new StringWriter();
    if (message != null) {
        prompt.append(message);
        prompt.append("\n");
    }/*from www .j  a  v a  2 s  .c  om*/
    if (ex != null) {
        LOG.error(message, ex);
        if (ex.getMessage() != null) {
            prompt.append(ex.getMessage());
            prompt.append("\n");
        }
        final StringWriter writer = new StringWriter();
        ex.printStackTrace(new PrintWriter(writer));
        prompt.append(writer.toString());
    }
    JOptionPane.showMessageDialog(this, prompt.toString(), header, JOptionPane.ERROR_MESSAGE);
}

From source file:org.openhab.binding.samsungtv.internal.protocol.RemoteController.java

private String createKeyDataPayload(KeyCode key) throws IOException {
    /* @formatter:off/*from   w  w w  .j a v a2s. c o m*/
     * 
     * Payload:
     * 
     * offset value and description
     * ------ ---------------------
     * 0x18   three 0x00 bytes
     * 0x1b   0x000c - key code size (little endian)
     * 0x1d   key code encoded as base64 string
     * 
     * @formatter:on
     */

    StringWriter writer = new StringWriter();
    writer.append((char) 0x00);
    writer.append((char) 0x00);
    writer.append((char) 0x00);
    writeBase64String(writer, key.getValue());
    writer.flush();
    return writer.toString();
}

From source file:nl.knaw.dans.dccd.web.search.SearchResultDownloadPage.java

private String getDataAsTabDelimitedText() {
    java.io.StringWriter sw = new StringWriter();

    // TODO add a line for each search Hit
    for (int i = 0; i < 10; i++) {
        sw.append("Just \t some \t test\n");
    }/*from   w  ww  . j  a  va 2 s.  com*/
    sw.append("Mehr Informationen \t ber die DCCD Nutzung \t finden Sie hier.");

    return sw.toString();
}

From source file:org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.help.HelpManager.java

void appendURL(StringWriter w, String conceptName) {
    String[] parts = conceptName.split("/");
    int n = parts.length;
    String course = parts[0];/*from www. j  a v  a2 s  .c  om*/
    w.append("/").append(course).append("#").append(parts[n - (n > 1 ? 2 : 1)]).append("-")
            .append(parts[n - 1]);
}

From source file:org.mule.module.http.functional.listener.HttpListenerPersistentConnectionsTestCase.java

private String getResponse(Socket socket) {
    try {//from   ww  w.j  a  v  a2 s  .  c o  m
        StringWriter writer = new StringWriter();
        BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        if (reader != null) {
            String line;
            while (!StringUtils.isEmpty(line = reader.readLine())) {
                writer.append(line).append("\r\n");
            }
        }
        return writer.toString();
    } catch (IOException e) {
        return null;
    }
}

From source file:org.eclipse.packagedrone.utils.deb.build.DebianPackageWriter.java

protected ContentProvider createConfFilesContent() throws IOException {
    if (this.confFiles.isEmpty()) {
        return ContentProvider.NULL_CONTENT;
    }//ww  w. ja  v a2 s  .  c  o  m

    final StringWriter sw = new StringWriter();

    for (final String confFile : this.confFiles) {
        sw.append(confFile).append('\n');
    }

    sw.close();
    return new StaticContentProvider(sw.toString());
}

From source file:org.openhab.binding.samsungtv.internal.protocol.RemoteControllerLegacy.java

private String createRegistrationPayload(String ip) throws IOException {
    /*/*from w ww . j  a  va2  s  .com*/
     * Payload starts with 2 bytes: 0x64 and 0x00, then comes 3 strings
     * encoded with base64 algorithm. Every string is preceded by 2-bytes
     * field containing encoded string length.
     *
     * These three strings are as follow:
     *
     * remote control device IP, unique ID  value to distinguish
     * controllers, name  it will be displayed as controller name.
     */

    StringWriter w = new StringWriter();
    w.append((char) 0x64);
    w.append((char) 0x00);
    writeBase64String(w, ip);
    writeBase64String(w, uniqueId);
    writeBase64String(w, appName);
    w.flush();
    return w.toString();
}

From source file:edu.harvard.i2b2.pm.util.PMUtil.java

public String generateMessageId() {
    StringWriter strWriter = new StringWriter();
    for (int i = 0; i < 20; i++) {
        int num = getValidAcsiiValue();
        //System.out.println("Generated number: " + num + " char: "+(char)num);
        strWriter.append((char) num);
    }//from   w  w w  . j  a v  a  2 s. com
    return strWriter.toString();
}

From source file:de.mpg.escidoc.services.cone.util.TreeFragment.java

/**
 * {@inheritDoc}//  ww w .j  av a2 s. c  o  m
 */
public String toJson() {
    if (size() == 0) {
        try {
            return "\"" + PropertyReader.getProperty("escidoc.cone.service.url") + subject.replace("\"", "\\\"")
                    + "\"";
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else {
        StringWriter writer = new StringWriter();
        writer.append("{\n");
        if (!subject.startsWith("genid:")) {
            writer.append("\"id\" : \"");
            try {
                writer.append(
                        PropertyReader.getProperty("escidoc.cone.service.url") + subject.replace("\"", "\\\""));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            writer.append("\",\n");
        }
        for (Iterator<String> iterator = keySet().iterator(); iterator.hasNext();) {
            String key = iterator.next();
            writer.append("\"");
            writer.append(key.replaceAll("[" + REGEX_PREDICATE_REPLACE + "]+", "_").replace("\"", "\\\""));
            writer.append("\" : ");
            if (get(key).size() == 1) {
                writer.append(get(key).get(0).toJson());
            } else {
                writer.append("[\n");
                for (Iterator<LocalizedTripleObject> iterator2 = get(key).iterator(); iterator2.hasNext();) {
                    LocalizedTripleObject object = (LocalizedTripleObject) iterator2.next();
                    writer.append(object.toJson());
                    if (iterator2.hasNext()) {
                        writer.append(",");
                    }
                    writer.append("\n");
                }
                writer.append("]");
            }
            if (iterator.hasNext()) {
                writer.append(",\n");
            }
        }
        writer.append("\n}\n");
        return writer.toString();
    }
}

From source file:org.openhab.binding.samsungtv.internal.protocol.RemoteControllerLegacy.java

private String createKeyDataPayload(KeyCode key) throws IOException {
    /* @formatter:off/*from   w  w  w .jav a  2  s.  c  o m*/
    *
    * Payload:
    *
    * offset value and description
    * ------ ---------------------
    * 0x18   three 0x00 bytes
    * 0x1b   0x000c - key code size (little endian)
    * 0x1d   key code encoded as base64 string
    *
    * @formatter:on
    */

    StringWriter writer = new StringWriter();
    writer.append((char) 0x00);
    writer.append((char) 0x00);
    writer.append((char) 0x00);
    writeBase64String(writer, key.getValue());
    writer.flush();
    return writer.toString();
}