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:DocWriter.java

public static void writeNodeToStream(Node node, Writer out) throws IOException {
    serializeNode(node, out, "");
    out.write('\n');
    out.flush();/*from w  w w  .  j  av a  2  s . com*/
}

From source file:DocWriter.java

/**
 * Writes a document to a stream// www  .  ja v a2 s . c o m
 * 
 * @param doc
 *        the XML docuument to write
 * @param out
 *        the output stream to write to
 * @throws IOException
 */
public static void writeDocToStream(Document doc, Writer out) throws IOException {
    serializeNode(doc, out, "");
    out.write('\n');
    out.flush();
}

From source file:DocWriter.java

private static void writeNode(Node node, Writer out, String indent) throws IOException {
    out.write(nodeWithAttrs(node, indent));
    NodeList kids = node.getChildNodes();
    if (kids != null) {
        if ((kids.item(0) != null) && (kids.item(0).getNodeType() == Node.ELEMENT_NODE)) {
            out.write('\n');
        }/* w  w  w . j  av  a 2  s .co  m*/
        for (int i = 0; i < kids.getLength(); i++) {
            serializeNode(kids.item(i), out, indent + SINGLE_INDENT);
        }
        /* RLR - bug in indent logic - seems to work OK without
           if ( ( kids.item( 0 ) != null ) &&
         ( kids.item( kids.getLength()-1).getNodeType() == Node.ELEMENT_NODE ) )
           {
        out.write( indent );
           }
           */
    }
    if (node.hasChildNodes()) {
        /* indent bug - leave out
        if ( kids.item( 0 ) != null && kids.item( 0 ).getNodeType() == Node.ELEMENT_NODE )
        {
           out.write( indent );
        }
        */
        out.write("</" + node.getNodeName() + ">");
    }
}

From source file:com.richtodd.android.repository.JSONUtility.java

public static void saveJSONObject(File file, JSONObject jsonObject) throws RepositoryException {
    try {//from  w  ww . j a v a2 s  .  com
        String jsonString = jsonObject.toString();

        OutputStream out = new FileOutputStream(file);
        try {

            Writer writer = new OutputStreamWriter(out);
            try {
                writer.write(jsonString);
            } finally {
                writer.close();
            }
        } finally {
            out.close();
        }
    } catch (FileNotFoundException ex) {
        throw new RepositoryException(ex);
    } catch (IOException ex) {
        throw new RepositoryException(ex);
    }
}

From source file:Main.java

static public <E, T> void writeTo(Collection<E> c, String opener, String separator, String closer,
        Writer writer) throws IOException {

    Iterator<E> iterator = c.iterator();

    if (!iterator.hasNext()) {
        writer.write(opener);
        writer.write(closer);//www  .  j a va2s.  com
        return;
    }

    writer.write(opener);
    do {
        E element = iterator.next();
        writer.write(element.toString());

        if (!iterator.hasNext())
            break;
        writer.write(separator);
    } while (true);
    writer.write(closer);
}

From source file:boxConnection.SerBoxTelnet.java

public static void runReboot() throws IOException, InterruptedException {
    Logger.getLogger("SerBoxTelnet").info(ControlMain.getProperty("msg_reboot"));
    telnet.connect(ControlMain.getActiveBox().getDboxIp());
    OutputStream ostream = telnet.getOutputStream();
    Writer writer = new OutputStreamWriter(ostream);
    writer.write(ControlMain.getActiveBox().getLogin() + "\n");
    writer.flush();//from ww  w.j a  v a2 s .  c om
    Thread.sleep(1000);
    writer.write(ControlMain.getActiveBox().getPassword() + "\n");
    writer.flush();
    Thread.sleep(1000);
    writer.write("killall sectionsd" + "\n");
    writer.flush();
    Thread.sleep(1000);
    writer.write("killall camd2" + "\n");
    writer.flush();
    Thread.sleep(1000);
    writer.write("killall timerd" + "\n");
    writer.flush();
    Thread.sleep(1000);
    writer.write("killall timerd" + "\n");
    writer.flush();
    Thread.sleep(1000);
    writer.write("killall zapit" + "\n");
    writer.flush();
    Thread.sleep(1000);
    writer.write("killall controld" + "\n");
    writer.flush();
    Thread.sleep(1000);
    writer.write("killall nhttpd" + "\n");
    writer.flush();
    Thread.sleep(1000);
    writer.write("sleep 3" + "\n");
    writer.flush();
    Thread.sleep(1000);
    writer.write("busybox -reboot" + "\n");
    writer.flush();
    Thread.sleep(1000);
    closeTelnetSession();
}

From source file:Main.java

public final static void writeSimpleElementCDATALine(Writer w, int deep, String element, Reader content)
        throws IOException {
    if (deep >= 0)
        writeDeep(w, deep);//from   ww w  .j  a  v  a2 s  .  c  om
    w.write('<');
    w.write(element);
    w.write('>');
    writeEscCData(w, content);
    w.write('<');
    w.write('/');
    w.write(element);
    w.write('>');
    w.write('\n');
}

From source file:com.flexive.faces.javascript.FxJavascriptUtils.java

/**
 * Renders a function to be called when Yahoo UI has been loaded.
 *
 * @param out the output writer/*from w  ww  .  ja  va2s . c  om*/
 * @param fn  the javascript function, either a reference or an anonymous function
 * @throws IOException if the code could not be written
 */
public static void onYahooLoaded(Writer out, String fn) throws IOException {
    out.write("flexive.yui.onYahooLoaded(" + fn + ");\n");
}

From source file:Main.java

public static void writeEscapedChar(Writer writer, char c) throws IOException {
    if ((c >= ' ') && (c < 0x7f)) {
        if ((c == '\'') || (c == '\"') || (c == '\\')) {
            writer.write('\\');
        }//  w  ww  . jav a  2  s  .co m
        writer.write(c);
        return;
    } else if (c <= 0x7f) {
        switch (c) {
        case '\n':
            writer.write("\\n");
            return;
        case '\r':
            writer.write("\\r");
            return;
        case '\t':
            writer.write("\\t");
            return;
        }
    }

    writer.write("\\u");
    writer.write(Character.forDigit(c >> 12, 16));
    writer.write(Character.forDigit((c >> 8) & 0x0f, 16));
    writer.write(Character.forDigit((c >> 4) & 0x0f, 16));
    writer.write(Character.forDigit(c & 0x0f, 16));
}

From source file:Main.java

/**
 * Dump a <code>String</code> to a text file.
 *
 * @param file The output file/*from   w  w  w. j a va  2s .co m*/
 * @param string The string to be dumped
 * @param encoding The encoding for the output file or null for default platform encoding
 * @exception IOException IO Error
        
 */
public static void serializeString(File file, String string, String encoding) throws IOException {
    final Writer fw = (encoding == null) ? new FileWriter(file)
            : new OutputStreamWriter(new FileOutputStream(file), encoding);
    try {
        fw.write(string);
        fw.flush();
    } finally {
        fw.close();
    }
}