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:de.juwimm.cms.model.EditionHbmDaoImpl.java

@Override
protected void handleUnitToXml(Integer unitId, PrintStream out, EditionHbm edition) throws Exception {
    out.println("\t<units>");
    try {// w  ww. ja  v  a 2s  .  c  o m
        UnitHbm unit = getUnitHbmDao().load(unitId);
        out.print(getUnitHbmDao().toXmlRecursive(2, unit));
    } catch (Exception exe) {
        log.error("Error occured", exe);
    }
    out.println("\t</units>");

}

From source file:de.hasait.clap.CLAP.java

public void printUsage(final PrintStream pPrintStream) {
    final Map<CLAPUsageCategoryImpl, StringBuilder> categories = new TreeMap<CLAPUsageCategoryImpl, StringBuilder>();
    _root.printUsage(categories, null, null);
    for (final Entry<CLAPUsageCategoryImpl, StringBuilder> entry : categories.entrySet()) {
        pPrintStream.print(nls(entry.getKey().getTitleNLSKey()));
        pPrintStream.print(": "); //$NON-NLS-1$
        pPrintStream.print(entry.getValue().toString());
        pPrintStream.println();/* w  w w  .j  av  a2s  .  co  m*/
    }
}

From source file:examples.ClassPropertyUsageAnalyzer.java

/**
 * Prints a list of classes to the given output. The list is encoded as a
 * single CSV value, using "@" as a separator. Miga can decode this.
 * Standard CSV processors do not support lists of entries as values,
 * however.//from ww  w  .jav  a2s.c o  m
 *
 * @param out
 *            the output to write to
 * @param classes
 *            the list of class items
 */
private void printClassList(PrintStream out, Iterable<EntityIdValue> classes) {
    out.print(",\"");
    boolean first = true;
    for (EntityIdValue superClass : classes) {
        if (first) {
            first = false;
        } else {
            out.print("@");
        }
        // makeshift escaping for Miga:
        out.print(getClassLabel(superClass).replace("@", ""));
    }
    out.print("\"");
}

From source file:hudson.model.ExternalRun.java

/**
 * Instead of performing a build, accept the log and the return code from a
 * remote machine./*  w  w w  .j  ava  2  s .c o  m*/
 *
 * <p> The format of the XML is:
 *
 * <pre><xmp>
 * <run>
 *  <log>...console output...</log>
 *  <result>exit code</result>
 * </run>
 * </xmp></pre>
 */
@SuppressWarnings({ "Since15" })
public void acceptRemoteSubmission(final Reader in) throws IOException {
    final long[] duration = new long[1];
    run(new Runner() {
        private String elementText(XMLStreamReader r) throws XMLStreamException {
            StringBuilder buf = new StringBuilder();
            while (true) {
                int type = r.next();
                if (type == CHARACTERS || type == CDATA) {
                    buf.append(r.getTextCharacters(), r.getTextStart(), r.getTextLength());
                } else {
                    return buf.toString();
                }
            }
        }

        public Result run(BuildListener listener) throws Exception {
            PrintStream logger = null;
            try {
                logger = new PrintStream(new DecodingStream(listener.getLogger()));

                XMLInputFactory xif = XMLInputFactory.newInstance();
                XMLStreamReader p = xif.createXMLStreamReader(in);

                p.nextTag(); // get to the <run>
                p.nextTag(); // get to the <log>

                charset = p.getAttributeValue(null, "content-encoding");
                while (p.next() != END_ELEMENT) {
                    int type = p.getEventType();
                    if (type == CHARACTERS || type == CDATA) {
                        logger.print(p.getText());
                    }
                }
                p.nextTag(); // get to <result>

                Result r = Integer.parseInt(elementText(p)) == 0 ? Result.SUCCESS : Result.FAILURE;

                p.nextTag(); // get to <duration> (optional)
                if (p.getEventType() == START_ELEMENT && p.getLocalName().equals("duration")) {
                    duration[0] = Long.parseLong(elementText(p));
                }

                return r;
            } finally {
                IOUtils.closeQuietly(logger);
            }
        }

        public void post(BuildListener listener) {
            // do nothing
        }

        public void cleanUp(BuildListener listener) {
            // do nothing
        }
    });

    if (duration[0] != 0) {
        super.duration = duration[0];
        // save the updated duration
        save();
    }
}

From source file:com.intbit.PhantomImageConverter.java

private File tempHTML(String bodyString, JSONArray json_font_list) throws IOException {
    File newHtmlFile = null;//from   ww w . j av a2  s. c  o m
    StringBuilder html_content = new StringBuilder();

    try {

        OutputStream htmlfile = new FileOutputStream(new File(templateHTMLFilePath));

        PrintStream printhtml = new PrintStream(htmlfile);
        html_content.append("<HTML>" + "\n");
        html_content.append("<head>" + "\n");
        html_content.append("<meta charset=UTF-8>" + "\n");

        html_content.append(Utility.injectFontsInHTML(json_font_list));
        html_content.append("<link  href=\"" + path + File.separator
                + "css/imagefilter.css\" rel=\"stylesheet\" type=\"text/css\"></link>" + "\n");
        html_content.append("</head>" + "\n");
        html_content.append("<body>" + "\n");
        html_content.append(bodyString + "\n");
        html_content.append("</body>" + "\n");
        html_content.append("</HTML>");

        printhtml.print(html_content.toString());

        String fileName = dateFormat.format(new Date());
        //Using the date as the unique file name
        newHtmlFile = new File(tempPath + fileName + ".html");
        FileUtils.writeStringToFile(newHtmlFile, html_content.toString(), kEncoding);

    } catch (Exception e) {
        logger.log(Level.SEVERE, "", e);
    }
    return newHtmlFile;
}

From source file:com.sangupta.jerry.util.FileUtils.java

/**
 * Dump a given file into HEX starting at given offset and reading given number of rows where
 * a row consists of 16-bytes./* w  ww  . ja v  a 2 s .c o m*/
 * 
 * @param out
 * @param file
 * @param offset
 * @param maxRows
 * @throws IOException
 */
public static void hexDump(PrintStream out, File file, long offset, int maxRows) throws IOException {
    InputStream is = null;
    BufferedInputStream bis = null;

    try {
        is = new FileInputStream(file);
        bis = new BufferedInputStream(is);
        bis.skip(offset);

        int row = 0;
        if (maxRows == 0) {
            maxRows = Integer.MAX_VALUE;
        }

        StringBuilder builder1 = new StringBuilder(100);
        StringBuilder builder2 = new StringBuilder(100);

        while (bis.available() > 0) {
            out.printf("%04X  ", row * 16);
            for (int j = 0; j < 16; j++) {
                if (bis.available() > 0) {
                    int value = (int) bis.read();
                    builder1.append(String.format("%02X ", value));

                    if (!Character.isISOControl(value)) {
                        builder2.append((char) value);
                    } else {
                        builder2.append(".");
                    }
                } else {
                    for (; j < 16; j++) {
                        builder1.append("   ");
                    }
                }
            }
            out.print(builder1);
            out.println(builder2);
            row++;

            if (row > maxRows) {
                break;
            }

            builder1.setLength(0);
            builder2.setLength(0);
        }
    } finally {
        IOUtils.closeQuietly(bis);
        IOUtils.closeQuietly(is);
    }
}

From source file:org.apache.geode.test.dunit.standalone.ProcessManager.java

private void linkStreams(final String version, final int vmNum, final ProcessHolder holder,
        final InputStream in, final PrintStream out) {
    Thread ioTransport = new Thread() {
        public void run() {
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            String vmName = "[" + VM.getVMName(version, vmNum) + "] ";
            try {
                String line = reader.readLine();
                while (line != null) {
                    if (line.length() == 0) {
                        out.println();/*from  w ww. jav  a 2s .c  o  m*/
                    } else {
                        out.print(vmName);
                        out.println(line);
                    }
                    line = reader.readLine();
                }
            } catch (Exception e) {
                if (!holder.isKilled()) {
                    out.println("Error transporting IO from child process");
                    e.printStackTrace(out);
                }
            }
        }
    };

    ioTransport.setDaemon(true);
    ioTransport.start();
}

From source file:com.google.cloud.dataflow.sdk.runners.worker.TextReaderTest.java

@Test
public void testCloneIteratorWithEndPositionAndFinalBytesInBuffer() throws Exception {
    String line = "a\n";
    boolean stripNewlines = false;
    File tmpFile = tmpFolder.newFile();
    List<String> expected = new ArrayList<>();
    PrintStream writer = new PrintStream(new FileOutputStream(tmpFile));
    // Write 5x the size of the buffer and 10 extra trailing bytes
    for (long bytesWritten = 0; bytesWritten < TextReader.BUF_SIZE * 3 + 10;) {
        writer.print(line);
        expected.add(line);//from ww w .  java  2  s  .  co  m
        bytesWritten += line.length();
    }
    writer.close();
    Long fileSize = tmpFile.length();

    TextReader<String> textReader = new TextReader<>(tmpFile.getPath(), stripNewlines, null, fileSize,
            StringUtf8Coder.of(), TextIO.CompressionType.UNCOMPRESSED);

    List<String> actual = new ArrayList<>();
    Reader.ReaderIterator<String> iterator = textReader.iterator();
    while (iterator.hasNext()) {
        actual.add(iterator.next());
        iterator = iterator.copy();
    }
    assertEquals(expected, actual);
}

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

private static void naddresses(PrintStream ps, InternetAddress[] addrs) {
    int count = 0;
    if (addrs != null && addrs.length > 0) {
        for (InternetAddress addr : addrs) {
            if (addr.isGroup()) {
                // 7.4.2: "[RFC-2822] group syntax is indicated by a special form of address
                //         structure in which the host name field is NIL.  If the mailbox name
                //         field is also NIL, this is an end of group marker (semi-colon in RFC
                //         822 syntax).  If the mailbox name field is non-NIL, this is a start of
                //         group marker, and the mailbox name field holds the group name phrase."
                try {
                    String serialized = addr.getAddress();
                    int colon = serialized.indexOf(':');
                    String name = colon == -1 ? serialized : serialized.substring(0, colon);
                    InternetAddress[] members = addr.getGroup(false);

                    if (count++ == 0) {
                        ps.write('(');
                    }/*  w  w w. j  a  v  a 2  s .  com*/
                    ps.print("(NIL NIL ");
                    nstring(ps, name);
                    ps.print(" NIL)");
                    if (members != null) {
                        for (InternetAddress member : members) {
                            address(ps, member);
                        }
                    }
                    ps.print("(NIL NIL NIL NIL)");
                } catch (ParseException e) {
                }
            } else if (addr.getAddress() == null) {
                continue;
            } else {
                // 7.4.2: "The fields of an address structure are in the following order: personal
                //         name, [SMTP] at-domain-list (source route), mailbox name, and host name."
                if (count++ == 0) {
                    ps.write('(');
                }
                address(ps, addr);
            }
        }
    }

    if (count == 0) {
        ps.write(NIL, 0, 3);
    } else {
        ps.write(')');
    }
}

From source file:gov.nasa.ensemble.dictionary.nddl.NumericResourceTranslator.java

@Override
public void writeCompats(PrintStream oStrm) {

    // PHM 10/22/2012 Define global constants needed for
    // numeric compats More useful to see here than buried in
    // writeObjects. TODO: prune if not in resource effect.
    for (Constant constant : allConstants) {
        writeConstant(oStrm, constant);// w w  w. ja  va2  s. com
    }
    oStrm.printf("\n");

    // PHM 03/12/2013 Need an incon compat to set the
    // numerical resources. Omit the passive/active guards
    // for now, so only one.
    oStrm.print(
            "InitialConds::incon {\n" + "  if (scheduled == true) {\n" + "        eq(inconStart, start);\n\n");

    for (ENumericResourceDef res : resourceDefs_) {
        String startVar = NDDLUtil.escape("init_" + res.getName());
        String resName = NDDLUtil.escape(res.getName());
        oStrm.printf("\n" + "\t starts(%s.produce %s);\n" + "\t eq(%s.quantity, _%s);\n", resName, startVar,
                startVar, resName);
    }
    oStrm.print("    }\n  }\n\n");

    // PHM 10/22/2012 The compats are currently not legal
    // nddl, so put comment around them. They could be
    // manually rewritten.

    // PHM 04/12/2013 The compats are now legal but formulas
    // are limited to params and negations of params.
    // Intermediate variables should be used to evaluate
    // javascript quantities in SPIFe.

    // oStrm.printf("/* COMPATS FOR NUMERIC RESOURCES\n\n");

    for (ActResourceEffect are : actResourceEffects_) {
        for (ResourceEffect effect : are.effects) {
            if ((effect.startEffect != null) && (effect.startEffect.length() > 0)) {
                ST compat = createCompat(are.activity, effect, effect.startEffect, "start");
                oStrm.append(compat.render());
            }
            if ((effect.endEffect != null) && (effect.endEffect.length() > 0)) {
                ST compat = createCompat(are.activity, effect, effect.endEffect, "end");
                oStrm.append(compat.render());
            }
        }
    }

    // oStrm.printf("\n*/");
}