String source = "@startuml\n";
source += "Bob -> Alice : hello\n";
source += "@enduml\n";
SourceStringReader reader = new SourceStringReader(source);
final ByteArrayOutputStream os = new ByteArrayOutputStream();
// Write the first image to "os"
String desc = reader.generateImage(os, new FileFormatOption(FileFormat.SVG));
os.close();
// The XML is stored into svg
final String svg = new String(os.toByteArray(), Charset.forName("UTF-8"));
SVG generation from a String
If your diagram description is stored in a String, you can use the SourceStringReader class to generate some SVG file.
String source = "@startuml\n";
source += "Bob -> Alice : hello\n";
source += "@enduml\n";
SourceStringReader reader = new SourceStringReader(source);
final ByteArrayOutputStream os = new ByteArrayOutputStream();
// Write the first image to "os"
String desc = reader.generateImage(os, new FileFormatOption(FileFormat.SVG));
os.close();
// The XML is stored into svg
final String svg = new String(os.toByteArray(), Charset.forName("UTF-8"));