List of usage examples for java.io PrintWriter write
public void write(String s)
From source file:edu.cornell.med.icb.goby.modes.AggregatePeaksByRPKMDifferenceMode.java
public static void writeRPKM(final String outputFileName, final ObjectList<AnnotationRPKM> annotationList, final boolean append) { PrintWriter writer = null; final File outputFile = new File(outputFileName); try {/* www . j a v a 2 s. c om*/ if (!outputFile.exists()) { writer = new PrintWriter(outputFile); // Write the file header writer.write( "Chromosome_Name\tStrand\tPrimary_ID\tSecondary_ID\tTranscript_Start\tTranscript_End\tAverage_RPKM\n"); } else { writer = new PrintWriter(new FileOutputStream(outputFile, append)); } final ObjectListIterator<AnnotationRPKM> annotIterator = annotationList.listIterator(); while (annotIterator.hasNext()) { final AnnotationRPKM annotation = annotIterator.next(); annotation.write(writer); } } catch (FileNotFoundException fnfe) { System.err.println("Caught exception in writeAnnotations: " + fnfe.getMessage()); System.exit(1); } finally { IOUtils.closeQuietly(writer); } }
From source file:edu.cornell.med.icb.goby.modes.AggregatePeaksByRPKMDifferenceMode.java
public static void writeAnnotations(final String outputFileName, final ObjectList<Annotation> annotationList, final boolean append) { PrintWriter writer = null; final File outputFile = new File(outputFileName); try {// w w w . j a v a 2s. c om if (!outputFile.exists()) { writer = new PrintWriter(outputFile); // Write the file header writer.write( "Chromosome_Name\tStrand\tPrimary_ID\tSecondary_ID\tTranscript_Start\tTranscript_End\n"); } else { writer = new PrintWriter(new FileOutputStream(outputFile, append)); } final ObjectListIterator<Annotation> annotIterator = annotationList.listIterator(); while (annotIterator.hasNext()) { final Annotation annotation = annotIterator.next(); annotation.write(writer); } } catch (FileNotFoundException fnfe) { System.err.println("Caught exception in writeAnnotations: " + fnfe.getMessage()); System.exit(1); } finally { IOUtils.closeQuietly(writer); } }
From source file:de.xwic.appkit.core.remote.server.RemoteDataAccessServlet.java
/** * @param pwOut/*from ww w . jav a 2 s .c o m*/ */ public static void printResponse(final PrintWriter pwOut, final String response) { Document docResponse = DocumentFactory.getInstance().createDocument(); Element rootResponse = docResponse.addElement(ELM_RESPONSE); rootResponse.addAttribute(PARAM_VALUE, response); pwOut.write(docResponse.asXML()); }
From source file:at.tuwien.ifs.somtoolbox.data.InputDataWriter.java
public static void writeInputDatumToFile(PrintWriter writer, String label, DoubleMatrix1D vector) throws IOException { for (int i = 0; i < vector.size(); i++) { if (!Double.isNaN(vector.get(i))) { writer.write(vector.get(i) + " "); } else {// w w w . j a v a2 s . co m writer.write("? "); } } writer.println(label); }
From source file:at.tuwien.ifs.somtoolbox.data.InputDataWriter.java
/** Writes the class information to a file in SOMLib format. */ public static void writeAsSOMLib(SOMLibClassInformation classInfo, String fileName) throws IOException, SOMLibFileFormatException { PrintWriter writer = FileUtils.openFileForWriting("SOMLib class info", fileName); writer.println("$TYPE class_information"); writer.println("$NUM_CLASSES " + classInfo.numClasses()); writer.write("$CLASS_NAMES "); for (int i = 0; i < classInfo.numClasses(); i++) { writer.write(classInfo.getClassName(i)); if (i + 1 < classInfo.numClasses()) { writer.write(" "); }//from w w w . j a v a 2 s . c o m } writer.println(); writer.println("$XDIM 2"); writer.println("$YDIM " + classInfo.numData); for (String element : classInfo.getDataNames()) { writer.println(element + " " + classInfo.getClassName(element)); } writer.flush(); writer.close(); }
From source file:TrainLogistic.java
private static void saveTo(FileOutputStream modelOutput, OnlineLogisticRegression lr) { PrintWriter w = new PrintWriter(new OutputStreamWriter(modelOutput)); String str = new String(" "); //System.out.printf("%d columns\n",lr.getBeta().numCols()); System.out.printf("Now, writing file...\n"); for (int column = 0; column < lr.getBeta().numCols(); column++) { //System.out.printf("%f, ", lr.getBeta().get(0, column)); str = java.lang.String.format("%f\n", lr.getBeta().get(0, column)); w.write(str); w.flush();//from w w w.j a va 2 s. c o m } w.close(); }
From source file:eu.annocultor.converters.europeana.EuropeanaSolrDocumentTagger.java
public static void start(String solrServerFrom, String solrServerTo, String query, int start) throws MalformedURLException, Exception { Environment environment = new EnvironmentImpl(); PrintWriter log = new PrintWriter( new FileWriter(new File(environment.getAnnoCultorHome(), "enrichment.log"))); try {// ww w . ja v a 2 s .c o m EuropeanaSolrDocumentTagger tagger = new EuropeanaSolrDocumentTagger(query, solrServerFrom, solrServerTo, start, log); tagger.init("Europeana"); if (start == 0) { tagger.clearDestination(query); } tagger.tag(); tagger.report(); ReportPresenter.generateReport(environment.getAnnoCultorHome()); } catch (Exception e) { e.printStackTrace(new PrintWriter(log)); } finally { log.write("SEMANTIC ENRICHMENT COMPLETED"); log.flush(); log.close(); } }
From source file:controllers.IndexServlet.java
private static void Track(HttpServletRequest request, HttpServletResponse response, PrintWriter writer) { String userAddress = request.getParameter("userAddress"); String fileName = request.getParameter("fileName"); String storagePath = DocumentManager.StoragePath(fileName, userAddress); String body = ""; try {//from w ww .j a v a 2 s.com Scanner scanner = new Scanner(request.getInputStream()).useDelimiter("\\A"); body = scanner.hasNext() ? scanner.next() : ""; } catch (Exception ex) { writer.write("get request.getInputStream error:" + ex.getMessage()); return; } if (body.isEmpty()) { writer.write("empty request.getInputStream"); return; } JSONParser parser = new JSONParser(); JSONObject jsonObj; try { Object obj = parser.parse(body); jsonObj = (JSONObject) obj; } catch (Exception ex) { writer.write("JSONParser.parse error:" + ex.getMessage()); return; } long status = (long) jsonObj.get("status"); if (status == 2 || status == 3)//MustSave, Corrupted { String downloadUri = (String) jsonObj.get("url"); int saved = 1; try { URL url = new URL(downloadUri); java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection(); InputStream stream = connection.getInputStream(); if (stream == null) { throw new Exception("Stream is null"); } File savedFile = new File(storagePath); try (FileOutputStream out = new FileOutputStream(savedFile)) { int read; final byte[] bytes = new byte[1024]; while ((read = stream.read(bytes)) != -1) { out.write(bytes, 0, read); } out.flush(); } connection.disconnect(); } catch (Exception ex) { saved = 0; } } writer.write("{\"error\":0}"); }
From source file:org.apache.asterix.api.http.server.ResultUtil.java
public static void apiErrorHandler(PrintWriter out, Exception e) { int errorCode = 99; if (e instanceof ParseException) { errorCode = 2;/*from w w w. j av a 2 s .c om*/ } else if (e instanceof AlgebricksException) { errorCode = 3; } else if (e instanceof HyracksDataException) { errorCode = 4; } ObjectNode errorResp = ResultUtil.getErrorResponse(errorCode, extractErrorMessage(e), extractErrorSummary(e), extractFullStackTrace(e)); out.write(errorResp.toString()); }
From source file:edu.uci.ics.asterix.result.ResultUtils.java
public static void apiErrorHandler(PrintWriter out, Exception e) { int errorCode = 99; if (e instanceof ParseException) { errorCode = 2;//from w ww. j av a 2 s. c om } else if (e instanceof AlgebricksException) { errorCode = 3; } else if (e instanceof HyracksDataException) { errorCode = 4; } JSONObject errorResp = ResultUtils.getErrorResponse(errorCode, extractErrorMessage(e), extractErrorSummary(e), extractFullStackTrace(e)); out.write(errorResp.toString()); }