Skip to content

Commit

Permalink
Merge pull request #646 from afischerdev/engine-mode
Browse files Browse the repository at this point in the history
Update for new output logic
  • Loading branch information
afischerdev committed Dec 10, 2023
2 parents 7657985 + 03bbbcf commit bcf6a7f
Show file tree
Hide file tree
Showing 12 changed files with 1,162 additions and 948 deletions.
43 changes: 43 additions & 0 deletions brouter-core/src/main/java/btools/router/FormatCsv.java
@@ -0,0 +1,43 @@
package btools.router;

import java.io.BufferedWriter;
import java.io.StringWriter;

public class FormatCsv extends Formatter {


public FormatCsv(RoutingContext rc) {
super(rc);
}

@Override
public String format(OsmTrack t) {
try {
StringWriter sw = new StringWriter();
BufferedWriter bw = new BufferedWriter(sw);
writeMessages(bw, t);
return sw.toString();
} catch (Exception ex) {
return "Error: " + ex.getMessage();
}
}

public void writeMessages(BufferedWriter bw, OsmTrack t) throws Exception {
dumpLine(bw, MESSAGES_HEADER);
for (String m : t.aggregateMessages()) {
dumpLine(bw, m);
}
if (bw != null)
bw.close();
}

private void dumpLine(BufferedWriter bw, String s) throws Exception {
if (bw == null) {
System.out.println(s);
} else {
bw.write(s);
bw.write("\n");
}
}

}

0 comments on commit bcf6a7f

Please sign in to comment.