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.abid_mujtaba.bitcoin.tracker.data.Data.java

public static void append(String line) throws DataException // Append line to data file.
{
    File file = data_file();/*from   ww  w  . j  av a 2 s . c om*/

    try {
        FileOutputStream fos = new FileOutputStream(file, true); // We pass in true so that the text is appended
        PrintWriter pw = new PrintWriter(fos);
        pw.println(line);
        pw.flush();
        pw.close();
        fos.close();
    } catch (FileNotFoundException e) {
        throw new DataException("Error while writing to file.", e);
    } catch (IOException e) {
        throw new DataException("Error while writing to file.", e);
    }
}

From source file:DebugUtilities.java

public static void printClassHierarchy(Class aClass, PrintWriter writer, String prefix) {
    String subPrefix = "-->";

    for (int i = 0;; ++i) {
        writer.println(prefix + " " + subPrefix + " " + aClass.getName());

        aClass = aClass.getSuperclass();

        if (aClass == Object.class)
            break;

        subPrefix = "--" + subPrefix;
    }//w  w  w. ja  va2s. co m
}

From source file:TextFileTest.java

/**
 * Writes all employees in an array to a print writer
 * @param employees an array of employees
 * @param out a print writer//w w w . j  a v a  2  s.co m
 */
private static void writeData(Employee[] employees, PrintWriter out) throws IOException {
    // write number of employees
    out.println(employees.length);

    for (Employee e : employees)
        e.writeData(out);
}

From source file:Main.java

public static void writeXML(Document d, OutputStream os, String sysID) throws IOException {
    /**/*from   www  . j  a  v a2  s . c  om*/
     * To support i18n, we have to specify the encoding of
     * output writer to UTF-8 when we writing the XML.
     */
    // PrintWriter out=new PrintWriter(os);
    PrintWriter out = new PrintWriter(new OutputStreamWriter(os, "UTF-8"));

    out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    out.println();
    if (sysID != null) {
        out.println("<!DOCTYPE " + d.getDoctype().getName() + " SYSTEM \"" + sysID + "\">");
        out.println();
    }
    //d.getDocumentElement().normalize();
    writeXMLwalkTree(d.getDocumentElement(), 0, out);
    out.flush();
}

From source file:Main.java

public static void writeLine(OutputStream os, PrintWriter logWriter, String value) throws IOException {
    String line = value + "\n";
    os.write(line.getBytes());// www.j a  v a 2 s .co  m
    if (logWriter != null) {
        logWriter.println(value);
    }
}

From source file:net.bluehornreader.web.WebUtils.java

public static void showResult(String result, String nextPath, Request request,
        HttpServletResponse httpServletResponse) throws Exception {
    PrintWriter out = httpServletResponse.getWriter();

    out.println("<html>");
    out.println("<head>");
    out.println("<title>Bluehorn Reader</title>");
    out.println("</head>");

    out.println("<body>"); //ttt1 add formatting
    out.println("<h2>" + result + "</h2>");
    out.println("<p/>");
    out.println("<a href=\"" + nextPath + "\">Continue</a>");
    out.println("<p/>");
    out.println("</body>");
    out.println("</html>");

    request.setHandled(true);/*from   ww  w.  j ava  2 s . c o m*/
}

From source file:net.bluehornreader.web.WebUtils.java

public static void redirectToError(String error, Request request, HttpServletResponse httpServletResponse)
        throws Exception {
    /*MultiMap<String> params = new MultiMap<>(); //ttt2 see if can get this to work: whatever params are set in request, they are lost at redirection
    params.put(PARAM_ERROR, error);//from   w  w  w. ja  v  a2 s .com
    request.setParameters(params);
    request.???
    httpServletResponse.sendRedirect(PATH_ERROR);
     */

    PrintWriter out = httpServletResponse.getWriter();

    out.println("<html>");
    out.println("<head>");
    out.println("<title>Bluehorn Reader Error</title>");
    out.println("</head>");

    out.println("<body>"); //ttt1 add formatting
    out.println("<h2>Error: " + error + "</h2>");
    out.println("<p/>");
    out.println("<a href=\"" + ReaderHandler.PATH_LOGIN + "\">Log in</a>");
    out.println("<p/>");
    out.println("<a href=\"" + ReaderHandler.PATH_SIGNUP + "\">Sign up</a>");
    out.println("</body>");
    out.println("</html>");

    request.setHandled(true);
}

From source file:Main.java

public static void hexaDumpHangul(OutputStream outStream, byte[] data, int len, String desc) {

    //if (desc.compareToIgnoreCase("outflow")==0) return ;    

    PrintWriter out = new PrintWriter(outStream, true);
    int index = 0;

    out.println("[[LEN=" + len + "]/[" + desc + "][" + getTime() + "]]");
    for (int i = 0; i < len; i++) {

        index = (i + 1) % 16;/* www .  j av  a  2s. c om*/

        out.print(byteToHexa(data[i]) + " ");

        if (index == 0) {
            out.println("          " + new String(data, (i + 1) - 16, 16));
        }

    }

    if (index != 0) {
        for (int i = 0; i < 16 - index; i++)
            out.print("  " + " ");
        out.println("          " + new String(data, data.length - index, index));
    }
}

From source file:de.wdilab.coma.gui.extensions.RemoteRepo.java

public static boolean getRemoteConnection(String s, UUID uid) {

    UUID uuid;// www.  j  a  v  a  2  s  .  c o m
    String xslt_text;
    boolean is_stored = false;

    xslt_text = s.replaceAll("\"", "\\\"");
    xslt_text = xslt_text.replaceAll("\'", "\\\'");
    uuid = uid;

    try {
        File f = new File("helpingFile.csv");
        PrintWriter output = new PrintWriter(new FileWriter(f));
        output.println("uuid,data");
        xslt_text.trim();
        xslt_text = xslt_text.replace("\n", "").replace("\r", "");
        output.println(uuid + "," + xslt_text);
        output.close();

        HttpClient client = new DefaultHttpClient();
        FileEntity entity = new FileEntity(f, ContentType.create("text/plain", "UTF-8"));

        HttpPost httppost = new HttpPost(url);
        httppost.setEntity(entity);
        HttpResponse response = client.execute(httppost);
        //            System.out.println(response.getStatusLine().getStatusCode());
        if (response.getStatusLine().getStatusCode() == 200)
            is_stored = true;
        f.delete();
    } catch (IOException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    }

    //        System.out.println("xslt stored   "+is_stored);

    return is_stored;

}

From source file:avantssar.aslanpp.testing.HTMLHelper.java

public static File toHTML(File textFile, boolean lineNumbers) {
    if (textFile != null) {
        File htmlFile = new File(textFile.getAbsolutePath() + ".html");
        try {//from ww w  . j a  v  a  2s  .c  o  m
            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(textFile)));
            PrintWriter writer = new PrintWriter(htmlFile);
            String line;
            writer.println("<html>");
            writer.println("<body>");
            writer.println("<pre>");
            int lineCount = 1;
            while ((line = reader.readLine()) != null) {
                if (lineNumbers) {
                    line = String.format("%4d:   %s", lineCount++, line);
                }
                writer.println(line);
            }
            writer.println("</pre>");
            writer.println("</body>");
            writer.println("</html>");
            reader.close();
            writer.close();
            return htmlFile;
        } catch (IOException ex) {
            System.out.println(
                    "Failed to convert to HTML file '" + textFile.getAbsolutePath() + "': " + ex.getMessage());
            Debug.logger.error(ex);
            return null;
        }
    } else {
        return null;
    }
}