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:co.cask.cdap.filetailer.tailer.TailerLogUtils.java

public static void writeLineToFile(String filePath, String line) throws IOException {
    Writer writer = new FileWriter(filePath, true);
    writer.write(line + "\n");
    writer.flush();/*from   www .  ja  va2 s .  co m*/
    writer.close();
}

From source file:com.bstek.dorado.view.output.OutputUtils.java

/**
 * HTMLJavaScript/* w  ww  .j a v  a2  s  .c o  m*/
 * 
 * @throws IOException
 */
public static void outputScriptBeginTag(Writer writer) throws IOException {
    writer.write("<script language=\"javascript\" type=\"text/javascript\">\n");
}

From source file:com.bstek.dorado.view.output.OutputUtils.java

/**
 * HTMLJavaScript?// w  w  w  .  j  a  va2 s  . c  o m
 * 
 * @throws IOException
 */
public static void outputScriptEndTag(Writer writer) throws IOException {
    writer.write("</script>\n");
}

From source file:Main.java

/**
 * Write the entire contents of the supplied string to the given writer. This method always flushes and closes the writer when
 * finished.//  w  ww.  j  a  va 2  s. c  o m
 * 
 * @param content the content to write to the writer; may be null
 * @param writer the writer to which the content is to be written
 * @throws IOException
 * @throws IllegalArgumentException if the writer is null
 */
public static void write(String content, Writer writer) throws IOException {
    boolean error = false;
    try {
        if (content != null) {
            writer.write(content);
        }
    } catch (IOException e) {
        error = true; // this error should be thrown, even if there is an error flushing/closing writer
        throw e;
    } catch (RuntimeException e) {
        error = true; // this error should be thrown, even if there is an error flushing/closing writer
        throw e;
    } finally {
        try {
            writer.flush();
        } catch (IOException e) {
            if (!error)
                throw e;
        } finally {
            try {
                writer.close();
            } catch (IOException e) {
                if (!error)
                    throw e;
            }
        }
    }
}

From source file:Main.java

/**
 * Writes <CODE>string</CODE> into writer, escaping &, ', ", <, and >
 * with the XML excape strings./*ww  w . j ava  2s  . c om*/
 */
public static void writeEscapedString(Writer writer, String string) throws IOException {
    for (int i = 0; i < string.length(); i++) {
        char c = string.charAt(i);
        if (c == '<')
            writer.write("&lt;");
        else if (c == '>')
            writer.write("&gt;");
        else if (c == '&')
            writer.write("&amp;");
        else if (c == '\'')
            writer.write("&apos;");
        else if (c == '"')
            writer.write("&quot;");
        else
            writer.write(c);
    }
}

From source file:Main.java

private static void writeAsEncodedUnicode(StartElement element, Writer writer, boolean isEmpty)
        throws XMLStreamException {
    try {/*from   ww  w  . j a  v  a2 s  .  co  m*/
        // Write start tag.
        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());

        // Write namespace declarations.
        Iterator nsIter = element.getNamespaces();
        while (nsIter.hasNext()) {
            Namespace ns = (Namespace) nsIter.next();
            writer.write(' ');
            ns.writeAsEncodedUnicode(writer);
        }

        // Write attributes
        Iterator attrIter = element.getAttributes();
        while (attrIter.hasNext()) {
            Attribute attr = (Attribute) attrIter.next();
            writer.write(' ');
            attr.writeAsEncodedUnicode(writer);
        }

        if (isEmpty)
            writer.write('/');
        writer.write('>');
    } catch (IOException ioe) {
        throw new XMLStreamException(ioe);
    }
}

From source file:com.bstek.dorado.view.output.OutputUtils.java

/**
 * ??HTML//from   w  ww  . j  a  v  a  2s . co  m
 * 
 * @throws IOException
 */
public static void outputString(Writer writer, String s) throws IOException {
    writer.write(StringEscapeUtils.escapeHtml(s));
}

From source file:com.ikon.util.FileLogger.java

/**
 * Write to log file//from  w  ww. jav a  2  s.c o  m
 * 
 * @throws IOException If there is an exception when writing.
 */
private static void logWrite(String baseName, String level, String message, Object... params)
        throws IOException {
    Writer sLogger = new FileWriter(getLogFile(baseName), true);
    sLogger.write(getLogEntry(level, message, params));
    sLogger.flush();
    sLogger.close();
}

From source file:com.hunantv.fw.utils.StreamUtils.java

/**
 * Copy the contents of the given String to the given output OutputStream.
 * Leaves the stream open when done.//  ww w.j ava 2  s  . c  o  m
 * @param in the String to copy from
 * @param charset the Charset
 * @param out the OutputStream to copy to
 * @throws IOException in case of I/O errors
 */
public static void copy(String in, Charset charset, OutputStream out) throws IOException {
    Writer writer = new OutputStreamWriter(out, charset);
    writer.write(in);
    writer.flush();
}

From source file:Main.java

private static void writeEsc(Writer w, String s, boolean isAttVal) throws IOException {
    for (int i = 0; i < s.length(); i++) {
        switch (s.charAt(i)) {
        case '&':
            w.write("&amp;");
            break;
        case '<':
            w.write("&lt;");
            break;
        case '>':
            w.write("&gt;");
            break;
        case '\"':
            if (isAttVal) {
                w.write("&quot;");
            } else {
                w.write('\"');
            }/*  www.  j  a v a  2 s.  c  o m*/
            break;
        default:
            w.write(s.charAt(i));
        }
    }
}