List of usage examples for java.io PrintWriter PrintWriter
public PrintWriter(File file) throws FileNotFoundException
From source file:es.tunelator.log.Logger.java
/** * @param e/*from w w w . j av a2 s . co m*/ * @return */ private static String getStringStackTrace(Throwable e) { StringWriter sw = new StringWriter(); PrintWriter w = new PrintWriter(sw); e.printStackTrace(w); return sw.toString(); }
From source file:EchoServer.java
public void run() { System.out.println("Accepted Client : ID - " + clientID + " : Address - " + clientSocket.getInetAddress().getHostName()); try {/* w w w .j a va 2 s. c o m*/ BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); PrintWriter out = new PrintWriter(new OutputStreamWriter(clientSocket.getOutputStream())); while (running) { String clientCommand = in.readLine(); System.out.println("Client Says :" + clientCommand); if (clientCommand.equalsIgnoreCase("quit")) { running = false; System.out.print("Stopping client thread for client : " + clientID); } else { out.println(clientCommand); out.flush(); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:gov.nih.nci.cadsr.cadsrpasswordchange.core.CommonUtil.java
public static String toString(Throwable theException) { // Create a StringWriter and a PrintWriter both of these object // will be used to convert the data in the stack trace to a string. ////from w ww . j a v a 2s . c om StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); // // Instead of writting the stack trace in the console we write it // to the PrintWriter, to get the stack trace message we then call // the toString() method of StringWriter. // theException.printStackTrace(pw); return sw.toString(); }
From source file:IndentPrinter.java
public IndentPrinter() { this(new PrintWriter(System.out), " "); }
From source file:org.jodconverter.boot.LocalConverterITest.java
/** * Creates an input file to convert and an output test directory just once. * * @throws IOException if an IO error occurs. *///from w w w. ja va2s. c o m @BeforeClass public static void setUpClass() throws IOException { inputFileTxt = testFolder.newFile("inputFile.txt"); try (final PrintWriter writer = new PrintWriter(new FileWriter(inputFileTxt))) { writer.println("This is the first line of the input file."); writer.println("This is the second line of the input file."); } }
From source file:io.proleap.vb6.TestGenerator.java
public static void generateTestClass(final File vb6InputFile, final File outputDirectory, final String packageName) throws IOException { final String inputFilename = getInputFilename(vb6InputFile); final File outputFile = new File( outputDirectory + "/" + inputFilename + OUTPUT_FILE_SUFFIX + JAVA_EXTENSION); final boolean createdNewFile = outputFile.createNewFile(); if (createdNewFile) { LOG.info("Creating unit test {}.", outputFile); final PrintWriter pWriter = new PrintWriter(new FileWriter(outputFile)); final String vb6InputFileName = vb6InputFile.getPath().replace("\\", "/"); pWriter.write("package " + packageName + ";\n"); pWriter.write("\n"); pWriter.write("import java.io.File;\n"); pWriter.write("\n"); pWriter.write("import org.junit.Test;\n"); pWriter.write("import io.proleap.vb6.runner.VbParseTestRunner;\n"); pWriter.write("import io.proleap.vb6.runner.impl.VbParseTestRunnerImpl;\n"); pWriter.write("\n"); pWriter.write("public class " + inputFilename + "Test {\n"); pWriter.write("\n"); pWriter.write(" @Test\n"); pWriter.write(" public void test() throws Exception {\n"); pWriter.write(" final File inputFile = new File(\"" + vb6InputFileName + "\");\n"); pWriter.write(" final VbParseTestRunner runner = new VbParseTestRunnerImpl();\n"); pWriter.write(" runner.parseFile(inputFile);\n"); pWriter.write(" }\n"); pWriter.write("}"); pWriter.flush();//w w w. j a v a 2s. c om pWriter.close(); } }
From source file:io.opentracing.contrib.elasticsearch.common.SpanDecorator.java
private static Map<String, Object> errorLogs(Throwable throwable) { Map<String, Object> errorLogs = new HashMap<>(4); errorLogs.put("event", Tags.ERROR.getKey()); errorLogs.put("error.kind", throwable.getClass().getName()); errorLogs.put("error.object", throwable); errorLogs.put("message", throwable.getMessage()); StringWriter sw = new StringWriter(); throwable.printStackTrace(new PrintWriter(sw)); errorLogs.put("stack", sw.toString()); return errorLogs; }
From source file:com.eyeq.pivot4j.util.MarkupWriter.java
/** * @param writer/*from ww w . j ava2 s. c o m*/ */ public MarkupWriter(Writer writer) { if (writer == null) { throw new NullArgumentException("writer"); } this.writer = new PrintWriter(writer); }
From source file:com.thoughtworks.go.agent.launcher.ServerCall.java
public static ServerResponseWrapper invoke(HttpMethod method) throws Exception { HashMap<String, String> headers = new HashMap<String, String>(); HttpClient httpClient = new HttpClient(); httpClient.setConnectionTimeout(HTTP_TIMEOUT_IN_MILLISECONDS); try {// w w w.j a v a 2s . co m final int status = httpClient.executeMethod(method); if (status == HttpStatus.SC_NOT_FOUND) { StringWriter sw = new StringWriter(); PrintWriter out = new PrintWriter(sw); out.println("Return Code: " + status); out.println("Few Possible Causes: "); out.println("1. Your Go Server is down or not accessible."); out.println( "2. This agent might be incompatible with your Go Server.Please fix the version mismatch between Go Server and Go Agent."); out.close(); throw new Exception(sw.toString()); } if (status != HttpStatus.SC_OK) { throw new Exception("Got status " + status + " " + method.getStatusText() + " from server"); } for (Header header : method.getResponseHeaders()) { headers.put(header.getName(), header.getValue()); } return new ServerResponseWrapper(headers, method.getResponseBodyAsStream()); } catch (Exception e) { String message = "Couldn't access Go Server with base url: " + method.getURI() + ": " + e.toString(); LOG.error(message); throw new Exception(message, e); } finally { method.releaseConnection(); } }
From source file:edu.illinois.cs.cogcomp.wikifier.utils.freebase.cleanDL.java
private static void outputMentions() throws FileNotFoundException { PrintWriter w = new PrintWriter("/Users/Shyam/mention.eval.dl.out"); for (String doc : mentions.keySet()) { for (DocMention tmp : mentions.get(doc)) w.println(doc + "\t" + tmp.start + "\t" + tmp.end + "\t" + tmp.mention); }// w w w. jav a 2 s . c o m w.close(); }