public static void injectDataInGherkinExamples(String filename, List<String[]> lines) {
        try {
            if (!lines.isEmpty()) {
                Path filePath = getFeaturePath(filename);
                String fileContent = new String(Files.readAllBytes(filePath), Charset.forName(Constants.DEFAULT_ENDODING));
                StringBuilder examples = new StringBuilder();
                examples.append("    ");
                for (int j = 0; j < lines.size(); j++) {
                    examples.append("|");
                    examples.append(j + 1);
                    for (String col : lines.get(j)) {
                        examples.append("|");
                        examples.append(col);
                    }
                    examples.append("|\n    ");
                }

                fileContent = fileContent.replaceAll("(" + DATA + "\r?\n.*\r?\n)[\\s\\S]*(" + DATA_END + ")", "$1" + examples.toString() + "$2");

                try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath.toString()), Charset.forName(Constants.DEFAULT_ENDODING)));) {
                    bw.write(fileContent);
                }
            }
        } catch (IOException e) {
            logger.error("error GherkinFactory.injectDataInGherkinExamples()", e);
        }
    }
public static void injectDataInGherkinExamples ( String filename , List < String [ ] > lines ) { try { if ( ! lines . isEmpty ( ) ) { Path filePath = getFeaturePath ( filename ) ; String fileContent = new String ( Files . readAllBytes ( filePath ) , Charset . forName ( Constants . DEFAULT_ENDODING ) ) ; StringBuilder examples = new StringBuilder ( ) ; examples . append ( "    " ) ; for ( int j = 0 ; j < lines . size ( ) ; j ++ ) { examples . append ( "|" ) ; examples . append ( j + 1 ) ; for ( String col : lines . get ( j ) ) { examples . append ( "|" ) ; examples . append ( col ) ; } examples . append ( "|\n    " ) ; } fileContent = fileContent . replaceAll ( "(" + DATA + "\r?\n.*\r?\n)[\\s\\S]*(" + DATA_END + ")" , "$1" + examples . toString ( ) + "$2" ) ; try ( BufferedWriter bw = new BufferedWriter ( new OutputStreamWriter ( new FileOutputStream ( filePath . toString ( ) ) , Charset . forName ( Constants . DEFAULT_ENDODING ) ) ) ; ) { bw . write ( fileContent ) ; } } } catch ( IOException e ) { logger . error ( "error GherkinFactory.injectDataInGherkinExamples()" , e ) ; } }
@param filename
name of input Gherkin file.
@param lines
is a table of data (line by line and without headers).