Example usage for java.io Writer write

List of usage examples for java.io Writer write

Introduction

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

Prototype

public void write(String str) throws IOException 

Source Link

Document

Writes a string.

Usage

From source file:Main.java

/**
 * Emit a single state in the <code>dot</code> language. 
 *///  ww w  . j  av a2 s  .  co  m
private static void emitDotState(Writer out, String name, String shape, String color, String label)
        throws IOException {
    out.write("  " + name + " [" + (shape != null ? "shape=" + shape : "") + " "
            + (color != null ? "color=" + color : "") + " "
            + (label != null ? "label=\"" + label + "\"" : "label=\"\"") + " " + "]\n");
}

From source file:Main.java

public final static void writeLine(Writer w, int deep, String line) throws IOException {
    if (deep >= 0)
        writeDeep(w, deep);/*from   w w w. j ava 2  s. c  o m*/
    w.write(line);
    w.write('\n');
}

From source file:Main.java

private static void writeEscCData(Writer w, Reader input) throws IOException {
    int trigger = 0;
    w.write("<![CDATA[");
    int c;/*from  ww w .  j  av  a2s.c om*/
    while ((c = input.read()) != -1) {
        if (c == ']') {
            w.write(']');
            trigger++;
        } else if ((c == '>') && (trigger >= 2)) {
            w.write("]]><![CDATA[>");
            trigger = 0;
        } else {
            w.write(c);
            trigger = 0;
        }
    }
    w.write("]]>");
}

From source file:Main.java

public final static void writeDeep(Writer w, int deep) throws IOException {
    if (deep == 0)
        return;//ww w  . j a v a2  s  .  co m
    for (int i = 0; i < deep; i++) {
        w.write("\t");
    }
}

From source file:Main.java

static void writeUtf(String text, String file) {
    Writer out;
    try {/*  www.j av a2s  . c  om*/
        out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
        out.write(text);
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

/**
 * Save {@link String} to {@link File} witht the specified encoding
 *
 * @param string {@link String}//from  ww  w  . j  a v  a2 s. co m
 * @param path   Path of the file
 * @param string Encoding
 * @throws IOException
 */
public static void saveStringToFile(String string, File path, String encoding) throws IOException {
    if (path.exists()) {
        path.delete();
    }

    if ((path.getParentFile().mkdirs() || path.getParentFile().exists())
            && (path.exists() || path.createNewFile())) {
        Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path), encoding));
        writer.write(string);
        writer.close();
    }
}

From source file:Main.java

public static void writeToFile(String s, String filePath, boolean append) {
    File f = new File(filePath);
    Writer writer = null;
    try {/*  w w w .  ja  v  a  2  s.  com*/
        writer = new BufferedWriter(new FileWriter(f, append));
        writer.write(s);
        writer.flush();
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (writer != null) {
        try {
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:Main.java

private static void writeAsEncodedUnicode(EndElement element, Writer writer) throws XMLStreamException {
    try {/*from   w  w w  . j av  a 2  s . co m*/
        // Write end tags.
        writer.write("</");
        QName name = element.getName();
        String prefix = name.getPrefix();
        if (prefix != null && prefix.length() > 0) {
            writer.write(prefix);
            writer.write(':');
        }
        writer.write(name.getLocalPart());
        writer.write('>');
    } catch (IOException ioe) {
        throw new XMLStreamException(ioe);
    }
}

From source file:com.github.rnewson.couchdb.lucene.util.ServletUtils.java

public static void sendJson(final HttpServletRequest req, final HttpServletResponse resp, final JSONObject json)
        throws IOException {
    setResponseContentTypeAndEncoding(req, resp);
    final Writer writer = resp.getWriter();
    try {// w w  w.  j a v a  2s  .c om
        writer.write(json.toString() + "\r\n");
    } finally {
        writer.close();
    }
}

From source file:com.github.rnewson.couchdb.lucene.util.ServletUtils.java

public static void sendJsonSuccess(final HttpServletRequest req, final HttpServletResponse resp)
        throws IOException {
    setResponseContentTypeAndEncoding(req, resp);
    final Writer writer = resp.getWriter();
    try {//from  www  .j  av  a 2 s  . co m
        writer.write("{\"ok\": true}\r\n");
    } finally {
        writer.close();
    }
}