Skip to content

Commit

Permalink
feat: Add ObjectDiagrams.dumpToString
Browse files Browse the repository at this point in the history
  • Loading branch information
Clashsoft committed Feb 22, 2024
1 parent 9e88e39 commit d7666c8
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/main/java/org/fulib/tools/ObjectDiagrams.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand Down Expand Up @@ -162,6 +163,36 @@ public String dumpSVG(String diagramFileName, Object... objectList)
return this.dump(Format.SVG_STANDALONE, diagramFileName, objectList);
}

/**
* Writes a string description of the objects to a file using {@link Object#toString()}.
* Each root in the list is written to a separate line.
* {@code null} roots are ignored.
*
* @param fileName the file name
* @param rootList the list of objects to display
*
* @since 1.7
*/
public void dumpToString(String fileName, Object... rootList)
{
try (final Writer writer = Files.newBufferedWriter(Paths.get(fileName), StandardCharsets.UTF_8))
{
for (Object obj : rootList)
{
if (obj == null)
{
continue;
}
writer.write(obj.toString());
writer.write('\n');
}
}
catch (IOException ex)
{
ex.printStackTrace();
}
}

/**
* Create yaml description.
*
Expand Down

0 comments on commit d7666c8

Please sign in to comment.