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:framework.GroovyTemplateEngine.java

private static void addChar(Writer writer, int s, int ch) throws IOException {
    if (ch == '\'' && s != 3 && s != 6) {
        writer.append("\\'");
    } else if (ch == '\\') {
        writer.append("\\\\");
    } else if (ch == '$') {
        writer.append("\\$");
    } else {/* w  ww.j a va  2 s . c om*/
        writer.write(ch);
    }
}

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

private static void appendMultiValues(Writer writer, Collection<?> value) throws IOException {
    for (Iterator<?> it = value.iterator(); it.hasNext();) {
        writer.append("         <value>").append(escapeXml(it.next().toString())).append("</value>")
                .append("\n");
    }//from w w  w .j a  v  a2 s .com
}

From source file:org.commoncrawl.util.HDFSUtils.java

public static void listToTextFile(List<String> lines, FileSystem fs, Path path) throws IOException {
    Writer writer = new OutputStreamWriter(fs.create(path), Charset.forName("UTF-8"));
    try {/*from w w  w. j  a v  a2s .co  m*/
        for (String line : lines) {
            writer.write(line);
            writer.append("\n");
        }
        writer.flush();
    } finally {
        writer.close();
    }
}

From source file:heigit.ors.util.FileUtility.java

public static void writeFile(String fileName, String encoding, String content) throws IOException {
    Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), encoding));
    out.append(content);
    out.flush();//from  w w w .  ja  v  a 2s .  c  o  m
    out.close();
}

From source file:de.quist.samy.remocon.RemoteSession.java

private static Writer writeText(Writer writer, String text) throws IOException {
    return writer.append((char) text.length()).append((char) 0x00).append(text);
}

From source file:com.dm.material.dashboard.candybar.helpers.ReportBugsHelper.java

@Nullable
public static String buildCrashLog(Context context, File folder, String stackTrace) {
    try {/*  ww  w.  j av a  2 s. c  o m*/
        if (stackTrace.length() == 0)
            return null;

        File fileDir = new File(folder.toString() + "/crashlog.txt");
        String deviceInfo = DeviceHelper.getDeviceInfoForCrashReport(context);
        Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileDir), "UTF8"));
        out.append(deviceInfo).append(stackTrace);
        out.flush();
        out.close();

        return fileDir.toString();
    } catch (Exception | OutOfMemoryError e) {
        Log.d(Tag.LOG_TAG, Log.getStackTraceString(e));
    }
    return null;
}

From source file:ch.zhaw.iamp.rct.weights.Weights.java

private static void matrixToCsv(final RealMatrix matrix, final String targetFilePath) throws IOException {
    Writer out = new FileWriter(targetFilePath);

    for (int i = 0; i < matrix.getRowDimension(); ++i) {
        for (int j = 0; j < matrix.getColumnDimension(); ++j) {
            out.append("" + matrix.getEntry(i, j));
            if (j < matrix.getColumnDimension() - 1) {
                out.append(",");
            }//ww  w .  j a  va 2s.  c  o  m
        }
        out.append("\n");
        out.flush();
    }

}

From source file:org.apache.sshd.SshServerDevelopment.java

protected static final void testAuthorizedPublicKeysAuthenticator(BufferedReader in, PrintStream out,
        SshServer sshd) throws Exception {
    /*//  ww w.  j  ava  2  s . co  m
    {
    URL url=ANCHOR.getResource(ANCHOR.getSimpleName() + "-authorized_keys");
    assertNotNull("Cannot find authorized keys resource", url);
    Collection<CryptoKeyEntry>  entries=CryptoKeyEntry.readAuthorizedKeys(url);
    server.setPublickeyAuthenticator(PublickeyAuthenticatorUtils.authorizedKeysAuthenticator(entries));
    }
    */

    final CommandFactory cmdFactory = new CommandFactory() {
        @Override
        public Command createCommand(final String command) {
            return new AbstractCommand(command) {
                @Override
                public void start(Environment env) throws IOException {
                    Map<String, String> values = env.getEnv();
                    if (ExtendedMapUtils.isEmpty(values)) {
                        logger.warn("start(" + command + ") no environment");
                    } else {
                        for (Map.Entry<String, String> e : values.entrySet()) {
                            logger.info("start(" + command + ")[" + e.getKey() + "]: " + e.getValue());
                        }
                    }

                    try {
                        Writer err = new CloseShieldWriter(new OutputStreamWriter(getErrorStream()));
                        try {
                            err.append(command).append(": N/A").append(SystemUtils.LINE_SEPARATOR);
                        } finally {
                            err.close();
                        }
                    } finally {
                        ExitCallback cbExit = getExitCallback();
                        cbExit.onExit(-1, "Failed");
                    }
                }
            };
        }
    };
    sshd.setCommandFactory(cmdFactory);
    sshd.setShellFactory(ECHO_SHELL);
    waitForExit(in, out, sshd);
}

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

/**
 * Write a multipart boundary//  ww w.  ja  va2 s.c om
 *
 * @param writer the output writer
 * @param boundary the boundary string
 * @param end false if inner boundary, true if final boundary
 */
private static void writeBoundary(Writer writer, String boundary, boolean end) throws IOException {
    writer.append("--");
    writer.append(boundary);
    if (end) {
        writer.append("--");
    }
    writer.append("\r\n");
}

From source file:org.apache.sling.distribution.util.impl.DigestUtils.java

private static void readDigest(MessageDigest messageDigest, Writer writer) throws IOException {
    final byte[] data = messageDigest.digest();
    for (byte element : data) {
        int intVal = element & 0xff;
        if (intVal < 0x10) {
            // append a zero before a one digit hex
            // number to make it two digits.
            writer.append('0');
        }//from w  w w . j  a  v  a2s .  c  om
        writer.append(toHexString(intVal));
    }
}