List of usage examples for java.io BufferedWriter append
public Writer append(CharSequence csq) throws IOException
From source file:com.pieframework.runtime.utils.azure.CsdefGenerator.java
private void printSettings(BufferedWriter out, Role r, boolean includeForwarder) { try {/*from w ww. j a v a2 s . c om*/ out.append("<ConfigurationSettings>"); printGlobalSettings(out, r, includeForwarder); Map<String, Service> settingsList = new HashMap<String, Service>(); for (String key : r.getChildren().keySet()) { Service service = null; if (r.getChildren().get(key) instanceof Service) { service = (Service) r.getChildren().get(key); for (String attr : service.getProps().keySet()) { settingsList.put(service.getId() + "." + attr, service); } if (service.getDependencies() != null) { for (Dependency d : service.getDependencies()) { if (d.getTarget() != null && d.getType() != null) { Object tmp = MVEL.getProperty(d.getTarget(), ModelStore.getCurrentModel()); if (tmp instanceof Service) { Service serviceDependency = (Service) tmp; for (String prop : serviceDependency.getProps().keySet()) { settingsList.put(serviceDependency.getId() + "." + prop, service); } } } } } settingsList.put(service.getId() + ".installContainer", service); } } for (String setting : settingsList.keySet()) { out.append("<Setting name=\"" + setting + "\" />"); } out.append("</ConfigurationSettings>"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.balloon_project.overflight.task.indexing.IndexingTask.java
private File getOrCreateDumpFile() throws IOException { // create file if it not already exists File dir = new File(configuration.getTripleDumpStoreDirectory()); dir.mkdirs();//w ww . j a v a 2 s. c o m File dumpFile = new File(dir, filename); boolean newFile = dumpFile.createNewFile(); // adding header to new file if (newFile) { BufferedWriter writer = new BufferedWriter(new FileWriter(dumpFile)); try { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); writer.append( "# ---------------------------------------------------------------------------------------------------------------------------\n"); writer.append( "# Triples indexed by Balloon Overflight (https://www.dimis.fim.uni-passau.de/balloon/)\n"); writer.append("# " + KEY_ENDPOINT + ": ").append(endpoint.getEndpointID()).append("\n"); writer.append("# URL: ").append(endpoint.getUrl()).append("\n"); writer.append("# SPARQL: ").append(endpoint.getSparqlEndpoint()).append("\n"); writer.append("# Information: http://datahub.io/dataset/").append(endpoint.getEndpointID()) .append("\n"); writer.append("# " + KEY_PREDICATE + ": ").append(relEntity.getPredicate()).append("\n"); writer.append("# PredicateIdentifier: ").append(relEntity.getShortname()).append("\n"); writer.append("# PredicateType: ").append(relEntity.getType().toString()).append("\n"); writer.append("# " + KEY_DATE + ": ").append(dateFormat.format(new Date())).append("\n"); writer.append( "# ---------------------------------------------------------------------------------------------------------------------------\n"); writer.append(BEGIN_DATA); writer.append("\n"); } finally { writer.flush(); writer.close(); } } return dumpFile; }
From source file:com.mitre.holdshort.AlertLogger.java
private void endAlert(Location loc, AlertEndType endType) { currentAlert.setStopTime(System.currentTimeMillis()); currentAlert.setStopLatLon(String.valueOf(loc.getLatitude()), String.valueOf(loc.getLongitude())); currentAlert.setStopHeading(loc.getBearing()); currentAlert.setStopSpeed((float) (loc.getSpeed() * MainActivity.MS_TO_KNOTS)); currentAlert.setStopAltitude(loc.getAltitude() * MainActivity.M_TO_FEET); currentAlert.setEndType(endType);/*w w w. ja va 2s .c o m*/ try { alertFTPClient.connect(this.ftpHost, 21); if (alertFTPClient.login(this.ftpUser, this.ftpPassword)) { alertFTPClient.enterLocalPassiveMode(); writeDataToFtpServer(currentAlert); currentAlert = null; } } catch (UnknownHostException e) { System.err.println("No Connection For FTP Client"); // No write that stuff to oldAlerts.dat File oldAlerts = new File(ctx.getFilesDir() + "/oldAlerts.dat"); FileWriter logWriter = null; try { logWriter = new FileWriter(oldAlerts, true); BufferedWriter outer = new BufferedWriter(logWriter); outer.append(currentAlert.getAlertString()); outer.newLine(); outer.close(); System.out.println(String.valueOf(oldAlerts.length())); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { System.err.println("No Connection For FTP Client"); // No write that stuff to oldAlerts.dat File oldAlerts = new File(ctx.getFilesDir() + "/oldAlerts.dat"); FileWriter logWriter = null; try { logWriter = new FileWriter(oldAlerts, true); BufferedWriter outer = new BufferedWriter(logWriter); outer.append(currentAlert.getAlertString()); outer.newLine(); outer.close(); System.out.println(String.valueOf(oldAlerts.length())); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }
From source file:com.microsoft.gittf.core.tasks.FetchTask.java
private boolean writeFetchHead(final ObjectId commitID, final int changesetID) throws IOException { Ref fetchHeadRef = repository.getRef(Constants.FETCH_HEAD); boolean referencesEqual = fetchHeadRef == null ? false : fetchHeadRef.getObjectId().equals(commitID); if (referencesEqual) { return false; }/*from w ww .ja v a 2 s. c o m*/ final File refFile = new File(repository.getDirectory(), Constants.FETCH_HEAD); final LockFile lockFile = new LockFile(refFile, repository.getFS()); if (lockFile.lock()) { try { BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(lockFile.getOutputStream(), Charset.forName("UTF-8"))); //$NON-NLS-1$ try { writer.append(MessageFormat.format("{0}\t\t{1}", commitID.getName(), //$NON-NLS-1$ Messages.formatString("FetchTask.RefLogFormat", //$NON-NLS-1$ Integer.toString(changesetID)))); } finally { writer.close(); } lockFile.commit(); } finally { lockFile.unlock(); } } return true; }
From source file:com.termmed.reconciliation.RelationshipReconciliation.java
/** * Write r f2 type line./*from w ww .j a va2s . co m*/ * * @param bw the bw * @param relationshipId the relationship id * @param effectiveTime the effective time * @param active the active * @param moduleId the module id * @param sourceId the source id * @param destinationId the destination id * @param relationshipGroup the relationship group * @param relTypeId the rel type id * @param characteristicTypeId the characteristic type id * @param modifierId the modifier id * @throws IOException Signals that an I/O exception has occurred. */ public static void writeRF2TypeLine(BufferedWriter bw, String relationshipId, int effectiveTime, int active, long moduleId, long sourceId, long destinationId, int relationshipGroup, long relTypeId, String characteristicTypeId, String modifierId) throws IOException { bw.append(relationshipId + "\t" + effectiveTime + "\t" + active + "\t" + moduleId + "\t" + sourceId + "\t" + destinationId + "\t" + relationshipGroup + "\t" + relTypeId + "\t" + characteristicTypeId + "\t" + modifierId); bw.append("\r\n"); }
From source file:de.upb.timok.run.GenericSmacPipeline.java
private void writeSample(String line, BufferedWriter writer) throws IOException { writer.write(line);/*from w ww. ja v a 2 s . c om*/ writer.append('\n'); }
From source file:com.pieframework.runtime.utils.azure.CsdefGenerator.java
private void printWorkerRoleContent(BufferedWriter out, Role role, int counter, Boolean includeForwarder) { try {/* ww w . j av a 2 s .c o m*/ Policy p = (Policy) role.getResources().get("provisionPolicy"); out.append("<WorkerRole name=\"" + role.getId() + "\" vmsize=\"" + p.getSize() + "\" >"); List<String> epList = printEndpoints(out, role); printLocalResources(out, role); printCertificates(out, role); printStartupTasks(out, role); printImports(out, role, includeForwarder); printSettings(out, role, includeForwarder); out.append("</WorkerRole>"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.pieframework.runtime.utils.azure.CsdefGenerator.java
private void printCertificates(BufferedWriter out, Role r) { //print certificates try {/*from w ww . j av a 2 s . c o m*/ AzureKey ssl = (AzureKey) r.getResources().get("sslCert"); String certName = ssl.getCertificateName(); out.append("<Certificates>"); out.append("<Certificate name=\"" + certName + "\" storeLocation=\"LocalMachine\" storeName=\"My\" />"); out.append("</Certificates>"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.matsim.contrib.analysis.vsp.traveltimedistance.TravelTimeValidationRunner.java
private void writeTravelTimeValidation(String folder, List<CarTrip> trips) { BufferedWriter bw = IOUtils.getBufferedWriter(folder + "/validated_trips.csv"); XYSeriesCollection times = new XYSeriesCollection(); XYSeriesCollection distances = new XYSeriesCollection(); XYSeries distancess = new XYSeries("distances", true, true); XYSeries timess = new XYSeries("times", true, true); times.addSeries(timess);//from ww w . j ava2s.c om distances.addSeries(distancess); try { bw.append( "agent;departureTime;fromX;fromY;toX;toY;traveltimeActual;traveltimeValidated;traveledDistance;validatedDistance"); for (CarTrip trip : trips) { if (trip.getValidatedTravelTime() != null) { bw.newLine(); bw.append(trip.toString()); timess.add(trip.getActualTravelTime(), trip.getValidatedTravelTime()); distancess.add(trip.getTravelledDistance(), trip.getValidatedTravelDistance()); } } bw.flush(); bw.close(); final JFreeChart chart2 = ChartFactory.createScatterPlot("Travel Times", "Simulated travel time [s]", "Validated travel time [s]", times); final JFreeChart chart = ChartFactory.createScatterPlot("Travel Distances", "Simulated travel distance [m]", "Validated travel distance [m]", distances); NumberAxis yAxis = (NumberAxis) ((XYPlot) chart2.getPlot()).getRangeAxis(); NumberAxis xAxis = (NumberAxis) ((XYPlot) chart2.getPlot()).getDomainAxis(); NumberAxis yAxisd = (NumberAxis) ((XYPlot) chart.getPlot()).getRangeAxis(); NumberAxis xAxisd = (NumberAxis) ((XYPlot) chart.getPlot()).getDomainAxis(); yAxisd.setUpperBound(xAxisd.getUpperBound()); yAxis.setUpperBound(xAxis.getUpperBound()); yAxis.setTickUnit(new NumberTickUnit(500)); xAxis.setTickUnit(new NumberTickUnit(500)); XYAnnotation diagonal = new XYLineAnnotation(xAxis.getRange().getLowerBound(), yAxis.getRange().getLowerBound(), xAxis.getRange().getUpperBound(), yAxis.getRange().getUpperBound()); ((XYPlot) chart2.getPlot()).addAnnotation(diagonal); XYAnnotation diagonald = new XYLineAnnotation(xAxisd.getRange().getLowerBound(), yAxisd.getRange().getLowerBound(), xAxisd.getRange().getUpperBound(), yAxisd.getRange().getUpperBound()); ((XYPlot) chart.getPlot()).addAnnotation(diagonald); ChartUtilities.writeChartAsPNG(new FileOutputStream(folder + "/validated_traveltimes" + ".png"), chart2, 1500, 1500); ChartUtilities.writeChartAsPNG(new FileOutputStream(folder + "/validated_traveldistances.png"), chart, 1500, 1500); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:edu.utah.bmi.biosio.skos.DbToSkosExporter.java
/** * Export vocabulary concepts from the database to a single Turtle/SKOS file * @param filePath Path to the output file * @throws Exception //from w w w . j a va 2s . c o m */ public void exportToFile(String filePath) throws Exception { BufferedWriter bw = null; File file = new File(filePath); try { bw = new BufferedWriter(new FileWriter(file)); //add header with prefixes bw.append("@prefix skos: <http://www.w3.org/2004/02/skos/core#> .\n"); bw.append("@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n"); bw.append("@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n"); bw.append("@prefix owl: <http://www.w3.org/2002/07/owl#> .\n"); bw.append("@prefix dc: <http://purl.org/dc/elements/1.1/> .\n"); bw.append("@prefix dct: <http://purl.org/dc/terms/> .\n"); bw.append("@prefix " + skosVocabularyPrefix + ": <" + skosVocabularyUri + "#> .\n"); bw.append("@base <" + skosVocabularyUri + "> .\n"); DBQueryUtils queryService = new DBQueryUtils(this.sessionFactory); //ontology imports List<ExternalOntology> ontologies = queryService.getExternalOntologies(); if (ontologies != null) { for (ExternalOntology ontology : ontologies) { bw.append( "@prefix " + ontology.getId().toLowerCase() + ": <" + ontology.getPrefix() + "#> .\n"); } } /*//ontology information bw.append("\n<" + skosVocabularyUri + ">\n"); bw.append(" rdf:type owl:Ontology ;\n"); bw.append(" dc:title \""+skosVocabularyName+"\" ;\n"); SimpleDateFormat formatter = new SimpleDateFormat("YYYY-MM-dd"); bw.append(" dc:date \""+formatter.format(new Date())+"\" ;\n"); bw.append(" dc:creator \""+skosVocabularyAuthor+"\" .\n");*/ //SKOS scheme (necessary?) bw.append("\n" + skosVocabularyPrefix + ":" + skosVocabularyName + " rdf:type skos:ConceptScheme ;\n"); bw.append(" rdfs:label \"" + skosVocabularyName + "\"@en ;\n"); bw.append(" rdfs:comment \"" + skosVocabularyDescription + "\"@en ;\n"); bw.append(" dc:title \"" + skosVocabularyDescription + "\";\n"); SimpleDateFormat formatter = new SimpleDateFormat("YYYY-MM-dd"); bw.append(" dc:date \"" + formatter.format(new Date()) + "\";\n"); bw.append(" dc:creator \"" + skosVocabularyAuthor + "\" .\n"); System.out.println("Retrieving concepts from database..."); List<Concept> concepts = queryService.getConcepts(); System.out.println(" -> " + concepts.size() + " concepts and relationships found.\nExporting..."); int c = 0; int rISA = 0; int rAssoc = 0; /*//add citation as possible annotation property String citationPropertyStr = "\n"+rdfOntoPrefix+":citation rdf:type owl:AnnotationProperty ;\n"; citationPropertyStr += " "+"rdfs:label \"citation\"@en ;\n"; citationPropertyStr += " "+"rdfs:comment \"Reference to scientific literature or online resource\"@en .\n"; bw.append(citationPropertyStr);*/ for (Concept concept : concepts) { if (!concept.getIsRelationship()) { StringBuilder conceptStringBuilder = new StringBuilder(); //concept conceptStringBuilder.append( "\n" + skosVocabularyPrefix + ":" + concept.getCui() + " rdf:type skos:Concept ;\n"); conceptStringBuilder .append(" skos:inScheme " + skosVocabularyPrefix + ":" + skosVocabularyName + " ;\n"); conceptStringBuilder.append(" skos:prefLabel \"" + concept.getTerm() + "\"@en ;\n"); //concept terms List<Synonym> synonyms = queryService.getConceptTerms(concept.getCui()); for (Synonym synonym : synonyms) { if (!synonym.getTerm().equals(concept.getTerm())) conceptStringBuilder.append(" skos:altLabel \"" + synonym.getTerm() + "\"@" + synonym.getLanguage().toLowerCase() + " ;\n"); } //definitions Set<Description> descriptions = concept.getDescriptions(); for (Description desc : descriptions) { conceptStringBuilder.append(" skos:scopeNote \"" + desc.getDescription() + "\"@" + desc.getLanguage().toLowerCase() + " ;\n"); conceptStringBuilder.append(" skos:definition \"" + desc.getDescription() + "\"@" + desc.getLanguage().toLowerCase() + " ;\n"); } //relationships (FROM this concept) boolean hasBroaderRel = false; List<Relationship> relationships = queryService.getConceptRelationships(concept.getCui()); for (Relationship rel : relationships) { Concept conceptTo = rel.getConceptTo(); Concept conceptRel = rel.getRelationshipDefinition(); String concept2 = conceptTo.getCui(); if (getNormalizedConceptTerm(conceptRel.getTerm()).equals("is_a")) { conceptStringBuilder .append(" skos:broader " + skosVocabularyPrefix + ":" + concept2 + " ;\n"); rISA++; hasBroaderRel = true; } else { conceptStringBuilder .append(" skos:related " + skosVocabularyPrefix + ":" + concept2 + " ;\n"); rAssoc++; } } //relationships (TO this concept) List<Relationship> toRelationships = queryService .getRelationshipsTargetingConcept(concept.getCui()); if (toRelationships != null) { for (Relationship rel : toRelationships) { Concept conceptFrom = rel.getConceptFrom(); Concept conceptRel = rel.getRelationshipDefinition(); String concept1 = conceptFrom.getCui(); if (getNormalizedConceptTerm(conceptRel.getTerm()).equals("is_a")) { conceptStringBuilder.append( " skos:narrower " + skosVocabularyPrefix + ":" + concept1 + " ;\n"); } } } /*//citations List<Citation> citations = queryService.getCitationsByCUI(concept.getCui()); if (citations!=null){ for (Citation cit : citations){ conceptStringBuilder.append(" " + skosVocabularyPrefix+":citation \"" + cit.getText() + "\" ;\n"); } }*/ // mappings List<Mapping> ontologyMappings = queryService.getOntologyMappingsByCUI(concept.getCui()); if (ontologyMappings != null) { for (Mapping ontologyMapping : ontologyMappings) { conceptStringBuilder.append(" skos:exactMatch " + ontologyMapping.getOntologyDefinition().getId().toLowerCase() + ":" + ontologyMapping.getOntologyTerm() + " ;\n"); } } String conceptString = conceptStringBuilder.toString(); bw.append(conceptString.substring(0, conceptString.length() - 2) + ".\n"); //add to top concepts if no broader concept if (!hasBroaderRel) bw.append("\n" + skosVocabularyPrefix + ":" + skosVocabularyName + " skos:hasTopConcept " + skosVocabularyPrefix + ":" + concept.getCui() + " .\n"); c++; } } System.out.println(" -> " + c + " concepts, " + rISA + " 'broader/narrower' relationships, and " + rAssoc + " associative relationships exported!"); bw.close(); } catch (Exception e) { if (bw != null) { try { bw.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } throw e; } }