Example usage for java.io PrintStream write

List of usage examples for java.io PrintStream write

Introduction

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

Prototype

private void write(String s) 

Source Link

Usage

From source file:Main.java

/**
 * Performs the actual recursive dumping of a DOM tree to a given
 * <CODE>PrintStream</CODE>. Note that dump is intended to be a detailed
 * debugging aid rather than pretty to look at. 
 * //from w  w w. jav a  2  s  . c  o  m
 * @param    out            The <CODE>PrintStream</CODE> to write to.
 * @param    node         The <CODE>Node</CODE> under consideration.
 * @param    indent         The level of indentation.
 * @see      #dump(Node)
 * @see      #dump(PrintStream, Node)
 * @since   TFP 1.0
 */
private static void doDump(PrintStream out, final Node node, int indent) {
    if (node != null) {
        for (int index = 0; index < indent; ++index)
            out.write(' ');

        switch (node.getNodeType()) {
        case Node.DOCUMENT_NODE: {
            Document document = (Document) node;

            out.println("DOCUMENT:");

            doDump(out, document.getDoctype(), indent + 1);
            doDump(out, document.getDocumentElement(), indent + 1);
            break;
        }

        case Node.DOCUMENT_TYPE_NODE: {
            DocumentType type = (DocumentType) node;

            out.println("DOCTYPE: [" + "name=" + format(type.getName()) + "," + "publicId="
                    + format(type.getPublicId()) + "," + "systemId=" + format(type.getSystemId()) + "]");
            break;
        }

        case Node.ELEMENT_NODE: {
            Element element = (Element) node;

            out.println("ELEMENT: [" + "ns=" + format(element.getNamespaceURI()) + "," + "name="
                    + format(element.getLocalName()) + "]");

            NamedNodeMap attrs = element.getAttributes();

            for (int index = 0; index < attrs.getLength(); ++index)
                doDump(out, attrs.item(index), indent + 1);

            for (Node child = element.getFirstChild(); child != null;) {
                doDump(out, child, indent + 1);
                child = child.getNextSibling();
            }
            break;
        }
        case Node.ATTRIBUTE_NODE: {
            Attr attr = (Attr) node;

            out.println("ATTRIBUTE: [" + "ns=" + format(attr.getNamespaceURI()) + "," + "prefix="
                    + format(attr.getPrefix()) + "," + "name=" + format(attr.getLocalName()) + "," + "value="
                    + format(attr.getNodeValue()) + "]");
            break;
        }

        case Node.TEXT_NODE: {
            Text text = (Text) node;

            out.println("TEXT: [" + format(text.getNodeValue()) + "]");

            for (Node child = text.getFirstChild(); child != null;) {
                doDump(out, child, indent + 1);
                child = child.getNextSibling();
            }
            break;
        }

        case Node.CDATA_SECTION_NODE: {
            CDATASection data = (CDATASection) node;

            out.println("CDATA: [" + format(data.getNodeValue()) + "]");
            break;
        }

        case Node.COMMENT_NODE: {
            Comment comm = (Comment) node;

            out.println("COMMENT: [" + format(comm.getNodeValue()) + "]");
            break;
        }

        default:
            out.println("UNKNOWN: [type=" + node.getNodeType() + "]");
            break;
        }
    }
}

From source file:com.zimbra.cs.imap.ImapMessage.java

private static void ndisposition(PrintStream ps, String disposition) {
    if (disposition == null) {
        ps.print("NIL");
    } else {//from w w w  . ja v a 2s  . co  m
        ContentDisposition cdisp = new ContentDisposition(disposition);
        ps.write('(');
        astring(ps, cdisp.getDisposition());
        ps.write(' ');
        nparams(ps, cdisp);
        ps.write(')');
    }
}

From source file:com.zimbra.cs.imap.ImapMessage.java

private static void nlist(PrintStream ps, String[] list) {
    if (list == null || list.length == 0) {
        ps.print("NIL");
    } else if (list.length == 1) {
        astring(ps, list[0]);//from   w  w w  . j a  v a  2  s .  co m
    } else {
        ps.write('(');
        for (int i = 0; i < list.length; i++) {
            if (i != 0) {
                ps.write(' ');
            }
            astring(ps, list[i]);
        }
        ps.write(')');
    }
}

From source file:com.zimbra.cs.imap.ImapMessage.java

private static void nparams(PrintStream ps, MimeCompoundHeader header) {
    boolean first = true;
    for (Iterator<Map.Entry<String, String>> it = header.parameterIterator(); it.hasNext(); first = false) {
        Map.Entry<String, String> param = it.next();
        ps.print(first ? '(' : ' ');
        aSTRING(ps, param.getKey());/*from   www.  j a v a2 s . c  o  m*/
        ps.write(' ');
        nstring2047(ps, param.getValue());
    }
    ps.print(first ? "NIL" : ")");
}

From source file:com.zimbra.cs.imap.ImapMessage.java

private static void address(PrintStream ps, InternetAddress addr) {
    String address = addr.getAddress().trim(), route = null;

    // handle obsolete route-addr
    int colon;/*from w  w w  .  j  av a 2  s .co  m*/
    if (address.startsWith("@") && (colon = address.indexOf(':')) != -1) {
        route = address.substring(0, colon);
        address = address.substring(colon + 1);
    }

    String[] parts = address.split("@", 2);
    ps.write('(');
    nstring2047(ps, addr.getPersonal());
    ps.write(' ');
    nstring(ps, route);
    ps.write(' ');
    nstring(ps, parts[0]);
    ps.write(' ');
    nstring(ps, parts.length > 1 ? parts[1] : null);
    ps.write(')');
}

From source file:org.apache.whirr.cli.command.VersionCommand.java

@Override
public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception {
    InputStream input = getClass().getResourceAsStream("/version-banner.txt");
    if (input == null) {
        err.printf("Cannot determine version number\n");
        return -1;
    }/*from  w w  w  . j  a v  a 2s.c  o  m*/
    out.write(IOUtils.toByteArray(input));
    out.println("jclouds " + JcloudsVersion.get().toString());
    return 0;
}

From source file:com.prowidesoftware.swift.model.MxNode.java

private void _print(int level, final MxNode node, final PrintStream w) throws IOException {
    for (int i = 0; i < level; i++) {
        w.write("   ".getBytes());
    }/*from  w  ww.  ja va2s.  c om*/
    w.write((node.localName + "\n").getBytes());
    int nextLevel = level + 1;
    for (final MxNode child : node.children) {
        _print(nextLevel, child, w);
    }
}

From source file:com.xebialabs.overcast.command.CommandProcessor.java

private Thread showProcessOutput(final InputStream from, final PrintStream to) {
    Thread t = new Thread(new Runnable() {
        public void run() {
            try {
                for (;;) {
                    int c = from.read();
                    if (c == -1)
                        break;
                    to.write((char) c);
                }/*  w  ww. ja  v  a  2 s  .com*/
            } catch (IOException ignore) {
            }
        }
    });
    t.start();
    return t;
}

From source file:com.zimbra.cs.imap.ImapMessage.java

static void serializeEnvelope(PrintStream ps, MimeMessage mm) throws MessagingException {
    // 7.4.2: "The fields of the envelope structure are in the following order: date, subject,
    //         from, sender, reply-to, to, cc, bcc, in-reply-to, and message-id.  The date,
    //         subject, in-reply-to, and message-id fields are strings.  The from, sender,
    //         reply-to, to, cc, and bcc fields are parenthesized lists of address structures."
    InternetAddress[] from = Mime.parseAddressHeader(mm, "From", false);
    InternetAddress[] sender = Mime.parseAddressHeader(mm, "Sender", false),
            replyTo = Mime.parseAddressHeader(mm, "Reply-To", false);
    ps.write('(');
    nstring(ps, mm.getHeader("Date", ","));
    ps.write(' ');
    nstring2047(ps, Mime.getSubject(mm));
    ps.write(' ');
    naddresses(ps, from);//from   w  w  w .  j a  va  2 s  .co  m
    ps.write(' ');
    naddresses(ps, sender.length == 0 ? from : sender);
    ps.write(' ');
    naddresses(ps, replyTo.length == 0 ? from : replyTo);
    ps.write(' ');
    naddresses(ps, Mime.parseAddressHeader(mm, "To", false));
    ps.write(' ');
    naddresses(ps, Mime.parseAddressHeader(mm, "CC", false));
    ps.write(' ');
    naddresses(ps, Mime.parseAddressHeader(mm, "BCC", false));
    ps.write(' ');
    nstring(ps, mm.getHeader("In-Reply-To", " "));
    ps.write(' ');
    nstring(ps, mm.getMessageID());
    ps.write(')');
}

From source file:com.zimbra.cs.imap.ImapMessage.java

private static void astring(PrintStream ps, String value, boolean upcase) {
    boolean literal = false;
    StringBuilder nonulls = null;
    int i = 0, lastNull = -1;
    for (int length = value.length(); i < length; i++) {
        char c = value.charAt(i);
        if (c == '\0') {
            if (nonulls == null) {
                nonulls = new StringBuilder();
            }/*from   w  ww  .  jav a  2s.  c  om*/
            nonulls.append(value.substring(lastNull + 1, i));
            lastNull = i;
        } else if (c == '"' || c == '\\' || c >= 0x7f || c < 0x20) {
            literal = true;
        }
    }

    String content = nonulls == null ? value : nonulls.append(value.substring(lastNull + 1, i)).toString();
    if (upcase) {
        content = content.toUpperCase();
    }

    if (!literal) {
        ps.write('"');
        ps.print(content);
        ps.write('"');
    } else {
        try {
            byte[] bytes = content.getBytes(MimeConstants.P_CHARSET_UTF8);
            ps.write('{');
            ps.print(bytes.length);
            ps.write('}');
            ps.write(ImapHandler.LINE_SEPARATOR_BYTES, 0, 2);
            ps.write(bytes, 0, bytes.length);
        } catch (UnsupportedEncodingException uee) {
            ps.write(NIL, 0, 3);
        }
    }
}