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.jaeksoft.searchlib.util.ExceptionUtils.java

public final static String getFullStackTrace(StackTraceElement[] stackTrace) {
    StringWriter sw = null;/*from ww  w  .  j a  v  a 2s.  c  om*/
    PrintWriter pw = null;
    try {
        sw = new StringWriter();
        pw = new PrintWriter(sw);
        for (StackTraceElement element : stackTrace)
            pw.println(element);
        return sw.toString();
    } finally {
        IOUtils.close(pw, sw);
    }
}

From source file:com.tractionsoftware.reshoot.Reshoot.java

private static void showUsageAndExit(org.apache.commons.cli.Options options) {
    PrintWriter pw = new PrintWriter(System.out);

    pw.println("Reshoot uses Selenium WebDriver to automate shooting product screenshots");
    pw.println();/*from   w w w.  j  a  v  a  2 s  .com*/
    pw.println("  Usage:");
    pw.println("    java -jar Reshoot.jar [options] [files...]");
    pw.println();
    pw.println("  Options:");

    HelpFormatter formatter = new HelpFormatter();
    formatter.printOptions(pw, 74, options, 1, 2);

    pw.println();
    pw.println("  Documentation:");
    pw.println("    https://github.com/tractionsoftware/reshoot");
    pw.println();

    pw.flush();
    System.exit(1);
}

From source file:Main.java

/**
 * Print the stack trace for a SQLException to a 
 * specified PrintWriter. //from  ww  w  .j a v  a 2s . co m
 *
 * @param e SQLException to print stack trace of
 * @param pw PrintWriter to print to
 */
public static void printStackTrace(SQLException e, PrintWriter pw) {

    SQLException next = e;
    while (next != null) {
        next.printStackTrace(pw);
        next = next.getNextException();
        if (next != null) {
            pw.println("Next SQLException:");
        }
    }
}

From source file:gov.nist.appvet.tool.synchtest.util.ReportUtil.java

/**
 * This method returns report information to the AppVet ToolAdapter as ASCII
 * text and cannot attach a file to the response.
 *///from  w  w  w  .j  a v a  2  s  . c  o  m
public static boolean sendInHttpResponse(HttpServletResponse response, String reportText,
        ToolStatus reportStatus) {
    try {
        response.setStatus(HttpServletResponse.SC_OK); // HTTP 200
        response.setContentType("text/html");
        response.setHeader("apprisk", reportStatus.name());
        PrintWriter out = response.getWriter();
        out.println(reportText);
        out.flush();
        out.close();
        log.info("Returned report");
        return true;
    } catch (IOException e) {
        log.error("Report not sent: " + e.toString());
        return false;
    }
}

From source file:sample.server.NativeGemFireServer.java

private static void writeStringTo(File file, String fileContents) {
    PrintWriter fileWriter = null;

    try {/*from  ww  w .ja v  a  2s .c o  m*/
        fileWriter = new PrintWriter(new BufferedWriter(new FileWriter(file, true)), true);
        fileWriter.println(fileContents);
        fileWriter.flush();
    } catch (IOException e) {
        throw new RuntimeException(String.format("Failed to write [%s] to file [%s]", fileContents, file), e);
    } finally {
        if (fileWriter != null) {
            fileWriter.close();
        }
    }
}

From source file:com.dongli.model.MyJSONData.java

public static void updateObject(MyJSONObject mjo) throws MyRESTException {

    String uid = mjo.getUID();/*from   www. j  a v  a  2s .  c  o  m*/
    MyJSONObject myJSONObject = queryObject(uid);

    String path = "/tmp/" + uid;

    // write the JSON object to a tmp file
    try {
        FileWriter fw = new FileWriter(path, false);
        PrintWriter pw = new PrintWriter(fw);
        pw.println(mjo.toString());
        pw.close();
        fw.close();
    } catch (IOException e) {
        // failed to create the new object
        File nf = new File(path);
        nf.delete();
        throw new MyRESTException("Failed to update the object.");
    }

    // update the new object on Amazon AWS S3 
    try {
        File uploadFile = new File(path);
        MyAWSStorage.getInstance().s3client
                .putObject(new PutObjectRequest(MyConfiguration.getInstance().bucket, uid, uploadFile));
    } catch (AmazonServiceException ase) {
        throw new MyRESTException("Failed to update the object " + uid + ".");
    } catch (AmazonClientException ace) {
        throw new MyRESTException("Failed to qpdate the object " + uid + ".");
    }
}

From source file:org.shareok.data.plosdata.PlosUtil.java

public static void createContentFile(String fileName, String content) {
    try {/*from w w  w . ja  va2  s.com*/
        PrintWriter writer = new PrintWriter(fileName, "UTF-8");
        writer.println(content);
        writer.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.dongli.model.MyJSONData.java

public static String createObject(MyJSONObject mjo) throws MyRESTException {

    // generate uid for this object
    String uid = UIDGenerator.getUID();
    mjo.setUID(uid);//from  w w w.  j  a  v a2s .c o m

    // tmp path of data file to store this object. The file will to sent to S3 later.
    String path = "/tmp/" + uid;

    try {
        FileWriter fw = new FileWriter(path, false);
        PrintWriter pw = new PrintWriter(fw);
        pw.println(mjo.toString());
        pw.close();
        fw.close();
    } catch (IOException e) {
        // e.printStackTrace();
        // failed to create the new object
        File nf = new File(path);
        nf.delete();
        throw new MyRESTException("Failed to create the object " + uid + ".");
    }

    // create the new object on AWS S3 
    try {
        File uploadFile = new File(path);
        MyAWSStorage.getInstance().s3client
                .putObject(new PutObjectRequest(MyConfiguration.getInstance().bucket, uid, uploadFile));
    } catch (AmazonServiceException ase) {
        throw new MyRESTException("Failed to create the object " + uid + ".");
    } catch (AmazonClientException ace) {
        throw new MyRESTException("Failed to create the object " + uid + ".");
    }

    return uid;
}

From source file:mp1.include.me.Sabsalon1.java

private static void writeOutput() throws FileNotFoundException, UnsupportedEncodingException {
    System.out.println("\nWriting to file...(outputFile.out)");
    PrintWriter writer = new PrintWriter("outputFile.out", "UTF-8");
    finaloutput.stream().forEach((element) -> {
        writer.println(element);
    });/*from w  w w .  ja va 2 s . c om*/
    writer.close();
    System.out.println("File write success!");
}

From source file:Main.java

/**
 * Saves an index (Hashtable) to a file.
 * //from w w  w  .  java 2 s.  c  om
 * @param root_
 *            The file where the index is stored in.
 * @param index
 *            The indextable.
 * @exception IOException
 *                If an internal error prevents the file from being written.
 */
public static void saveIndex(File root_, String name, Hashtable index) throws IOException {
    File indexfile = new File(root_, name);
    PrintWriter out = new PrintWriter(new FileWriter(indexfile));
    Enumeration keys = index.keys();
    String key = null;
    while (keys.hasMoreElements()) {
        key = (String) keys.nextElement();
        out.println(key);
        out.println((Long) index.get(key));
    }
    out.close();
}