'Is it possible to convert OutStream to a string?
I have a method that uses DOM parsing to build an XML file and it takes an OutputStream as an argument. I'm trying to run the program from the command line, but the command line option only accepts strings.
I can run it by inputting System.out as an argument and running the the program, but that's it.
Here's a snippet of code:
public class WriteSourceTranslatedToTXML extends GetSourceSentences {
public static String makeTranslated(OutputStream output, String out) throws ParserConfigurationException, IOException, SAXException, URISyntaxException {
System.out.println("---creating XML file---");
Document doc = new Document();
doc.setRootElement(new Element("txml"));
// Built XML here and inserted sentences
xmlOutputter.setFormat(Format.getPrettyFormat());
xmlOutputter.output(doc, output);
// Write to file
XMLOutputter xout = new XMLOutputter();
String xml = xout.outputString(doc.getRootElement().getContent());
try(FileOutputStream fileOutputStream =
new FileOutputStream(out)) {
xmlOutputter.output(doc, fileOutputStream);
And here is the code for the command line:
@Command(name = "fileCli", description = "Performs file manipulation operations", mixinStandardHelpOptions = true, version = "File Client 1.0")
public class TranslateTXML implements Callable<String> {
@Option(names = "-o", description = "output path")
private String output;
if (output != null) {
WriteSourceTranslatedToTXML.makeTranslated(output); // Red line under output
System.out.println("translated made");
System.out.println("------");
System.out.println("File \"translated.txml\" has been outputted to designated path");
How can I do it?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
