Skip to content

Commit

Permalink
Added option to write graph directly to stream
Browse files Browse the repository at this point in the history
  • Loading branch information
britzl committed Oct 2, 2023
1 parent e1f5918 commit 8c860ca
Showing 1 changed file with 17 additions and 3 deletions.
Expand Up @@ -21,8 +21,11 @@
import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.io.Writer;
import java.io.StringWriter;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -110,9 +113,7 @@ private void writeJSON(JsonGenerator generator) throws IOException {
generator.writeEndObject();
}

public String toJSON() throws IOException {
StringWriter stringWriter = new StringWriter();
BufferedWriter writer = new BufferedWriter(stringWriter);
private void writeJSON(Writer writer) throws IOException {
JsonGenerator generator = null;
try {
generator = (new JsonFactory()).createJsonGenerator(writer);
Expand All @@ -124,7 +125,20 @@ public String toJSON() throws IOException {
generator.close();
}
IOUtils.closeQuietly(writer);

}
}

public void writeJSON(OutputStream os) throws IOException {
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(os);
BufferedWriter writer = new BufferedWriter(outputStreamWriter);
writeJSON(writer);
}

public String toJSON() throws IOException {
StringWriter stringWriter = new StringWriter();
BufferedWriter writer = new BufferedWriter(stringWriter);
writeJSON(writer);
return stringWriter.toString();
}

Expand Down

0 comments on commit 8c860ca

Please sign in to comment.