List of usage examples for java.io PrintWriter close
public void close()
From source file:org.jenkinsci.plugins.pipeline.modeldefinition.endpoints.ModelConverterAction.java
public static List<String> errorToStrings(Exception e) { List<String> output = new ArrayList<>(); if (e instanceof MultipleCompilationErrorsException) { MultipleCompilationErrorsException ce = (MultipleCompilationErrorsException) e; for (Object o : ce.getErrorCollector().getErrors()) { if (o instanceof SyntaxErrorMessage) { SyntaxErrorMessage s = (SyntaxErrorMessage) o; StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); s.write(pw);/*www . ja v a2 s .c om*/ pw.close(); output.add(sw.toString()); } } } else { output.add(e.getMessage()); } return output; }
From source file:com.github.fcannizzaro.prefs.Prefs.java
/** * Write each change on the file//from w w w .ja va2 s.c om */ private static void updateMemory() { try { PrintWriter output = new PrintWriter(new FileWriter("res/" + resource)); output.print(json.toString()); output.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:net.mybox.mybox.Server.java
private static void log(String message) { // TODO: change this to be a static PrintWriter opened at construction time PrintWriter out = null; try {/* w w w . ja va 2 s. c o m*/ out = new PrintWriter(new FileWriter(logFile, true)); } catch (Exception e) { System.out.println("Unable to open log file: " + e); } out.print(message); out.close(); }
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 {/*from w w w. j a v a 2 s.c o 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:com.dianping.avatar.cache.util.CacheMonitorUtil.java
private static String getErrorString(Throwable throwable) { OutputStream out = null;/*from w w w . j a va 2s . co m*/ PrintWriter writer = null; try { out = new ByteArrayOutputStream(3000); writer = new PrintWriter(out); throwable.printStackTrace(writer); writer.flush(); return out.toString(); } catch (Exception e2) { return throwable.getMessage(); } finally { if (writer != null) { writer.close(); } out = null; writer = null; } }
From source file:com.indivica.olis.Driver.java
static void writeToFile(String data) { try {/*w w w . j av a 2 s . c o m*/ File tempFile = new File(System.getProperty("java.io.tmpdir") + (Math.random() * 100) + ".xml"); PrintWriter pw = new PrintWriter(new FileWriter(tempFile)); pw.println(data); pw.flush(); pw.close(); } catch (Exception e) { MiscUtils.getLogger().error("Error", e); } }
From source file:IO.java
public static void writeData(int[] data, int nData, String filepath) { File file = new File(filepath); PrintWriter writer; try {// w w w .j a va 2 s . co m writer = new PrintWriter(file); for (int i = 0; i < nData; i++) { if (i == nData - 1) { writer.print(data[i]); } else { writer.print(data[i] + ","); } } writer.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:com.github.seqware.queryengine.system.Utility.java
/** * Write to output file a tab separated key value file represented by map * * @param outputFile a {@link java.io.File} object. * @param map a {@link java.util.Map} object. *///from www . j a va 2 s . c om public static void writeKeyValueFile(File outputFile, Map<String, String> map) { if (outputFile != null) { try { PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(outputFile))); for (Map.Entry<String, String> e : map.entrySet()) { out.println(e.getKey() + "\t" + e.getValue()); Logger.getLogger(FeatureImporter.class.getName()) .info("Writing " + e.getKey() + " " + e.getValue() + " file"); } out.close(); } catch (IOException ex) { Logger.getLogger(FeatureImporter.class.getName()).fatal("Could not write to output file"); } } }
From source file:net.ontopia.persistence.rdbms.DatabaseProjectReader.java
public static void saveProject(Project project, String filename, String encoding) throws IOException, SAXException { PrintWriter print = new PrintWriter(new FileWriter(filename)); saveProject(project, new PrettyPrinter(print, encoding)); print.close(); }
From source file:com.jolbox.benchmark.BenchmarkLaunch.java
/** * @param title /*from w w w . j ava 2 s .c om*/ * @param filename * @param results * @throws IOException */ private static void plotBarGraph(String title, String filename, long[] results) throws IOException { String fname = System.getProperty("java.io.tmpdir") + File.separator + filename; PrintWriter out = new PrintWriter(new FileWriter(fname + ".txt")); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (ConnectionPoolType poolType : ConnectionPoolType.values()) { dataset.setValue(results[poolType.ordinal()], "ms", poolType); out.println(results[poolType.ordinal()] + "," + poolType); } out.close(); JFreeChart chart = ChartFactory.createBarChart(title, "Connection Pool", "Time (ms)", dataset, PlotOrientation.VERTICAL, false, true, false); try { ChartUtilities.saveChartAsPNG(new File(fname), chart, 1024, 768); System.out.println("******* Saved chart to: " + fname); } catch (IOException e) { e.printStackTrace(); System.err.println("Problem occurred creating chart."); } }