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:com.sldeditor.tool.html.ExportHTML.java

/**
 * Save all html to folder./*  w  w  w.  j a  v a2  s. com*/
 *
 * @param destinationFolder the destination folder
 * @param filename the filename
 * @param sldDataList the sld data list
 * @param backgroundColour the background colour
 */
public static void save(File destinationFolder, String filename, List<SLDDataInterface> sldDataList,
        Color backgroundColour) {
    if (!destinationFolder.exists()) {
        destinationFolder.mkdirs();
    }

    InputStream inputStream = ExportHTML.class.getResourceAsStream(HTML_TEMPLATE);

    if (inputStream == null) {
        ConsoleManager.getInstance().error(ExportHTML.class, "Failed to find html template");
    } else {
        String htmlTemplate = null;
        BufferedReader reader = null;
        try {
            File file = stream2file(inputStream);

            reader = new BufferedReader(new FileReader(file));
            String line = null;
            StringBuilder stringBuilder = new StringBuilder();
            String ls = System.getProperty("line.separator");

            while ((line = reader.readLine()) != null) {
                stringBuilder.append(line);
                stringBuilder.append(ls);
            }
            htmlTemplate = stringBuilder.toString();
        } catch (Exception e) {
            ConsoleManager.getInstance().exception(ExportHTML.class, e);
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    ConsoleManager.getInstance().exception(ExportHTML.class, e);
                }
            }
        }

        StringBuilder sb = new StringBuilder();
        sb.append("  <tr>\n");
        sb.append("    <th>Layer Name</th>\n");
        sb.append("    <th>Legend</th>\n");
        sb.append("  </tr>\n");

        for (SLDDataInterface sldData : sldDataList) {
            StyleWrapper styleWrapper = sldData.getStyle();

            String layerName = styleWrapper.getStyle();
            sb.append("  <tr>\n");

            sb.append(String.format("    <td>%s</td>\n", layerName));

            StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);

            if (sld != null) {
                String showHeading = null;
                String showFilename = null;

                List<String> legendFileNameList = new ArrayList<String>();

                boolean result = LegendManager.getInstance().saveLegendImage(backgroundColour, sld,
                        destinationFolder, layerName, showHeading, showFilename, legendFileNameList);

                if (result) {
                    String legendFilename = legendFileNameList.get(0);
                    sb.append(String.format("    <td><img src=\"%s\" alt=\"%s\" ></td>\n", legendFilename,
                            layerName));
                }
            }
            sb.append("  </tr>\n");
        }

        if (htmlTemplate != null) {
            htmlTemplate = htmlTemplate.replace(TEMPLATE_INSERT_CODE, sb.toString());

            PrintWriter out;
            try {
                File f = new File(destinationFolder, filename);
                out = new PrintWriter(f);
                out.println(htmlTemplate);
                out.close();
            } catch (FileNotFoundException e) {
                ConsoleManager.getInstance().exception(ExportHTML.class, e);
            }
        }
    }
}

From source file:ThreadLister.java

/** Display info about a thread group and its threads and groups */
private static void printGroupInfo(PrintWriter out, ThreadGroup g, String indent) {
    if (g == null)
        return;//from w w  w.ja  v a 2s . com
    int num_threads = g.activeCount();
    int num_groups = g.activeGroupCount();
    Thread[] threads = new Thread[num_threads];
    ThreadGroup[] groups = new ThreadGroup[num_groups];

    g.enumerate(threads, false);
    g.enumerate(groups, false);

    out.println(indent + "Thread Group: " + g.getName() + "  Max Priority: " + g.getMaxPriority()
            + (g.isDaemon() ? " Daemon" : ""));

    for (int i = 0; i < num_threads; i++)
        printThreadInfo(out, threads[i], indent + "    ");
    for (int i = 0; i < num_groups; i++)
        printGroupInfo(out, groups[i], indent + "    ");
}

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

private static void clearAuthentication(PrintWriter writer, SecurityContext oldContext) {
    if (oldContext != SecurityContextHolder.getContext()) {
        SecurityContextHolder.clearContext();
        SecurityContextHolder.setContext(oldContext);
        writer.println("@Restoring older context after secured session");
    }/* www  .j a v  a 2  s  .c o  m*/
}

From source file:edu.msu.cme.rdp.readseq.utils.SequenceTrimmer.java

public static void writeStats(PrintWriter out, String seqName, TrimStats stats, boolean passed) {
    out.println(String.format("%s\t%d\t%d\t%.2f\t%d\t%d\t%d\t%d\t%d\t%d\t%b", seqName, stats.seqStart,
            stats.seqStop, stats.filledRatio, stats.seqTrimStart, stats.seqTrimStop, stats.numNs,
            stats.nsInTrim, stats.trimmedLength, stats.seqLength, passed));
}

From source file:io.stallion.plugins.javascript.JavascriptShell.java

private static Context makeContext(InputStream in, OutputStream out, OutputStream err, String[] args) {

    PrintStream pout = out instanceof PrintStream ? (PrintStream) out : new PrintStream(out);
    PrintStream perr = err instanceof PrintStream ? (PrintStream) err : new PrintStream(err);
    PrintWriter wout = new PrintWriter(pout, true);
    PrintWriter werr = new PrintWriter(perr, true);
    ErrorManager errors = new ErrorManager(werr);
    Options options = new Options("nashorn", werr);
    if (args != null) {
        try {/*from   www  .ja  va 2s. c om*/
            options.process(args);
        } catch (IllegalArgumentException var27) {
            werr.println(bundle.getString("shell.usage"));
            options.displayHelp(var27);
            return null;
        }
    }
    return new Context(options, errors, wout, werr, Thread.currentThread().getContextClassLoader());
}

From source file:com.l2jfree.lang.L2Thread.java

public static void dumpThreads() {
    PrintWriter pw = null;
    try {/*from   w  w  w  .ja va 2 s  .c  om*/
        pw = new PrintWriter(new FileWriter("Thread-" + System.currentTimeMillis() + ".log"), true);

        for (String line : getStats())
            pw.println(line);
    } catch (Exception e) {
        _log.warn("", e);
    } finally {
        IOUtils.closeQuietly(pw);
    }
}

From source file:com.quattroresearch.helm.HlConfigEntry.java

public static void handleInputOutputFiles(String ifilename, String ofilename)
        throws IOException, JDOMException {
    BufferedReader br = new BufferedReader(new FileReader(ifilename));
    PrintWriter pw = new PrintWriter(ofilename);
    String helmString;//from  w  ww.  ja va  2  s . co m

    // initialize the output HTML file:
    pw.println("<html>\n<head>\n<meta charset=\"UTF-8\">\n<font style=\"font-size: "
            + defaultFontsizeEntry.value + "pt\">\n</head>\n<body>");

    while ((helmString = br.readLine()) != null) { // read and process all HELM2-Strings from the input file
        processHelmString(helmString, pw);
    }
    br.close();

    pw.println("</body>\n</html>"); // write out the closing HTML sequence
    pw.flush();
    pw.close();
}

From source file:bide.simulation.Simulation.java

private static void generateSimDataFile(String simFile, GelSetting g, int noOfSpot) {
    try {/* w  w w  .  ja v a  2s. com*/

        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(simFile)));
        out.println(g.createLabel());
        for (int j = 0; j < noOfSpot; j++) {
            out.println(j + "\t" + GelSetting.printGel(g.generateSpot()));
        }
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:cpd3314.buildit12.CPD3314BuildIt12.java

/**
 * Build a sample method that saves a handful of car instances as Serialized
 * objects, and as JSON objects.//from   w  w  w.  j a v a  2  s .  c om
 */
public static void doBuildIt2Output() {
    Car[] cars = { new Car("Honda", "Civic", 2001), new Car("Buick", "LeSabre", 2003),
            new Car("Toyota", "Camry", 2005) };

    // Saves as Serialized Objects
    try {
        FileOutputStream objFile = new FileOutputStream("cars.obj");
        ObjectOutputStream objStream = new ObjectOutputStream(objFile);

        for (Car car : cars) {
            objStream.writeObject(car);
        }

        objStream.close();
        objFile.close();
    } catch (IOException ex) {
        Logger.getLogger(CPD3314BuildIt12.class.getName()).log(Level.SEVERE, null, ex);
    }

    // Saves as JSONObject
    try {
        PrintWriter jsonStream = new PrintWriter("cars.json");

        JSONArray arr = new JSONArray();
        for (Car car : cars) {
            arr.add(car.toJSON());
        }

        JSONObject json = new JSONObject();
        json.put("cars", arr);

        jsonStream.println(json.toJSONString());

        jsonStream.close();
    } catch (IOException ex) {
        Logger.getLogger(CPD3314BuildIt12.class.getName()).log(Level.SEVERE, null, ex);
    }
}

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

private static void invokeSecuredBean(PrintWriter writer, TestService service) {

    if (service != null) {
        String serviceName = service.getName();
        String serviceDescription = service.getDescription();

        writer.println("### Performing test on " + serviceName + "###");
        writer.println(serviceDescription);
        writer.println();//from   w w w .ja v a2 s  . c  o  m

        try {
            service.serviceOne();
            writer.println("Executed " + serviceName + ".serviceOne();");
        } catch (AuthenticationException | AccessDeniedException e) {
            writer.println("Auth failed: " + e.getMessage() + " (" + e.getClass().getSimpleName() + ")");
        }
        try {
            service.serviceTwo("input");
            writer.println("Executed " + serviceName + ".serviceTwo(...);");
        } catch (AuthenticationException | AccessDeniedException e) {
            writer.println("Auth failed: " + e.getMessage() + " (" + e.getClass().getSimpleName() + ")");
        }
        try {
            String ret = service.serviceThree();
            writer.println("Executed " + serviceName + ".serviceThree(); with result: " + ret);
        } catch (AuthenticationException | AccessDeniedException e) {
            writer.println("Auth failed: " + e.getMessage() + " (" + e.getClass().getSimpleName() + ")");
        }
        try {
            String ret = service.serviceFour("input");
            writer.println("Executed " + serviceName + ".serviceFour(...); with result: " + ret);
        } catch (AuthenticationException | AccessDeniedException e) {
            writer.println("Auth failed: " + e.getMessage() + " (" + e.getClass().getSimpleName() + ")");
        }
        try {
            List<String> ret = service.serviceFive();
            if (ret != null) {
                writer.println("Executed " + serviceName + ".serviceFive with result "
                        + Arrays.toString(ret.toArray()));
            } else {
                writer.println("Executed " + serviceName + ".serviceFive with result null!");
            }
        } catch (AuthenticationException | AccessDeniedException e) {
            writer.println("Auth failed: " + e.getMessage() + " (" + e.getClass().getSimpleName() + ")");
        }
    } else {
        writer.println("Service bean not injected!");
    }
    writer.println();
    writer.println();
}