for (int i = 0; i < columnsToExport.length; i++) {
columnsToExport[i] = columns[i].getIndex();
}
}
CsvWriter writer = new CsvWriter(out, separator, charset);
//Write column headers:
for (int column = 0; column < columnsToExport.length; column++) {
int columnIndex = columnsToExport[column];
if (columnIndex == FAKE_COLUMN_EDGE_SOURCE) {
writer.write("Source");
} else if (columnIndex == FAKE_COLUMN_EDGE_TARGET) {
writer.write("Target");
} else if (columnIndex == FAKE_COLUMN_EDGE_TYPE) {
writer.write("Type");
} else {
writer.write(table.getColumn(columnIndex).getTitle(), true);
}
}
writer.endRecord();
//Write rows:
Object value;
String text;
for (int row = 0; row < rows.length; row++) {
for (int column = 0; column < columnsToExport.length; column++) {
int columnIndex = columnsToExport[column];
if (columnIndex == FAKE_COLUMN_EDGE_SOURCE) {
value = ((Edge)rows[row]).getSource().getNodeData().getId();
} else if (columnIndex == FAKE_COLUMN_EDGE_TARGET) {
value = ((Edge)rows[row]).getTarget().getNodeData().getId();
} else if (columnIndex == FAKE_COLUMN_EDGE_TYPE) {
value = ((Edge)rows[row]).isDirected() ? "Directed" : "Undirected";
} else {
value = rows[row].getAttributes().getValue(columnIndex);
}
if (value != null) {
text = value.toString();
} else {
text = "";
}
writer.write(text, true);
}
writer.endRecord();
}
writer.close();
}