Example usage for java.io PrintWriter println

List of usage examples for java.io PrintWriter println

Introduction

In this page you can find the example usage for java.io PrintWriter println.

Prototype

public void println(Object x) 

Source Link

Document

Prints an Object and then terminates the line.

Usage

From source file:net.metanotion.sqlc.SqlcPhp.java

private static void generateStructs(final String outputFolder, final StructManager sm,
        final Set<String> implicits, final Map<String, String> implicitDocs) throws IOException {
    for (final Map.Entry<String, GetInitializer> e : sm) {
        if (!implicits.contains(e.getKey())) {
            continue;
        }/*from   w w  w  .  j av a 2 s .  com*/
        System.out.println("GENERATING " + e.getKey());
        final String docString = implicitDocs.get(e.getKey());
        final GetInitializer gi = e.getValue();

        final Struct s = (Struct) gi;
        final String[] name = e.getKey().split("\\.");
        final String[] pkg = new String[name.length - 1];
        for (int i = 0; i < pkg.length; i++) {
            pkg[i] = name[i];
        }
        final FileOutputStream fos = new FileOutputStream(mkPath(outputFolder, pkg, name[pkg.length]));
        final PrintWriter writer = new PrintWriter(new OutputStreamWriter(fos, "UTF-8"));
        writer.println("<?php");
        if (pkg.length > 0) {
            writer.print("namespace ");
            String sep = "";
            for (String pe : pkg) {
                writer.print(sep + pe);
                sep = "\\";
            }
            writer.println(";");
            writer.println("");
        }

        System.out.println("GENERATING: " + name[pkg.length]);
        writer.print("/** ");
        if (docString != null) {
            writer.println(docString.substring(3, docString.length() - 2));
        }
        writer.println("<i>This is a data/struct/value class generated by the SQLC compiler.</i> */");
        writer.println("final class " + name[pkg.length] + " {");
        for (final String p : s.listProperties()) {
            writer.print("\tpublic ");
            //writer.print(s.getType(p));
            writer.println(" $" + p + ";");
        }
        writer.println("}");
        writer.println("?>");
        writer.close();
        fos.close();
    }
}

From source file:com.indivica.olis.Driver.java

static void writeToFile(String data) {
    try {/*from   w w w.jav  a  2s.c o m*/
        File tempFile = new File(System.getProperty("java.io.tmpdir") + (Math.random() * 100) + ".xml");
        PrintWriter pw = new PrintWriter(new FileWriter(tempFile));
        pw.println(data);
        pw.flush();
        pw.close();
    } catch (Exception e) {
        MiscUtils.getLogger().error("Error", e);
    }
}

From source file:de.jgoldhammer.alfresco.jscript.jmx.JmxDumpUtil.java

/**
 * Show a message stating the JmxDumper has been started, with the current
 * date and time./*  w  w  w . j  a  v  a2  s.c  o m*/
 */
private static void showStartBanner(PrintWriter out) {
    DateFormat df = SimpleDateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
    out.println(JmxDumpUtil.class.getSimpleName() + " started: " + df.format(new Date()));
    out.println();
}

From source file:de.jgoldhammer.alfresco.jscript.jmx.JmxDumpUtil.java

/**
 * Outputs a single value, dealing with nested arrays and CompositeData
 * objects.//from w  w w .  java2 s .  c om
 * 
 * @param out
 *            PrintWriter to write the output to
 * @param value
 *            the value to output
 * @param nestLevel
 *            the nesting level
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public static void outputValue(PrintWriter out, Object value, int nestLevel) throws IOException {
    if (value == null) {
        out.println(JmxDumpUtil.NULL_VALUE);
    } else if (value.getClass().isArray()) {
        int length = Array.getLength(value);
        if (length == 0) {
            out.println("[]");
        } else {
            out.println();
            indent(out, nestLevel + 1);
            out.println('[');
            for (int i = 0; i < length; i++) {
                indent(out, nestLevel + 2);
                outputValue(out, Array.get(value, i), nestLevel + 2);
                if (i + 1 < length) {
                    indent(out, nestLevel + 1);
                    out.println(',');
                }
            }
            indent(out, nestLevel + 1);
            out.println(']');
        }
    } else if (value instanceof CompositeData) {
        out.println();
        indent(out, nestLevel + 1);
        out.println('[');
        printCompositeInfo((CompositeData) value, out, nestLevel + 2);
        indent(out, nestLevel + 1);
        out.println(']');
    } else {
        out.println(value.toString());
    }
}

From source file:net.cristcost.study.services.ServiceTestUtil.java

private static void wait(PrintWriter writer, HttpServletRequest request,
        AuthenticationManager authenticationManager) {
    if (request.getParameter("entropy") != null) {
        try {/*from ww w  . j  a va 2s . c  o  m*/
            int waitTime = Integer.parseInt(request.getParameter("wait"));
            Thread.sleep(waitTime);
            writer.println("* Waiting for creating Thread entropy: " + waitTime + " ms");

        } catch (NumberFormatException | InterruptedException e) {
            writer.println("* Exception while creating Thread entropy: " + e.getMessage());
        }
        writer.println();
    }
}

From source file:gov.nih.nci.caarray.application.translation.geosoft.GeoSoftFileWriterUtil.java

private static void writeSeriesSection(Experiment experiment, String permaLinkUrl, PrintWriter out) {
    out.print("^SERIES=");
    out.println(experiment.getPublicIdentifier());
    out.print("!Series_title=");
    out.println(experiment.getTitle());//from w  w  w.j  a  v  a 2  s.  c  om
    out.print("!Series_summary=");
    final String desc = StringUtils.isNotBlank(experiment.getDescription()) ? experiment.getDescription()
            : experiment.getTitle();
    out.println(desc);
    writeExperimentDesignTypes(experiment, desc, out);
    for (final Publication pub : experiment.getPublications()) {
        out.print("!Series_pubmed_id=");
        out.println(pub.getPubMedId());
    }
    for (final ExperimentContact c : experiment.getExperimentContacts()) {
        writeExperimentContact(c, out);
    }
    out.print("!Series_web_link=");
    out.println(permaLinkUrl);
    for (final Hybridization h : experiment.getHybridizations()) {
        out.print("!Series_sample_id=");
        out.println(h.getName());
    }
}

From source file:Main.java

/**
 * Save the contents of a table to a TSV file
 * Note:  uses toString() on the header cells as well as the data cells.  If you've got funny columns,
 * expect funny behavior/*  w w  w .  j  a v a2  s  . c o  m*/
 * @param table
 * @param outFile
 * @throws IOException
 */
public static void SaveTableAsTSV(JTable table, File outFile) throws IOException {
    PrintWriter outPW = new PrintWriter(outFile);

    TableModel tableModel = table.getModel();
    TableColumnModel columnModel = table.getColumnModel();

    StringBuffer headerLineBuf = new StringBuffer();
    for (int i = 0; i < columnModel.getColumnCount(); i++) {
        if (i > 0)
            headerLineBuf.append("\t");
        headerLineBuf.append(columnModel.getColumn(i).getHeaderValue().toString());
    }
    outPW.println(headerLineBuf.toString());
    outPW.flush();
    for (int i = 0; i < tableModel.getRowCount(); i++) {
        StringBuffer lineBuf = new StringBuffer();
        for (int j = 0; j < tableModel.getColumnCount(); j++) {
            if (j > 0)
                lineBuf.append("\t");
            lineBuf.append(tableModel.getValueAt(i, j).toString());
        }
        outPW.println(lineBuf.toString());
        outPW.flush();
    }
    outPW.close();
}

From source file:org.age.console.command.TestCommand.java

private static void listExamples(final @NonNull PrintWriter printWriter) {
    log.debug("Listing examples.");
    try {//  w  w w .j  av a  2 s  .c o m
        final ClassPath classPath = ClassPath.from(TestCommand.class.getClassLoader());
        final ImmutableSet<ClassPath.ClassInfo> classes = classPath.getTopLevelClasses(EXAMPLES_PACKAGE);
        log.debug("Class path {}.", classes);
        classes.forEach(klass -> printWriter.println(klass.getSimpleName()));
    } catch (final IOException e) {
        log.error("Cannot load classes.", e);
        printWriter.println("Error: Cannot load classes.");
    }
}

From source file:grails.util.GrailsUtil.java

public static void printSanitizedStackTrace(Throwable t, PrintWriter p, StackTraceFilterer stackTraceFilterer) {
    t = stackTraceFilterer.filter(t);/*from   w w w . jav  a  2  s . c  o  m*/

    StackTraceElement[] trace = t.getStackTrace();
    for (StackTraceElement stackTraceElement : trace) {
        p.println("at " + stackTraceElement.getClassName() + "(" + stackTraceElement.getMethodName() + ":"
                + stackTraceElement.getLineNumber() + ")");
    }
}

From source file:org.epics.archiverappliance.utils.ui.GetUrlContent.java

/**
 * Combine JSON arrays of JSON objects from multiple URL's in sequence and sends them to the writer..
 * The difference from combineJSONArrays is that inserts a newline after each element.
 * //from  ww  w . j  a  v a 2 s .  c  o  m
 * @param urlStrs multiple URLs
 * @param out PrintWriter 
 */
public static void combineJSONArraysAndPrintln(List<String> urlStrs, PrintWriter out) {
    out.println("[");
    boolean first = true;
    for (String urlStr : urlStrs) {
        try {
            logger.debug("Getting the contents of " + urlStr + " as a JSON array.");
            JSONParser parser = new JSONParser();
            try (InputStream is = getURLContentAsStream(urlStr)) {
                JSONArray content = (JSONArray) parser.parse(new InputStreamReader(is));
                if (content != null) {
                    for (Object obj : content) {
                        JSONObject jsonObj = (JSONObject) obj;
                        if (first) {
                            first = false;
                        } else {
                            out.println(",");
                        }
                        out.print(JSONValue.toJSONString(jsonObj));
                    }
                } else {
                    logger.debug(urlStr + " returned an empty array");
                }
            }
        } catch (IOException ex) {
            logger.error("Exception getting contents of internal URL " + urlStr, ex);
        } catch (ParseException pex) {
            logger.error(
                    "Parse exception getting contents of internal URL " + urlStr + " at " + pex.getPosition(),
                    pex);
        }
    }
    out.println("]");
}