Exemple #1
0
 private void writeVertex(Writer writer, Vertex v, int id) throws IOException {
   writer.write(TAB);
   writer.write(GMLTokens.NODE);
   writer.write(OPEN_LIST);
   writeKey(writer, GMLTokens.ID);
   writeNumberProperty(writer, id);
   writeVertexProperties(writer, v);
   writer.write(TAB);
   writer.write(CLOSE_LIST);
 }
Exemple #2
0
  private void writeGraph(Writer writer, List<Vertex> verticies, List<Edge> edges)
      throws IOException {
    Map<Vertex, Integer> ids = new HashMap<Vertex, Integer>();

    writer.write(GMLTokens.GRAPH);
    writer.write(OPEN_LIST);
    writeVerticies(writer, verticies, ids);
    writeEdges(writer, edges, ids);
    writer.write(CLOSE_LIST);
  }
Exemple #3
0
 private void writeMapProperty(Writer writer, Map<?, ?> map, int tabs) throws IOException {
   writer.write(OPEN_LIST);
   tabs++;
   for (Entry<?, ?> entry : map.entrySet()) {
     writeTabs(writer, tabs);
     writeKey(writer, entry.getKey().toString());
     writeProperty(writer, entry.getValue(), tabs);
   }
   writeTabs(writer, tabs - 1);
   writer.write(CLOSE_LIST);
 }
Exemple #4
0
 private void writeEdgeProperties(Writer writer, Edge e, Integer source, Integer target)
     throws IOException {
   writer.write(TAB);
   writer.write(GMLTokens.EDGE);
   writer.write(OPEN_LIST);
   writeKey(writer, GMLTokens.SOURCE);
   writeNumberProperty(writer, source);
   writeKey(writer, GMLTokens.TARGET);
   writeNumberProperty(writer, target);
   writeKey(writer, GMLTokens.LABEL);
   writeStringProperty(writer, e.getLabel());
   writeEdgeProperties(writer, e);
   writer.write(TAB);
   writer.write(CLOSE_LIST);
 }
Exemple #5
0
  /**
   * Write the data in a Graph to a GML OutputStream.
   *
   * @param gMLOutputStream the GML OutputStream to write the Graph data to
   * @throws java.io.IOException thrown if there is an error generating the GML data
   */
  public void outputGraph(final OutputStream gMLOutputStream) throws IOException {

    // ISO 8859-1 as specified in the GML documentation
    Writer writer =
        new BufferedWriter(new OutputStreamWriter(gMLOutputStream, Charset.forName("ISO-8859-1")));

    List<Vertex> verticies = new ArrayList<Vertex>();
    List<Edge> edges = new ArrayList<Edge>();

    populateLists(verticies, edges);

    if (normalize) {
      LexicographicalElementComparator comparator = new LexicographicalElementComparator();
      Collections.sort(verticies, comparator);
      Collections.sort(edges, comparator);
    }

    writeGraph(writer, verticies, edges);

    writer.flush();
    writer.close();
  }
Exemple #6
0
 private void writeKey(Writer writer, String command) throws IOException {
   writer.write(TAB);
   writer.write(TAB);
   writer.write(command);
   writer.write(DELIMITER);
 }
Exemple #7
0
 private void writeStringProperty(Writer writer, Object string) throws IOException {
   writer.write("\"");
   writer.write(string.toString());
   writer.write("\"");
   writer.write(NEW_LINE);
 }
Exemple #8
0
 private void writeNumberProperty(Writer writer, Number integer) throws IOException {
   writer.write(integer.toString());
   writer.write(NEW_LINE);
 }
Exemple #9
0
 private void writeTabs(Writer writer, int tabs) throws IOException {
   for (int i = 0; i <= tabs; i++) {
     writer.write(TAB);
   }
 }