From a314b14e312fe6c825932216a21a11a2cb20aedd Mon Sep 17 00:00:00 2001 From: Enrico Daga Date: Thu, 24 Nov 2022 16:49:11 +0000 Subject: [PATCH] implement #319 --- .../sparqlanything/cli/SPARQLAnything.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/sparql-anything-cli/src/main/java/com/github/sparqlanything/cli/SPARQLAnything.java b/sparql-anything-cli/src/main/java/com/github/sparqlanything/cli/SPARQLAnything.java index 7d787108..1dc1c320 100644 --- a/sparql-anything-cli/src/main/java/com/github/sparqlanything/cli/SPARQLAnything.java +++ b/sparql-anything-cli/src/main/java/com/github/sparqlanything/cli/SPARQLAnything.java @@ -52,6 +52,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.PrintStream; @@ -575,4 +576,22 @@ public static void main(String[] args) throws Exception { logger.trace("[time] Process ends: {}", System.currentTimeMillis() - duration); } } + + public static String callMain(String[] args) throws Exception { + // Thanks to: https://stackoverflow.com/a/8708357/1035608 + // Create a stream to hold the output + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream ps = new PrintStream(baos); + // IMPORTANT: Save the old System.out! + PrintStream old = System.out; + // Tell Java to use your special stream + System.setOut(ps); + // Print some output: goes to your special stream + main(args); + // Put things back + System.out.flush(); + System.setOut(old); + // Show what happened + return baos.toString(); + } }