Search in sources :

Example 1 with InputFileTo

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;
    }
}
Also used : StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) InputFileTo(com.devonfw.cobigen.api.externalprocess.to.InputFileTo)

Example 2 with InputFileTo

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);
}
Also used : IOException(java.io.IOException) InputFileTo(com.devonfw.cobigen.api.externalprocess.to.InputFileTo) InputReaderException(com.devonfw.cobigen.api.exception.InputReaderException)

Aggregations

InputFileTo (com.devonfw.cobigen.api.externalprocess.to.InputFileTo)2 IOException (java.io.IOException)2 InputReaderException (com.devonfw.cobigen.api.exception.InputReaderException)1 BufferedReader (java.io.BufferedReader)1 StringReader (java.io.StringReader)1