List of usage examples for java.io PrintWriter println
public void println(Object x)
From source file:com.betfair.tornjak.monitor.service.InOutServiceMonitor.java
protected void writeLine(String s, File f) throws FileNotFoundException { PrintWriter pw = new PrintWriter(f); pw.println(s); pw.close();/* w w w . j ava 2 s .c o m*/ }
From source file:com.taobao.lottery.web.app1.module.screen.simple.Count.java
public void execute(@Param("to") int toNumber) throws Exception { // buffering,???? brc.setBuffering(false);// w ww .j a va2s . c o m // content type,??charset,charset response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println(" <title>Count to " + toNumber + "</title>"); out.println("</head>"); out.println("<body>"); for (int i = 1; i <= toNumber; i++) { for (int j = 0; j < 10000; j++) { out.print(i); } out.println(); out.flush(); // ??? Thread.sleep(1000); // ?1, } out.println("</body>"); out.println("</html>"); }
From source file:de.tudarmstadt.tk.statistics.importer.ExternalResultsReader.java
public static void readMUGCTrainTest(String filePath) { String outFileName = "AggregatedTrainTest.csv"; logger.log(Level.INFO, String.format("Importing data from directory %s.", filePath)); // Method requires input directory. Check this condition. File directory = new File(filePath); if (directory.isDirectory()) { System.err.println("Please specify a file. Aborting."); return;/*from ww w . j a v a 2s . c o m*/ } //Empty previous output file, if there was one File outputFile = new File(directory.getParentFile(), outFileName); if (outputFile.exists()) { outputFile.delete(); } try { String header = "Train;Test;Classifier;FeatureSet;Measure;Value"; PrintWriter out = new PrintWriter(new FileWriter(outputFile, true)); out.println(header); out.close(); } catch (IOException e) { System.err.println("Error while writing aggregated Train-Test file."); e.printStackTrace(); } ArrayList<String> outputRows = new ArrayList<String>(); // iterate all rows List<String[]> inputRowsFirstFile = new ArrayList<>(); inputRowsFirstFile = readAndCheckCSV(filePath, ';'); // first: order by train set ArrayList<ExternalResults> extResults = new ArrayList<>(); for (int i = 0; i < inputRowsFirstFile.size(); i++) { ExternalResults results = new ExternalResults(); // identify current train/test split String[] datasetNames = inputRowsFirstFile.get(i)[0].replace("TRAIN:", "").replace("TEST:", "") .split(","); results.trainSetName = datasetNames[0].replace(" ", ""); results.testSetName = datasetNames[1].replace(" ", ""); // set classifier name results.classifierParameters = inputRowsFirstFile.get(i)[1]; // read feature set results.featureSetName = inputRowsFirstFile.get(i)[2]; // read classification results results.recall = Double.parseDouble(inputRowsFirstFile.get(i)[3]); results.fMeasure = Double.parseDouble(inputRowsFirstFile.get(i)[4]); results.precision = Double.parseDouble(inputRowsFirstFile.get(i)[5]); results.accuracy = Double.parseDouble(inputRowsFirstFile.get(i)[10]) / 100; extResults.add(results); } HashMap<String, ArrayList<ExternalResults>> extResultsByTrainTestFeature = new HashMap<>(); // order by test set for (ExternalResults result : extResults) { String IdKey = result.trainSetName + result.testSetName + result.featureSetName; if (extResultsByTrainTestFeature.containsKey(IdKey)) { extResultsByTrainTestFeature.get(IdKey).add(result); } else { extResultsByTrainTestFeature.put(IdKey, new ArrayList<ExternalResults>()); extResultsByTrainTestFeature.get(IdKey).add(result); } } ArrayList<ExternalResults> aggregatedResults = new ArrayList<>(); // aggregate results or keep as are for (Entry<String, ArrayList<ExternalResults>> trainTestSplit : extResultsByTrainTestFeature.entrySet()) { ExternalResults aggrResult = new ExternalResults(); double recall = 0; double fMeasure = 0; double precision = 0; double accuracy = 0; int nrClassifiers = 0; // for all entries that are from the same train/test split and use the same feature set -> aggregate results for (ExternalResults result : trainTestSplit.getValue()) { aggrResult.testSetName = result.testSetName; aggrResult.trainSetName = result.trainSetName; aggrResult.classifierParameters = result.classifierParameters; aggrResult.featureSetName = result.featureSetName; recall += result.recall; fMeasure += result.fMeasure; precision += result.precision; accuracy += result.accuracy; nrClassifiers++; } aggrResult.accuracy = (accuracy / nrClassifiers); aggrResult.fMeasure = (fMeasure / nrClassifiers); aggrResult.recall = (recall / nrClassifiers); aggrResult.precision = (precision / nrClassifiers); aggregatedResults.add(aggrResult); } // write values of measure for (ExternalResults result : aggregatedResults) { String outputRow = String.format("%s;%s;%s;%s;%s;%s", result.trainSetName, result.testSetName, "0", result.featureSetName, "Percent Correct", result.accuracy); outputRows.add(outputRow); outputRow = String.format("%s;%s;%s;%s;%s;%s", result.trainSetName, result.testSetName, "0", result.featureSetName, "Weighted Precision", result.precision); outputRows.add(outputRow); outputRow = String.format("%s;%s;%s;%s;%s;%s", result.trainSetName, result.testSetName, "0", result.featureSetName, "Weighted Recall", result.recall); outputRows.add(outputRow); outputRow = String.format("%s;%s;%s;%s;%s;%s", result.trainSetName, result.testSetName, "0", result.featureSetName, "Weighted F-Measure", result.fMeasure); outputRows.add(outputRow); } // Write aggregated data to a new file try { PrintWriter out = new PrintWriter(new FileWriter(outputFile, true)); for (String s : outputRows) { out.println(s); } out.close(); } catch (IOException e) { System.err.println("Error while writing aggregated Train-Test file."); e.printStackTrace(); } logger.log(Level.INFO, String.format("Finished import. The aggregated data was written to %s.", outFileName)); }
From source file:TimeServer.java
public void run() { Socket client = null;/*from ww w . ja v a 2 s. co m*/ while (true) { if (sock == null) return; try { client = sock.accept(); BufferedOutputStream bos = new BufferedOutputStream(client.getOutputStream()); PrintWriter os = new PrintWriter(bos, false); String outLine; Date now = new Date(); os.println(now); os.flush(); os.close(); client.close(); } catch (IOException e) { System.out.println("Error: couldn't connect to client."); System.exit(1); } } }
From source file:com.nginious.http.serialize.JsonObjectCollectionSerializer.java
/** * Serializes the specified collection and writes it using the specified writer. * //w ww. j a v a 2s . c o m * @param writer the given writer * @param items the given collection of bean elements to serialize * @throws SerializerException if unable to serialize collection */ public void serialize(PrintWriter writer, Collection<?> items) throws SerializerException { writer.println(serialize(items)); }
From source file:ThreadedEchoServer.java
public void run() { try {//from w w w.ja va 2s . c o m try { InputStream inStream = incoming.getInputStream(); OutputStream outStream = incoming.getOutputStream(); Scanner in = new Scanner(inStream); PrintWriter out = new PrintWriter(outStream, true /* autoFlush */); out.println("Hello! Enter BYE to exit."); // echo client input boolean done = false; while (!done && in.hasNextLine()) { String line = in.nextLine(); out.println("Echo: " + line); if (line.trim().equals("BYE")) done = true; } } finally { incoming.close(); } } catch (IOException e) { e.printStackTrace(); } }
From source file:com.adaptris.core.services.exception.SimpleExceptionReport.java
public Document create(Exception e, String workflow, String location) throws Exception { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw, true); pw.println("<" + elementName() + ">"); pw.println("<![CDATA["); e.printStackTrace(pw);/*from ww w.j av a 2 s . c om*/ pw.println("]]>"); pw.println("</" + elementName() + ">"); pw.close(); logR.trace("Created Exception Report " + sw.toString()); return createDocument(sw.toString(), (DocumentBuilderFactoryBuilder) null); }
From source file:com.rabidgremlin.legalbeagle.report.TsvReportWriter.java
public void generateReport(String output, Report report) throws Exception { log.info("Writing report to {}...", output); PrintWriter out = new PrintWriter(new File(output)); out.println("File\tStatus\tDescription\tLicense(s)\tError"); for (ReportItem reportItem : report.getReportItems()) { out.print(reportItem.getFile().getAbsolutePath()); out.print("\t"); out.print(reportItem.getReportItemStatus()); out.print("\t"); if (reportItem.getDescription() != null) { out.print(reportItem.getDescription()); }/* w w w. ja v a 2 s. c o m*/ out.print("\t"); out.print(StringUtils.join(reportItem.getLicenses(), "; ")); out.print("\t"); if (reportItem.getError() != null) { out.print(reportItem.getError()); } out.println(); } out.flush(); out.close(); }
From source file:$.Count.java
public void execute(@Param("to") int toNumber) throws Exception { // buffering???? brc.setBuffering(false);/* w w w . ja v a 2s . c om*/ // content type??charsetcharset response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println(" <title>Count to " + toNumber + "</title>"); out.println("</head>"); out.println("<body>"); for (int i = 1; i <= toNumber; i++) { for (int j = 0; j < 10000; j++) { out.print(i); } out.println(); out.flush(); // ??? Thread.sleep(1000); // ?1 } out.println("</body>"); out.println("</html>"); }
From source file:com.shin1ogawa.appengine.marketplace.controller.ConfigureForAdminController.java
@Override protected Navigation run() throws Exception { response.setContentType("text/html"); response.setCharacterEncoding("utf-8"); PrintWriter w = response.getWriter(); w.println("<html><head><title>appengine-gdata-example</title></head><body>"); w.println("<h1>appengine-gdata-example</h1>"); w.println("<p>from 'Additional Configuration' at cpanel</p>"); w.println(/*w w w. j a va2s. c o m*/ "<p><a target=\"_blank\" href=\"http://github.com/shin1ogawa/appengine-marketplace-example/blob/master/src/main/java/com/shin1ogawa/appengine/marketplace/controller/ConfigureForAdminController.java\">"); w.println("source code</a></p>"); w.println(Utils.getHtmlForDebug(request)); w.print("<a href=\"https://www.google.com/a/cpanel/"); w.print(domain); w.print("/PikeplaceAppSettings?appId="); w.print(Configuration.get().getMarketplaceAppId()); w.println("&licenseNamespace=PACKAGE_GAIAID\">"); w.println("complete configuration and back to apps cpanel.</a>"); w.println("</body></html>"); response.flushBuffer(); return null; }