use of com.devonfw.cobigen.api.externalprocess.to.InputFileTo in project cobigen by devonfw.
the class TypeScriptMerger method runBeautifierExcludingImports.
/**
* Reads the output.ts temporary file to get the merged contents
*
* @param content The content to be beautified
* @return merged contents already beautified
*/
private String runBeautifierExcludingImports(String content) {
StringBuffer importsAndExports = new StringBuffer();
StringBuffer body = new StringBuffer();
try (StringReader isr = new StringReader(content);
BufferedReader br = new BufferedReader(isr)) {
LOG.debug("Receiving output from Server....");
Stream<String> s = br.lines();
s.parallel().forEachOrdered((String line) -> {
if (line.startsWith("import ") || isExportStatement(line)) {
importsAndExports.append(line);
importsAndExports.append(LINE_SEP);
} else {
body.append(line);
body.append(LINE_SEP);
}
});
InputFileTo fileTo = new InputFileTo("", body.toString(), UTF8);
String beautifiedContent = this.externalProcess.postJsonRequest("beautify", fileTo);
return importsAndExports + LINE_SEP + LINE_SEP + beautifiedContent;
} catch (IOException e) {
LOG.warn("Unable to read service response for beautification", e);
// beautification anyhow is not critical, let's keep returning what we have
return content;
}
}
use of com.devonfw.cobigen.api.externalprocess.to.InputFileTo in project cobigen by devonfw.
the class ExternalServerInputReaderProxy method read.
@Override
public Object read(Path path, Charset inputCharset, Object... additionalArguments) throws InputReaderException {
String fileContents;
String fileName = path.toString();
try {
fileContents = String.join("", Files.readAllLines(path, inputCharset));
} catch (IOException e) {
throw new InputReaderException("Could not read input file!" + fileName, e);
}
InputFileTo inputFile = new InputFileTo(fileName, fileContents, inputCharset.name());
return this.externalProcess.postJsonRequest("getInputModel", inputFile);
}
Aggregations