Java Code Examples for java.io.PrintWriter

The following are top voted examples for showing how to use java.io.PrintWriter. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: aws-toolkit-eclipse   File: AwsPortalFeedbackFormUtils.java View source code Vote up 6 votes
public static String getStackTraceFromThrowable(Throwable t) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);

    t.printStackTrace(pw);
    pw.println();

    if (t.getCause() != null) {
        t.getCause().printStackTrace(pw);
    }

    return sw.toString();
}
 
Example 2
Project: iswc2012metadata   File: ToolIO.java View source code Vote up 6 votes
public static void pipeStringToFile(String szContent, File f, boolean bGzip, boolean bAppend)
throws Sw4jException {
	PrintWriter out = prepareUtf8Writer(ToolIO.prepareFileOutputStream(f, bAppend, bGzip));
	if (ToolSafe.isEmpty(szContent))
		out.print("");
	else{
		out.print(szContent);
	}
	out.close();
}
 
Example 3
Project: aws-toolkit-eclipse   File: PlatformEnvironmentDataModel.java View source code Vote up 6 votes
@Override
public String toString() {
    StringWriter sb = new StringWriter();
    PrintWriter pw = new PrintWriter(sb);

    pw.println("============= Platform environment =============");
    pw.println();

    pw.print("Eclipse platform version : ");
    pw.println(getEclipsePlatformVersion());

    pw.print("OS name : ");
    pw.println(getOsName());
    pw.print("OS version : ");
    pw.println(getOsVersion());
    pw.print("OS architecture : ");
    pw.println(getOsArch());
    pw.print("JVM name : ");
    pw.println(getJavaVmName());
    pw.print("JVM version : ");
    pw.println(getJavaVmVersion());
    pw.print("Java lang version : ");
    pw.println(getJavaVersion());
    pw.println();

    pw.println("============= Installed Plug-ins =============");
    pw.println();

    for (Bundle bundle : getInstalledBundles()) {
        pw.println(bundle.toString());
    }

    return sb.toString();
}
 
Example 4
Project: iswc2012metadata   File: ToolIO.java View source code Vote up 6 votes
public static void pipeStringToLineNumberedString(String szText, PrintWriter out)
throws Sw4jException {
	LineNumberReader reader = new LineNumberReader(pipeStringToReader(szText));
	String line=null;
	try {
		while (null!=(line=reader.readLine())){
			out.println(String.format("%d: %s", reader.getLineNumber(), line));
		}
		out.flush();
		out.close();
		reader.close();

	} catch (IOException e) {
		Sw4jException e1 = new Sw4jException(Sw4jMessage.STATE_FATAL, e);
		getLogger().error(e1.getMessage());
	}
}
 
Example 5
Project: iswc2012metadata   File: ToolIO.java View source code Vote up 6 votes
public static PrintWriter prepareUtf8Writer(OutputStream out, boolean bAutoFlush){
	try {
		getLogger().info("use utf-8 as output");
		PrintWriter ret =  new PrintWriter(new OutputStreamWriter(out,"UTF-8"));
		ret.write('\ufeff'); //add BOM
		return ret;
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
		return null;
	}
}
 
Example 6
Project: jena   File: MgtCmdServlet.java View source code Vote up 6 votes
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
{
    try {
        // serverLog.info("Fuseki Server Config servlet") ;

        PrintWriter out = resp.getWriter() ;
        resp.setContentType("text/plain") ;
        SPARQLServer server = Fuseki.getServer() ;

        out.println("Software:") ;
        String fusekiVersion = Fuseki.VERSION ;
        if ( fusekiVersion.equals("${project.version}") )
            fusekiVersion = "(development)" ;

        out.printf("  %s %s\n", Fuseki.NAME, fusekiVersion) ;
        out.printf("  %s %s\n", TDB.NAME, TDB.VERSION) ;
        out.printf("  %s %s\n", ARQ.NAME, ARQ.VERSION) ;
        out.printf("  %s %s\n", Jena.NAME, Jena.VERSION) ;

        // out.printf("Port: %s\n",
        // server.getServer().getConnectors()[0].getPort()) ;
        out.println() ;

        for ( DatasetRef dsRef : server.getDatasets() ) {
            datasetRefDetails(out, dsRef) ;
            out.println() ;
        }
    }
    catch (IOException ex) {}
}
 
Example 7
Project: jboss-dmr   File: ObjectModelValue.java View source code Vote up 6 votes
@Override
void format(final PrintWriter writer, final int indent, final boolean multiLineRequested) {
    writer.append('{');
    final boolean multiLine = multiLineRequested && map.size() > 1;
    if (multiLine) {
        indent(writer.append('\n'), indent + 1);
    }
    final Iterator<Map.Entry<String, ModelNode>> iterator = map.entrySet().iterator();
    while (iterator.hasNext()) {
        final Map.Entry<String, ModelNode> entry = iterator.next();
        writer.append(quote(entry.getKey()));
        final ModelNode value = entry.getValue();
        writer.append(" => ");
        value.format(writer, multiLine ? indent + 1 : indent, multiLineRequested);
        if (iterator.hasNext()) {
            if (multiLine) {
                indent(writer.append(",\n"), indent + 1);
            } else {
                writer.append(',');
            }
        }
    }
    if (multiLine) {
        indent(writer.append('\n'), indent);
    }
    writer.append('}');
}
 
Example 8
Project: statalign   File: ExportTools.java View source code Vote up 6 votes
private static void writeChildrenNodeToFile(Node thisnode, Node parent, PrintWriter out){
	//Writes tree in Newick format 
	if(thisnode.getChildren().size()>0){
		out.write("(");
	}
	int cnt = 0;
	for(Node child:thisnode.getChildren()){
		writeChildrenNodeToFile(child, thisnode, out);
		if(cnt<thisnode.getChildren().size()-1){
			//if there are more children
			out.write(",");
		}
		cnt++;
	}
	if(thisnode.getChildren().size()>0){
		out.write(")");
	}
	if(thisnode.getName()!=null){
		//a node with name
		out.write(thisnode.getName());
	}
	if(thisnode.getDistanceFromParent()!=0){
		out.format(":%.4f",thisnode.getDistanceFromParent());
	}
}
 
Example 9
Project: clapir   File: AudioUtil.java View source code Vote up 6 votes
public static void outputData(short [] data, PrintWriter writer)
{
    for (int i = 0; i < data.length; i++)
    {
        writer.println(String.valueOf(data[i]));
    }
    if (writer.checkError())
    {
        Log.w(TAG, "Error writing sensor event data");
    }
}
 
Example 10
Project: EclipseTrader   File: BlockingBuffer.java View source code Vote up 6 votes
/**
 * Gets the next value from the buffer, waiting until an object is
 * added if the buffer is empty. This method uses the default timeout
 * set in the constructor.
 *
 * @throws BufferUnderflowException if an interrupt is received
 */
public Object get() {
    synchronized (lock) {
        while (collection.isEmpty()) {
            try {
                if (timeout <= 0) {
                    lock.wait();
                } else {
                    return get(timeout);
                }
            } catch (InterruptedException e) {
                PrintWriter out = new PrintWriter(new StringWriter());
                e.printStackTrace(out);
                throw new BufferUnderflowException("Caused by InterruptedException: " + out.toString());
            }
        }
        return getBuffer().get();
    }
}