Example usage for java.io PrintStream print

List of usage examples for java.io PrintStream print

Introduction

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

Prototype

public void print(Object obj) 

Source Link

Document

Prints an object.

Usage

From source file:org.apache.cassandra.tools.SSTableExport.java

/**
 * Get portion of the columns and serialize in loop while not more columns left in the row
 * @param row SSTableIdentityIterator row representation with Column Family
 * @param key Decorated Key for the required row
 * @param out output stream//from   w  ww  . j av  a  2 s  . c  om
 */
private static void serializeRow(SSTableIdentityIterator row, DecoratedKey key, PrintStream out) {
    ColumnFamily columnFamily = row.getColumnFamily();
    boolean isSuperCF = columnFamily.isSuper();
    CFMetaData cfMetaData = columnFamily.metadata();
    AbstractType comparator = columnFamily.getComparator();

    out.print(asKey(bytesToHex(key.key)));
    out.print(isSuperCF ? "{" : "[");

    if (isSuperCF) {
        while (row.hasNext()) {
            IColumn column = row.next();

            out.print(asKey(comparator.getString(column.name())));
            out.print("{");
            out.print(asKey("deletedAt"));
            out.print(column.getMarkedForDeleteAt());
            out.print(", ");
            out.print(asKey("subColumns"));
            out.print("[");
            serializeColumns(column.getSubColumns().iterator(), out, columnFamily.getSubComparator(),
                    cfMetaData);
            out.print("]");
            out.print("}");

            if (row.hasNext())
                out.print(", ");
        }
    } else {
        serializeColumns(row, out, comparator, cfMetaData);
    }

    out.print(isSuperCF ? "}" : "]");
}

From source file:org.apache.myfaces.util.DebugUtils.java

private static void printComponent(UIComponent comp, PrintStream stream, int indent,
        boolean withChildrenAndFacets, String facetName) {
    printIndent(stream, indent);/*ww w .  j a v a  2s .  c o m*/
    stream.print('<');

    String compType = comp.getClass().getName();
    if (compType.startsWith(JSF_COMPONENT_PACKAGE)) {
        compType = compType.substring(JSF_COMPONENT_PACKAGE.length());
    } else if (compType.startsWith(MYFACES_COMPONENT_PACKAGE)) {
        compType = compType.substring(MYFACES_COMPONENT_PACKAGE.length());
    }
    stream.print(compType);

    printAttribute(stream, "id", comp.getId());

    if (facetName != null) {
        printAttribute(stream, "facetName", facetName);
    }

    for (Iterator it = comp.getAttributes().entrySet().iterator(); it.hasNext();) {
        Map.Entry entry = (Map.Entry) it.next();
        if (!"id".equals(entry.getKey())) {
            printAttribute(stream, (String) entry.getKey(), entry.getValue());
        }
    }

    //HACK: comp.getAttributes() only returns attributes, that are NOT backed
    //by a corresponding component property. So, we must explicitly get the
    //available properties by Introspection:
    BeanInfo beanInfo;
    try {
        beanInfo = Introspector.getBeanInfo(comp.getClass());
    } catch (IntrospectionException e) {
        throw new RuntimeException(e);
    }

    PropertyDescriptor propDescriptors[] = beanInfo.getPropertyDescriptors();
    for (int i = 0; i < propDescriptors.length; i++) {
        if (propDescriptors[i].getReadMethod() != null) {
            String name = propDescriptors[i].getName();
            if (!"id".equals(name)) {
                ValueBinding vb = comp.getValueBinding(name);
                if (vb != null) {
                    printAttribute(stream, name, vb.getExpressionString());
                } else {
                    if (name.equals("value") && comp instanceof ValueHolder) {
                        //-> localValue
                    } else if (!IGNORE_ATTRIBUTES.contains(name)) {
                        try {
                            Object value = comp.getAttributes().get(name);
                            printAttribute(stream, name, value);
                        } catch (Exception e) {
                            log.error(e);
                            printAttribute(stream, name, null);
                        }
                    }
                }
            }
        }
    }

    boolean mustClose = true;
    boolean nestedObjects = false;

    if (comp instanceof UICommand) {
        FacesListener[] listeners = ((UICommand) comp).getActionListeners();
        if (listeners != null && listeners.length > 0) {
            nestedObjects = true;
            stream.println('>');
            mustClose = false;
            for (int i = 0; i < listeners.length; i++) {
                FacesListener listener = listeners[i];
                printIndent(stream, indent + 1);
                stream.print('<');
                stream.print(listener.getClass().getName());
                stream.println("/>");
            }
        }
    }

    if (comp instanceof UIInput) {
        FacesListener[] listeners = ((UIInput) comp).getValueChangeListeners();
        if (listeners != null && listeners.length > 0) {
            nestedObjects = true;
            stream.println('>');
            mustClose = false;
            for (int i = 0; i < listeners.length; i++) {
                FacesListener listener = listeners[i];
                printIndent(stream, indent + 1);
                stream.print('<');
                stream.print(listener.getClass().getName());
                stream.println("/>");
            }
        }

        Validator[] validators = ((UIInput) comp).getValidators();
        if (validators != null && validators.length > 0) {
            nestedObjects = true;
            stream.println('>');
            mustClose = false;
            for (int i = 0; i < validators.length; i++) {
                Validator validator = validators[i];
                printIndent(stream, indent + 1);
                stream.print('<');
                stream.print(validator.getClass().getName());
                stream.println("/>");
            }
        }
    }

    if (withChildrenAndFacets) {
        int childCount = comp.getChildCount();
        Map facetsMap = comp.getFacets();
        if (childCount > 0 || !facetsMap.isEmpty()) {
            nestedObjects = true;
            if (mustClose) {
                stream.println('>');
                mustClose = false;
            }

            if (childCount > 0) {
                for (Iterator it = comp.getChildren().iterator(); it.hasNext();) {
                    UIComponent child = (UIComponent) it.next();
                    printComponent(child, stream, indent + 1, true, null);
                }
            }

            for (Iterator it = facetsMap.entrySet().iterator(); it.hasNext();) {
                Map.Entry entry = (Map.Entry) it.next();
                printComponent((UIComponent) entry.getValue(), stream, indent + 1, true,
                        (String) entry.getKey());
            }
        }
    }

    if (nestedObjects) {
        if (mustClose) {
            stream.println("/>");
        } else {
            printIndent(stream, indent);
            stream.print("</");
            stream.print(compType);
            stream.println('>');
        }
    } else {
        stream.println("/>");
    }
}

From source file:org.apache.orc.tools.json.JsonSchemaFinder.java

static void printAsTable(PrintStream out, StructType type) {
    out.println("create table tbl (");
    boolean first = true;
    for (Map.Entry<String, HiveType> field : type.fields.entrySet()) {
        if (!first) {
            out.println(",");
        } else {/*w  w w.  j a  v  a2 s  . c om*/
            first = false;
        }
        for (int i = 0; i < INDENT; ++i) {
            out.print(' ');
        }
        out.print(field.getKey());
        out.print(" ");
        printType(out, field.getValue(), 2 * INDENT);
    }
    out.println();
    out.println(")");
}

From source file:org.apache.bookkeeper.tools.framework.CommandUtils.java

private static void printCommand(PrintStream printer, String name, Command command,
        final int longestCommandName) {
    if (command.hidden()) {
        return;//from  w ww .  j a va2 s.  co  m
    }

    final int indent = DEFAULT_INDENT;
    final int startOfDescription = (((indent + longestCommandName) / DEFAULT_INDENT) + 2) * DEFAULT_INDENT;

    int current = 0;
    printIndent(printer, indent);
    printer.print(name);
    current += (indent + name.length());
    printIndent(printer, startOfDescription - current);
    printDescription(printer, 0, startOfDescription, command.description());
}

From source file:esiptestbed.mudrod.ontology.process.LocalOntology.java

public static void renderClassDescription(PrintStream out, OntClass c, int depth) {
    indent(out, depth);/*w w w  .j  a v a  2 s.  co  m*/

    if (c.isRestriction()) {
        renderRestriction(out, (Restriction) c.as(Restriction.class));
    } else {
        if (!c.isAnon()) {
            out.print("Class ");
            renderURI(out, c.getModel(), c.getURI());

            out.print(c.getLocalName());

            out.print(" [");
            for (Iterator i = c.listLabels(null); i.hasNext();) {
                out.print(((Literal) i.next()).getString() + ", ");
            }
            out.print("] ");
        } else {
            renderAnonymous(out, c, "class");
        }
    }
}

From source file:edu.utah.further.core.api.xml.XmlUtil.java

/**
 * @param xmlReader// www  . j  av  a 2  s . co m
 */
private static void printName(final PrintStream os, final XMLStreamReader xmlReader) {
    if (xmlReader.hasName()) {
        os.print(getName(xmlReader));
    }
}

From source file:edu.utah.further.core.api.xml.XmlUtil.java

/**
 * @param os/* ww  w .j  a  v a 2  s.  c  o m*/
 * @param xmlReader
 * @param printAttributes
 */
public static void printElement(final PrintStream os, final XMLStreamReader xmlReader,
        final boolean printAttributes) {
    os.print("<");
    printName(os, xmlReader);
    printNamespaces(os, xmlReader);
    if (printAttributes) {
        printAttributes(os, xmlReader);
    }
    os.print(">");
}

From source file:org.apache.myfaces.util.DebugUtils.java

private static void printAttribute(PrintStream stream, String name, Object value) {
    if (IGNORE_ATTRIBUTES.contains(name))
        return;//from   w  w  w.  j a v  a  2s.  com
    if (name.startsWith("javax.faces.webapp.UIComponentTag.")) {
        name = name.substring("javax.faces.webapp.UIComponentTag.".length());
    }
    stream.print(' ');
    stream.print(name.toString());
    stream.print("=\"");
    if (value != null) {
        if (value instanceof UIComponent) {
            stream.print("[id:");
            stream.print(((UIComponent) value).getId());
            stream.print(']');
        } else if (value instanceof MethodBinding) {
            stream.print(((MethodBinding) value).getExpressionString());
        } else {
            stream.print(value.toString());
        }
    } else {
        stream.print("NULL");
    }
    stream.print('"');
}

From source file:com.bjond.utilities.MiscUtils.java

public static <T> void printSetOfSet(PrintStream ps, Set<Set<T>> sos) {

    for (Set<T> s : sos) {
        ps.print("#" + "{"); // <-- Stupid Eclipse, stupid EL...
        boolean first = true;
        for (T t : s) {
            if (first) {
                first = false;//  w  ww . j a  va  2 s.  com
            } else {
                ps.print(",");
            }

            ps.print(t);
        }
        ps.println("}");
    }
}

From source file:org.apache.cassandra.tools.SSTableExport.java

/**
 * Serialize a given column to the JSON format
 * @param column column presentation//from  www . j  av a  2  s .  c o  m
 * @param out output stream
 * @param comparator columns comparator
 * @param cfMetaData Column Family metadata (to get validator)
 */
private static void serializeColumn(IColumn column, PrintStream out, AbstractType comparator,
        CFMetaData cfMetaData) {
    ByteBuffer name = ByteBufferUtil.clone(column.name());
    ByteBuffer value = ByteBufferUtil.clone(column.value());
    AbstractType validator = cfMetaData.getValueValidator(name);

    out.print("[");
    out.print(quote(comparator.getString(name)));
    out.print(", ");
    out.print(quote(validator.getString(value)));
    out.print(", ");
    out.print(column.timestamp());

    if (column instanceof DeletedColumn) {
        out.print(", ");
        out.print("\"d\"");
    } else if (column instanceof ExpiringColumn) {
        out.print(", ");
        out.print("\"e\"");
        out.print(", ");
        out.print(((ExpiringColumn) column).getTimeToLive());
        out.print(", ");
        out.print(column.getLocalDeletionTime());
    } else if (column instanceof CounterColumn) {
        out.print(", ");
        out.print("\"c\"");
        out.print(", ");
        out.print(((CounterColumn) column).timestampOfLastDelete());
    }

    out.print("]");
}