List of usage examples for java.io FileWriter append
@Override public Writer append(CharSequence csq) throws IOException
From source file:org.kurento.test.base.BrowserTest.java
public void writeCSV(String outputFile, Table<Integer, Integer, String> resultTable) throws IOException { FileWriter writer = new FileWriter(outputFile); for (Integer row : resultTable.rowKeySet()) { boolean first = true; for (Integer column : resultTable.columnKeySet()) { if (!first) { writer.append(','); }/*from www .j a va 2 s .co m*/ String value = resultTable.get(row, column); if (value != null) { writer.append(value); } first = false; } writer.append('\n'); } writer.flush(); writer.close(); }
From source file:de.pangaea.fixo3.CreateBrowser.java
private void run() throws IOException { StringBuffer observatories = new StringBuffer(); observatories.append("<!doctype html>"); observatories.append("<html>"); observatories.append("<head>"); observatories.append("<meta charset=\"utf-8\">"); observatories.append("<link rel=\"stylesheet\" href=\"main.css\">"); observatories.append("</head>"); observatories.append("<body>"); String q1 = FileUtils.readFileToString(new File("src/main/resources/sparql/browser-query1.rq")); QueryExecution qe1 = QueryExecutionFactory.sparqlService(service, q1); ResultSet rs1 = qe1.execSelect(); observatories.append("<div id=\"main\">"); observatories.append("<h1>FixO3 Observatories</h1>"); int openModalCount = 0; while (rs1.hasNext()) { QuerySolution qs1 = rs1.next();//from w ww . j av a 2 s . c om String obsId = qs1.getResource("obsId").getURI(); String obsLocalName = qs1.getResource("obsId").getLocalName(); String obsLabel = qs1.getLiteral("obsLabel").getLexicalForm(); String obsTitle = qs1.getLiteral("obsTitle").getLexicalForm(); String obsComment = qs1.getLiteral("obsComment").getLexicalForm(); String obsLocation = qs1.getLiteral("obsLocation").getLexicalForm(); Point point = new Point(obsLocation); observatories.append("<div class=\"platform\">"); observatories.append("<a href=\"" + obsLocalName + ".html\">"); observatories.append("<strong title=\"" + obsId + "\">"); observatories.append(obsLabel); observatories.append("</strong>"); observatories.append("</a>"); observatories.append("</br>"); observatories.append(obsTitle); observatories.append("</div>"); StringBuffer observatory = new StringBuffer(); observatory.append("<!doctype html>"); observatory.append("<html>"); observatory.append("<head>"); observatory.append("<meta charset=\"utf-8\">"); observatory.append("<link rel=\"stylesheet\" href=\"main.css\">"); observatory.append( "<script src=\"https://maps.googleapis.com/maps/api/js?key=AIzaSyCeLgOdZllXtTwtjlmuvbbw5Z8AeSFYwjE&signed_in=true\"></script>"); observatory.append("<script src=\"https://cdn.plot.ly/plotly-latest.min.js\"></script>"); observatory.append("</head>"); observatory.append("<body>"); observatory.append("<div id=\"main\">"); observatory.append("<section id=\"header\">"); observatory.append("<h1>"); observatory.append(obsLabel); observatory.append("</h1>"); observatory.append("<h2>"); observatory.append(obsTitle); observatory.append("</h2>"); observatory.append("</section>"); observatory.append("<section id=\"content\">"); observatory.append("<div id=\"description\">"); observatory.append(obsComment); observatory.append("</div>"); observatory.append("<div id=\"location\">"); observatory.append("<div id=\"map\"></div>"); observatory.append("<script>"); observatory.append("var coords = {lat: " + point.getLat() + ", lng: " + point.getLon() + "};"); observatory.append("new google.maps.Marker({"); observatory.append("position: coords,"); observatory.append("map: new google.maps.Map(document.getElementById('map'), {"); observatory.append("zoom: 4,"); observatory.append("center: coords"); observatory.append("})"); observatory.append("});"); observatory.append("</script>"); observatory.append("</div>"); observatory.append("</section>"); observatory.append("<br/>"); String q1c = FileUtils.readFileToString(new File("src/main/resources/sparql/browser-query1c.rq")) .replaceAll("\\?obsId", obsId.replaceAll("http://fixo3.eu/vocab/", "fixo3:")); QueryExecution qe1c = QueryExecutionFactory.sparqlService(service, q1c); Model m1c = qe1c.execConstruct(); StringWriter sw1c = new StringWriter(); m1c.write(sw1c, "Turtle"); m1c.close(); observatory.append("<div id=\"action\">"); observatory.append("<a href=\"#openModal" + (++openModalCount) + "\">Show RDF</a>"); observatory.append("</div>"); observatory.append("<div id=\"openModal" + (openModalCount) + "\" class=\"modalDialogPopUp\">"); observatory.append("<div>"); observatory.append("<a href=\"#close\" title=\"Close\" class=\"close\">X</a>"); observatory.append(sw1c.toString().replaceAll("<", "<").replaceAll(">", ">") .replaceAll(" ", " ").replaceAll("\n", "<br/>")); observatory.append("</div>"); observatory.append("</div>"); observatory.append("<div id=\"action\">"); observatory.append("<a href=\"#openModal" + (++openModalCount) + "\">Show SPARQL</a>"); observatory.append("</div>"); observatory.append("<div id=\"openModal" + (openModalCount) + "\" class=\"modalDialogPopUp\">"); observatory.append("<div>"); observatory.append("<a href=\"#close\" title=\"Close\" class=\"close\">X</a>"); observatory.append(q1.replaceAll("SELECT\\s\\?obsId", "SELECT") .replaceAll("\\?obsId", obsId.replaceAll("http://fixo3.eu/vocab/", "fixo3:")) .replaceAll("<", "<").replaceAll(">", ">").replaceAll(" ", " ") .replaceAll("\n", "<br/>")); observatory.append("</div>"); observatory.append("</div>"); String q2 = FileUtils.readFileToString(new File("src/main/resources/sparql/browser-query2.rq")) .replaceAll("OBS_ID", obsId.replaceAll("http://fixo3.eu/vocab/", "fixo3:")); QueryExecution qe2 = QueryExecutionFactory.sparqlService(service, q2); ResultSet rs2 = qe2.execSelect(); observatory.append("<div id=\"sensors\">"); if (rs2.hasNext()) { observatory.append("<h3>Sensors</h3>"); } int plotCount = 0; while (rs2.hasNext()) { QuerySolution qs2 = rs2.next(); String sensorId = qs2.getResource("sensorId").getURI(); String sensorLabel = qs2.getLiteral("sensorLabel").getLexicalForm(); String observedPropertyId = qs2.getResource("propertyId").getURI(); String observedPropertyLabel = qs2.getLiteral("propertyLabel").getLexicalForm(); String featureId = qs2.getResource("featureId").getURI(); String featureLabel = qs2.getLiteral("featureLabel").getLexicalForm(); String stimulusId = qs2.getResource("stimulusId").getURI(); String stimulusLabel = qs2.getLiteral("stimulusLabel").getLexicalForm(); observatory.append("<div class=\"sensor\">"); observatory.append("<h4>"); observatory.append(sensorLabel); observatory.append("</h4>"); observatory.append("<div>"); observatory.append("<table>"); observatory.append("<tr>"); observatory.append("<td>"); observatory.append("<i>Observed Property</i>"); observatory.append("</td>"); observatory.append("<td>"); observatory.append(observedPropertyLabel); observatory.append("</td>"); observatory.append("</tr>"); observatory.append("<tr>"); observatory.append("<td>"); observatory.append("<i>Monitored Feature</i>"); observatory.append("</td>"); observatory.append("<td>"); observatory.append(featureLabel); observatory.append("</td>"); observatory.append("</tr>"); observatory.append("<tr>"); observatory.append("<td>"); observatory.append("<i>Detected Stimulus</i>"); observatory.append("</td>"); observatory.append("<td>"); observatory.append(stimulusLabel); observatory.append("</td>"); observatory.append("</tr>"); observatory.append("</table>"); observatory.append("<br/>"); String q2c = FileUtils.readFileToString(new File("src/main/resources/sparql/browser-query2c.rq")) .replaceAll("OBS_ID", obsId.replaceAll("http://fixo3.eu/vocab/", "fixo3:")) .replaceAll("\\?sensorId", sensorId.replaceAll("http://fixo3.eu/vocab/", "fixo3:")); QueryExecution qe2c = QueryExecutionFactory.sparqlService(service, q2c); Model m2c = qe2c.execConstruct(); StringWriter sw2c = new StringWriter(); m2c.write(sw2c, "Turtle"); m2c.close(); observatory.append("<div id=\"action\">"); observatory.append("<a href=\"#openModal" + (++openModalCount) + "\">Show RDF</a>"); observatory.append("</div>"); observatory.append("<div id=\"openModal" + (openModalCount) + "\" class=\"modalDialogPopUp\">"); observatory.append("<div>"); observatory.append("<a href=\"#close\" title=\"Close\" class=\"close\">X</a>"); observatory.append(sw2c.toString().replaceAll("<", "<").replaceAll(">", ">") .replaceAll(" ", " ").replaceAll("\n", "<br/>")); observatory.append("</div>"); observatory.append("</div>"); observatory.append("<div id=\"action\">"); observatory.append("<a href=\"#openModal" + (++openModalCount) + "\">Show SPARQL</a>"); observatory.append("</div>"); observatory.append("<div id=\"openModal" + (openModalCount) + "\" class=\"modalDialogPopUp\">"); observatory.append("<div>"); observatory.append("<a href=\"#close\" title=\"Close\" class=\"close\">X</a>"); observatory.append(q2.replaceAll("SELECT\\s\\?sensorId", "SELECT") .replaceAll("\\?sensorId", sensorId.replaceAll("http://fixo3.eu/vocab/", "fixo3:")) .replaceAll("<", "<").replaceAll(">", ">").replaceAll(" ", " ") .replaceAll("\n", "<br/>")); observatory.append("</div>"); observatory.append("</div>"); observatory.append("<h5>Measurement Capabilities</h5>"); observatory.append("<table>"); String q3 = FileUtils.readFileToString(new File("src/main/resources/sparql/browser-query3.rq")) .replaceAll("SENSOR_ID", sensorId.replaceAll("http://fixo3.eu/vocab/", "fixo3:")); QueryExecution qe3 = QueryExecutionFactory.sparqlService(service, q3); ResultSet rs3 = qe3.execSelect(); while (rs3.hasNext()) { QuerySolution qs3 = rs3.next(); String value = null; String minValue = null; String maxValue = null; String unitId = null; String unitSymbol = null; String propertyLabel = qs3.getLiteral("propertyLabel").getLexicalForm(); if (qs3.getLiteral("value") != null) value = qs3.getLiteral("value").getLexicalForm(); if (qs3.getLiteral("minValue") != null) minValue = qs3.getLiteral("minValue").getLexicalForm(); if (qs3.getLiteral("maxValue") != null) maxValue = qs3.getLiteral("maxValue").getLexicalForm(); if (qs3.getResource("unitId") != null) unitId = qs3.getResource("unitId").getURI(); if (qs3.getLiteral("unitSymbol") != null) unitSymbol = qs3.getLiteral("unitSymbol").getLexicalForm(); observatory.append("<tr>"); observatory.append("<td>"); observatory.append("<i>" + propertyLabel + "</i>"); observatory.append("</td>"); observatory.append("<td>"); if (value != null) { observatory.append(value); } else if (minValue != null && maxValue != null) { observatory.append(minValue + " - " + maxValue); } if (unitId != null && unitSymbol != null) { observatory.append(" "); observatory.append("<a href=\"#openModal" + (++openModalCount) + "\">"); observatory.append(unitSymbol); observatory.append("</a>"); observatory.append("<div id=\"openModal" + (openModalCount) + "\" class=\"modalDialog\">"); observatory.append("<div>"); observatory.append("<a href=\"#close\" title=\"Close\" class=\"close\">X</a>"); QueryExecution qe4 = QueryExecutionFactory.sparqlService(service, FileUtils.readFileToString(new File("src/main/resources/sparql/browser-query4.rq")) .replaceAll("UNIT_ID", unitId)); ResultSet rs4 = qe4.execSelect(); observatory.append("<h2>"); observatory.append(unitId.replace(unit, "unit:")); observatory.append("</h2>"); observatory.append("<a href=\"" + unitId + "\">" + unitId + "</a>"); observatory.append("<div id=\"unit\">"); observatory.append("<table>"); while (rs4.hasNext()) { QuerySolution qs4 = rs4.next(); observatory.append("<tr>"); observatory.append("<td>"); observatory.append(qs4.getResource("property").getURI().replace(qudt, "qudt:") .replace(rdf, "rdf:")); observatory.append("</td>"); observatory.append("<td>"); if (qs4.get("object").isResource()) observatory.append(qs4.getResource("object").getURI().replace(qudt, "qudt:")); else observatory.append(qs4.getLiteral("object").toString().replace(xsd, "xsd:")); observatory.append("</td>"); observatory.append("</tr>"); } observatory.append("</table>"); observatory.append("</div>"); observatory.append("</div>"); observatory.append("</div>"); } observatory.append("</td>"); observatory.append("</tr>"); } qe3.close(); observatory.append("</table>"); observatory.append("</div>"); observatory.append("<br/>"); String q3c = FileUtils.readFileToString(new File("src/main/resources/sparql/browser-query3c.rq")) .replaceAll("SENSOR_ID", sensorId.replaceAll("http://fixo3.eu/vocab/", "fixo3:")); QueryExecution qe3c = QueryExecutionFactory.sparqlService(service, q3c); Model m3c = qe3c.execConstruct(); StringWriter sw3c = new StringWriter(); m3c.write(sw3c, "Turtle"); m3c.close(); observatory.append("<div id=\"action\">"); observatory.append("<a href=\"#openModal" + (++openModalCount) + "\">Show RDF</a>"); observatory.append("</div>"); observatory.append("<div id=\"openModal" + (openModalCount) + "\" class=\"modalDialogPopUp\">"); observatory.append("<div>"); observatory.append("<a href=\"#close\" title=\"Close\" class=\"close\">X</a>"); observatory.append(sw3c.toString().replaceAll("<", "<").replaceAll(">", ">") .replaceAll(" ", " ").replaceAll("\n", "<br/>")); observatory.append("</div>"); observatory.append("</div>"); observatory.append("<div id=\"action\">"); observatory.append("<a href=\"#openModal" + (++openModalCount) + "\">Show SPARQL</a>"); observatory.append("</div>"); observatory.append("<div id=\"openModal" + (openModalCount) + "\" class=\"modalDialogPopUp\">"); observatory.append("<div>"); observatory.append("<a href=\"#close\" title=\"Close\" class=\"close\">X</a>"); observatory.append(q3.replaceAll("<", "<").replaceAll(">", ">") .replaceAll(" ", " ").replaceAll("\n", "<br/>")); observatory.append("</div>"); observatory.append("</div>"); String q5 = FileUtils.readFileToString(new File("src/main/resources/sparql/browser-query5.rq")) .replaceAll("SENSOR_ID", sensorId.replaceAll("http://fixo3.eu/vocab/", "fixo3:")) .replaceAll("PROPERTY_ID", observedPropertyId.replaceAll("http://esonetyellowpages.com/vocab/", "eyp:")) .replaceAll("FEATURE_ID", featureId.replaceAll("http://esonetyellowpages.com/vocab/", "eyp:")) .replaceAll("STIMULUS_ID", stimulusId.replaceAll("http://esonetyellowpages.com/vocab/", "eyp:")); QueryExecution qe5 = QueryExecutionFactory.sparqlService(service, q5); ResultSet rs5 = qe5.execSelect(); if (!rs5.hasNext()) continue; List<String> times = new ArrayList<String>(); List<String> values = new ArrayList<String>(); while (rs5.hasNext()) { QuerySolution qs = rs5.next(); String time = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss").print(ISODateTimeFormat .dateTime().withOffsetParsed().parseDateTime(qs.getLiteral("time").getLexicalForm())); String value = qs.getLiteral("value").getLexicalForm(); times.add(time); values.add(value); } observatory.append("<div id=\"plot" + plotCount + "\" style=\"width:800px;height:600px;\"></div>"); observatory.append("<script>"); observatory.append("var data = ["); observatory.append("{"); observatory.append("x: ["); boolean first = true; for (String time : times) { if (!first) observatory.append(","); observatory.append("'" + time + "'"); first = false; } observatory.append("],"); observatory.append("y: ["); first = true; for (String value : values) { if (!first) observatory.append(","); observatory.append(value); first = false; } observatory.append("],"); observatory.append("type: 'scatter'"); observatory.append("}"); observatory.append("];"); observatory.append("Plotly.newPlot('plot" + plotCount + "', data);"); observatory.append("</script>"); observatory.append("</div>"); plotCount++; String q5c = FileUtils.readFileToString(new File("src/main/resources/sparql/browser-query5c.rq")) .replaceAll("SENSOR_ID", sensorId.replaceAll("http://fixo3.eu/vocab/", "fixo3:")) .replaceAll("PROPERTY_ID", observedPropertyId.replaceAll("http://esonetyellowpages.com/vocab/", "eyp:")) .replaceAll("FEATURE_ID", featureId.replaceAll("http://esonetyellowpages.com/vocab/", "eyp:")) .replaceAll("STIMULUS_ID", stimulusId.replaceAll("http://esonetyellowpages.com/vocab/", "eyp:")); QueryExecution qe5c = QueryExecutionFactory.sparqlService(service, q5c); Model m5c = qe5c.execConstruct(); StringWriter sw5c = new StringWriter(); m5c.write(sw5c, "Turtle"); m5c.close(); observatory.append("<div id=\"action\">"); observatory.append("<a href=\"#openModal" + (++openModalCount) + "\">Show RDF</a>"); observatory.append("</div>"); observatory.append("<div id=\"openModal" + (openModalCount) + "\" class=\"modalDialogPopUp\">"); observatory.append("<div>"); observatory.append("<a href=\"#close\" title=\"Close\" class=\"close\">X</a>"); observatory.append(sw5c.toString().replaceAll("<", "<").replaceAll(">", ">") .replaceAll(" ", " ").replaceAll("\n", "<br/>")); observatory.append("</div>"); observatory.append("</div>"); observatory.append("<div id=\"action\">"); observatory.append("<a href=\"#openModal" + (++openModalCount) + "\">Show SPARQL</a>"); observatory.append("</div>"); observatory.append("<div id=\"openModal" + (openModalCount) + "\" class=\"modalDialogPopUp\">"); observatory.append("<div>"); observatory.append("<a href=\"#close\" title=\"Close\" class=\"close\">X</a>"); observatory.append(q5.replaceAll("<", "<").replaceAll(">", ">") .replaceAll(" ", " ").replaceAll("\n", "<br/>")); observatory.append("</div>"); observatory.append("</div>"); } qe2.close(); observatory.append("</div>"); observatory.append("</div>"); observatory.append("</body>"); observatory.append("</html>"); FileWriter fw = new FileWriter(new File("browser/" + obsLocalName + ".html")); fw.append(observatory); fw.close(); } qe1.close(); observatories.append("<div id=\"action\">"); observatories.append("<a href=\"" + endpoint + "\">Endpoint</a>"); observatories.append("</div>"); String q0c = FileUtils.readFileToString(new File("src/main/resources/sparql/browser-query0c.rq")); QueryExecution qe0c = QueryExecutionFactory.sparqlService(service, q0c); Model m0c = qe0c.execConstruct(); StringWriter sw0c = new StringWriter(); m0c.write(sw0c, "Turtle"); m0c.close(); observatories.append("<div id=\"action\">"); observatories.append("<a href=\"#openModal" + (++openModalCount) + "\">Show RDF</a>"); observatories.append("</div>"); observatories.append("<div id=\"openModal" + (openModalCount) + "\" class=\"modalDialogPopUp\">"); observatories.append("<div>"); observatories.append("<a href=\"#close\" title=\"Close\" class=\"close\">X</a>"); observatories.append(sw0c.toString().replaceAll("<", "<").replaceAll(">", ">") .replaceAll(" ", " ").replaceAll("\n", "<br/>")); observatories.append("</div>"); observatories.append("</div>"); String q0 = FileUtils.readFileToString(new File("src/main/resources/sparql/browser-query0.rq")); observatories.append("<div id=\"action\">"); observatories.append("<a href=\"#openModal" + (++openModalCount) + "\">Show SPARQL</a>"); observatories.append("</div>"); observatories.append("<div id=\"openModal" + (openModalCount) + "\" class=\"modalDialogPopUp\">"); observatories.append("<div>"); observatories.append("<a href=\"#close\" title=\"Close\" class=\"close\">X</a>"); observatories.append(q0.replaceAll("<", "<").replaceAll(">", ">").replaceAll(" ", " ") .replaceAll("\n", "<br/>")); observatories.append("</div>"); observatories.append("</div>"); observatories.append("</div>"); observatories.append("</body>"); observatories.append("</html>"); FileWriter fw = new FileWriter(new File("browser/index.html")); fw.append(observatories); fw.close(); }
From source file:org.kurento.test.base.BrowserTest.java
public void writeCSV(String outputFile, Multimap<String, Object> multimap, boolean orderKeys) throws IOException { FileWriter writer = new FileWriter(outputFile); // Header/* w ww. j a va 2s. com*/ boolean first = true; Set<String> keySet = orderKeys ? new TreeSet<String>(multimap.keySet()) : multimap.keySet(); for (String key : keySet) { if (!first) { writer.append(','); } writer.append(key); first = false; } writer.append('\n'); // Values int i = 0; boolean moreValues; do { moreValues = false; first = true; for (String key : keySet) { Object[] array = multimap.get(key).toArray(); moreValues = i < array.length; if (moreValues) { if (!first) { writer.append(','); } writer.append(array[i].toString()); } first = false; } i++; if (moreValues) { writer.append('\n'); } } while (moreValues); writer.flush(); writer.close(); }
From source file:uk.org.openseizuredetector.SdServer.java
/** * Write data to SD card - writes to data log file unless alarm=true, * in which case writes to alarm log file. *///from w ww . j a v a 2 s . co m public void writeToSD(boolean alarm) { Log.v(TAG, "writeToSD(" + alarm + ")"); Time tnow = new Time(Time.getCurrentTimezone()); tnow.setToNow(); String dateStr = tnow.format("%Y-%m-%d"); // Select filename depending on 'alarm' parameter. String fname; if (alarm) fname = "AlarmLog"; else fname = "DataLog"; fname = fname + "_" + dateStr + ".txt"; // Open output directory on SD Card. if (isExternalStorageWritable()) { try { FileWriter of = new FileWriter(getDataStorageDir().toString() + "/" + fname, true); if (sdData != null) { Log.v(TAG, "writing sdData.toString()"); of.append(sdData.toString() + "\n"); } of.close(); } catch (Exception ex) { Log.e(TAG, "writeAlarmToSD - error " + ex.toString()); } } else { Log.e(TAG, "ERROR - Can not Write to External Folder"); } }
From source file:co.touchlab.squeaky.processor.AnnotationProcessor.java
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { try {//from w w w. ja v a 2 s . c o m return safeProcess(roundEnv); } catch (Exception e) { StringWriter sq = new StringWriter(); PrintWriter printWriter = new PrintWriter(sq); e.printStackTrace(printWriter); File debugOut = new File("/Users/kgalligan/temp/apterror.txt"); try { FileWriter fileWriter = new FileWriter(debugOut); fileWriter.append(sq.toString()); fileWriter.close(); } catch (IOException e1) { // } messager.printMessage(Diagnostic.Kind.ERROR, "(Failed in annotation processing) " + e.getClass().getName() + "/" + e.getMessage() + "\n\n" + sq.toString() + "\n\n"); return true; } }
From source file:com.thoughtworks.selenium.SeleneseTestNgHelperVir.java
/** * Generates the log time CSV file in the target/logs folder. * /*from www . j a v a2 s. c o m*/ */ private void generateTimeLogCSV() { FileWriter writer = null; Logger log = getLog(); try { File logsDir = new File("target" + File.separator + "logs"); if (!logsDir.exists()) { logsDir.mkdir(); } writer = new FileWriter("ExecutionTime.csv"); writer.append(logTimeCSVFileBuilder); writer.flush(); } catch (IOException e) { log.error(e); e.printStackTrace(); } catch (Exception e) { log.error(e); e.printStackTrace(); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:com.opengamma.analytics.financial.provider.curve.MulticurveBuildingDiscountingDiscountEURCommitteeTest.java
@Test(enabled = false) /**/*from ww w . ja v a2 s . co m*/ * Analyzes the shape of the forward curve. */ public void forwardAnalysis() { final MulticurveProviderInterface multicurve = CURVES_PAR_SPREAD_MQ_WITHOUT_TODAY_BLOCK.get(0).getFirst(); final int jump = 1; // final int startIndex = 0; final int nbDate = 500; ZonedDateTime startDate = NOW; final double[] rateDsc = new double[nbDate]; final double[] startTime = new double[nbDate]; try { final FileWriter writer = new FileWriter("dsc-committee.csv"); for (int loopdate = 0; loopdate < nbDate; loopdate++) { startTime[loopdate] = TimeCalculator.getTimeBetween(NOW, startDate); final ZonedDateTime endDate = ScheduleCalculator.getAdjustedDate(startDate, 1, TARGET); final double endTime = TimeCalculator.getTimeBetween(NOW, endDate); final double accrualFactor = EONIA.getDayCount().getDayCountFraction(startDate, endDate); rateDsc[loopdate] = multicurve.getForwardRate(EONIA, startTime[loopdate], endTime, accrualFactor); startDate = ScheduleCalculator.getAdjustedDate(startDate, jump, TARGET); writer.append(0.0 + "," + startTime[loopdate] + "," + rateDsc[loopdate] + "\n"); } writer.flush(); writer.close(); } catch (final IOException e) { e.printStackTrace(); } }
From source file:com.opengamma.analytics.financial.provider.curve.MulticurveBuildingDiscountingDiscountAUDTest.java
@Test(enabled = false) /**// ww w .ja v a 2 s . c o m * Analyzes the shape of the forward curve. */ public void forwardAnalysis() { final MulticurveProviderInterface marketDsc = CURVES_PAR_SPREAD_MQ_WITHOUT_TODAY_BLOCK.get(0).getFirst(); final int jump = 1; final int startIndex = 0; final int nbDate = 2750; ZonedDateTime startDate = ScheduleCalculator.getAdjustedDate(NOW, AUDBB3M.getSpotLag() + startIndex * jump, SYD); final double[] rateDsc = new double[nbDate]; final double[] startTime = new double[nbDate]; try { final FileWriter writer = new FileWriter("fwd-dsc.csv"); for (int loopdate = 0; loopdate < nbDate; loopdate++) { startTime[loopdate] = TimeCalculator.getTimeBetween(NOW, startDate); final ZonedDateTime endDate = ScheduleCalculator.getAdjustedDate(startDate, AUDBB3M, SYD); final double endTime = TimeCalculator.getTimeBetween(NOW, endDate); final double accrualFactor = AUDBB3M.getDayCount().getDayCountFraction(startDate, endDate); rateDsc[loopdate] = marketDsc.getForwardRate(AUDBB3M, startTime[loopdate], endTime, accrualFactor); startDate = ScheduleCalculator.getAdjustedDate(startDate, jump, SYD); writer.append(0.0 + "," + startTime[loopdate] + "," + rateDsc[loopdate] + "\n"); } writer.flush(); writer.close(); } catch (final IOException e) { e.printStackTrace(); } }
From source file:com.opengamma.analytics.financial.provider.curve.MulticurveBuildingDiscountingDiscountEUR3Test.java
@Test(enabled = false) /**/*from www .ja v a2 s . c o m*/ * Analyzes the shape of the forward curve. */ public void forwardAnalysis() { final MulticurveProviderInterface marketDsc = CURVES_PAR_SPREAD_MQ_WITHOUT_TODAY_BLOCK.get(0).getFirst(); final int jump = 1; final int startIndex = 0; final int nbDate = 2750; ZonedDateTime startDate = ScheduleCalculator.getAdjustedDate(NOW, EURIBOR3M.getSpotLag() + startIndex * jump, TARGET); final double[] rateDsc = new double[nbDate]; final double[] startTime = new double[nbDate]; try { final FileWriter writer = new FileWriter("fwd-dsc.csv"); for (int loopdate = 0; loopdate < nbDate; loopdate++) { startTime[loopdate] = TimeCalculator.getTimeBetween(NOW, startDate); final ZonedDateTime endDate = ScheduleCalculator.getAdjustedDate(startDate, EURIBOR3M, TARGET); final double endTime = TimeCalculator.getTimeBetween(NOW, endDate); final double accrualFactor = EURIBOR3M.getDayCount().getDayCountFraction(startDate, endDate); rateDsc[loopdate] = marketDsc.getForwardRate(EURIBOR3M, startTime[loopdate], endTime, accrualFactor); startDate = ScheduleCalculator.getAdjustedDate(startDate, jump, TARGET); writer.append(0.0 + "," + startTime[loopdate] + "," + rateDsc[loopdate] + "\n"); } writer.flush(); writer.close(); } catch (final IOException e) { e.printStackTrace(); } }
From source file:com.opengamma.analytics.financial.provider.curve.MulticurveBuildingDiscountingDiscountUSD2Test.java
@Test(enabled = false) /**//w w w . java 2 s .c o m * Analyzes the shape of the forward curve. */ public void forwardAnalysis() { final MulticurveProviderInterface marketDsc = CURVES_PAR_SPREAD_MQ_WITHOUT_TODAY_BLOCK.get(0).getFirst(); final int jump = 1; final int startIndex = 0; final int nbDate = 2750; ZonedDateTime startDate = ScheduleCalculator.getAdjustedDate(NOW, USDLIBOR3M.getSpotLag() + startIndex * jump, NYC); final double[] rateDsc = new double[nbDate]; final double[] startTime = new double[nbDate]; try { final FileWriter writer = new FileWriter("fwd-dsc.csv"); for (int loopdate = 0; loopdate < nbDate; loopdate++) { startTime[loopdate] = TimeCalculator.getTimeBetween(NOW, startDate); final ZonedDateTime endDate = ScheduleCalculator.getAdjustedDate(startDate, USDLIBOR3M, NYC); final double endTime = TimeCalculator.getTimeBetween(NOW, endDate); final double accrualFactor = USDLIBOR3M.getDayCount().getDayCountFraction(startDate, endDate); rateDsc[loopdate] = marketDsc.getForwardRate(USDLIBOR3M, startTime[loopdate], endTime, accrualFactor); startDate = ScheduleCalculator.getAdjustedDate(startDate, jump, NYC); writer.append(0.0 + "," + startTime[loopdate] + "," + rateDsc[loopdate] + "\n"); } writer.flush(); writer.close(); } catch (final IOException e) { e.printStackTrace(); } }