test_class.declarator: serializer
test_class.modifier: private
test_class.original_string: private CSVSerializer serializer;
test_class.type: CSVSerializer
test_class.var_name: serializer
test_class.file: dataprep-backend-service/src/test/java/org/talend/dataprep/schema/csv/CSVSerializerTest.java
test_class.identifier: CSVSerializerTest
test_case.body: @Test
      public void should_use_custom_import_parameters_double_quote_escape() throws Exception {
  
          // given (text escape char is |)
          InputStream inputStream = this.getClass().getResourceAsStream("tdp-4602_custom_param_csv_import.csv");
          DataSetMetadata datasetMetadata = getSimpleDataSetMetadata("column1", "column2");
          datasetMetadata.getContent().addParameter(SEPARATOR_PARAMETER, ",");
          datasetMetadata.getContent().addParameter(ESCAPE_CHAR, "\"");
          datasetMetadata.getContent().addParameter(TEXT_ENCLOSURE_CHAR, "+");
  
          // when
          InputStream input = serializer.serialize(inputStream, datasetMetadata, -1);
          String actual = IOUtils.toString(input, UTF_8);
  
          // then
          final String expected = IOUtils.toString(
                  this.getClass().getResourceAsStream("tdp-4602_custom_param_csv_import_double_quote_escape.json"),
                  UTF_8);
          JSONAssert.assertEquals(expected, actual, false);
      }
test_case.class_method_signature: CSVSerializerTest.should_use_custom_import_parameters_double_quote_escape()
test_case.full_signature: @Test public void should_use_custom_import_parameters_double_quote_escape()
test_case.identifier: should_use_custom_import_parameters_double_quote_escape
test_case.invocations: getResourceAsStream getClass getSimpleDataSetMetadata addParameter getContent addParameter getContent addParameter getContent serialize toString toString getResourceAsStream getClass assertEquals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void should_use_custom_import_parameters_double_quote_escape()
focal_class.declarator: LOGGER = LoggerFactory.getLogger(CSVSerializer.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger LOGGER = LoggerFactory.getLogger(CSVSerializer.class);
focal_class.type: Logger
focal_class.var_name: LOGGER
focal_class.declarator: defaultTextEnclosure
focal_class.modifier: @Value("${default.import.text.enclosure:\"}")
      private
focal_class.original_string: @Value("${default.import.text.enclosure:\"}")
      private String defaultTextEnclosure;
focal_class.type: String
focal_class.var_name: defaultTextEnclosure
focal_class.declarator: defaultEscapeChar
focal_class.modifier: @Value("${default.import.text.escape:\u0000}")
      private
focal_class.original_string: @Value("${default.import.text.escape:\u0000}")
      private String defaultEscapeChar;
focal_class.type: String
focal_class.var_name: defaultEscapeChar
focal_class.declarator: executor
focal_class.modifier: @Resource(name = "serializer#csv#executor")
      private
focal_class.original_string: @Resource(name = "serializer#csv#executor")
      private TaskExecutor executor;
focal_class.type: TaskExecutor
focal_class.var_name: executor
focal_class.file: dataprep-backend-service/src/main/java/org/talend/dataprep/schema/csv/CSVSerializer.java
focal_class.identifier: CSVSerializer
focal_class.interfaces: implements Serializer
focal_class.class_method_signature: CSVSerializer.serialize(InputStream rawContent, DataSetMetadata metadata, long limit)
focal_class.full_signature: @Override public InputStream serialize(InputStream rawContent, DataSetMetadata metadata, long limit)
focal_class.identifier: serialize
focal_class.modifiers: @Override public
focal_class.parameters: (InputStream rawContent, DataSetMetadata metadata, long limit)
focal_class.return: InputStream
focal_class.signature: InputStream serialize(InputStream rawContent, DataSetMetadata metadata, long limit)
focal_class.class_method_signature: CSVSerializer.getFromParameters(Map<String, String> parameters, String key, String defaultValue)
focal_class.full_signature: private char getFromParameters(Map<String, String> parameters, String key, String defaultValue)
focal_class.identifier: getFromParameters
focal_class.modifiers: private
focal_class.parameters: (Map<String, String> parameters, String key, String defaultValue)
focal_class.return: char
focal_class.signature: char getFromParameters(Map<String, String> parameters, String key, String defaultValue)
focal_class.class_method_signature: CSVSerializer.writeLineContent(CSVReader reader, DataSetMetadata metadata, JsonGenerator generator, String separator,
              long limit)
focal_class.full_signature: private void writeLineContent(CSVReader reader, DataSetMetadata metadata, JsonGenerator generator, String separator,
              long limit)
focal_class.identifier: writeLineContent
focal_class.modifiers: private
focal_class.parameters: (CSVReader reader, DataSetMetadata metadata, JsonGenerator generator, String separator,
              long limit)
focal_class.return: void
focal_class.signature: void writeLineContent(CSVReader reader, DataSetMetadata metadata, JsonGenerator generator, String separator,
              long limit)
focal_class.class_method_signature: CSVSerializer.withinLimit(long limit, int current)
focal_class.full_signature: private boolean withinLimit(long limit, int current)
focal_class.identifier: withinLimit
focal_class.modifiers: private
focal_class.parameters: (long limit, int current)
focal_class.return: boolean
focal_class.signature: boolean withinLimit(long limit, int current)
focal_class.class_method_signature: CSVSerializer.cleanCharacters(final String value)
focal_class.full_signature: private String cleanCharacters(final String value)
focal_class.identifier: cleanCharacters
focal_class.modifiers: private
focal_class.parameters: (final String value)
focal_class.return: String
focal_class.signature: String cleanCharacters(final String value)
focal_class.class_method_signature: CSVSerializer.getRemainingColumns(String[] line, int start, String separator)
focal_class.full_signature: private String getRemainingColumns(String[] line, int start, String separator)
focal_class.identifier: getRemainingColumns
focal_class.modifiers: private
focal_class.parameters: (String[] line, int start, String separator)
focal_class.return: String
focal_class.signature: String getRemainingColumns(String[] line, int start, String separator)
focal_method.body: @Override
      public InputStream serialize(InputStream rawContent, DataSetMetadata metadata, long limit) {
          try {
              PipedInputStream pipe = new PipedInputStream();
              PipedOutputStream jsonOutput = new PipedOutputStream(pipe);
              // Serialize asynchronously for better performance (especially if caller doesn't consume all, see sampling).
              Runnable r = () -> {
                  final Map<String, String> parameters = metadata.getContent().getParameters();
                  final String separator = parameters.get(CSVFormatFamily.SEPARATOR_PARAMETER);
                  final char actualSeparator = separator.charAt(0);
                  final char textEnclosureChar = getFromParameters(parameters, TEXT_ENCLOSURE_CHAR, defaultTextEnclosure);
                  final char escapeChar = getFromParameters(parameters, CSVFormatFamily.ESCAPE_CHAR, defaultEscapeChar);
  
                  try (InputStreamReader input = new InputStreamReader(rawContent, metadata.getEncoding());
                          CSVReader reader = new CSVReader(input, actualSeparator, textEnclosureChar, escapeChar)) {
  
                      JsonGenerator generator = new JsonFactory().createGenerator(jsonOutput);
                      int i = 0;
                      while (i++ < metadata.getContent().getNbLinesInHeader()) {
                          reader.readNext(); // Skip all header lines
                      }
                      generator.writeStartArray();
                      writeLineContent(reader, metadata, generator, separator, limit);
                      generator.writeEndArray();
                      generator.flush();
                  } catch (Exception e) {
                      // Consumer may very well interrupt consumption of stream (in case of limit(n) use for sampling).
                      // This is not an issue as consumer is allowed to partially consumes results, it's up to the
                      // consumer to ensure data it consumed is consistent.
                      LOGGER.debug("Unable to continue serialization for {}. Skipping remaining content.",
                              metadata.getId(), e);
                  } finally {
                      try {
                          jsonOutput.close();
                      } catch (IOException e) {
                          LOGGER.error("Unable to close output", e);
                      }
                  }
              };
              executor.execute(r);
              return pipe;
          } catch (IOException e) {
              throw new TDPException(CommonErrorCodes.UNABLE_TO_SERIALIZE_TO_JSON, e);
          }
      }
focal_method.class_method_signature: CSVSerializer.serialize(InputStream rawContent, DataSetMetadata metadata, long limit)
focal_method.full_signature: @Override public InputStream serialize(InputStream rawContent, DataSetMetadata metadata, long limit)
focal_method.identifier: serialize
focal_method.invocations: getParameters getContent get charAt getFromParameters getFromParameters getEncoding createGenerator getNbLinesInHeader getContent readNext writeStartArray writeLineContent writeEndArray flush debug getId close error execute
focal_method.modifiers: @Override public
focal_method.parameters: (InputStream rawContent, DataSetMetadata metadata, long limit)
focal_method.return: InputStream
focal_method.signature: InputStream serialize(InputStream rawContent, DataSetMetadata metadata, long limit)