@Test public void parseFile_ShouldParseFieldLines() throws Exception { Path testFile = getPath("profile.ffmpeg"); String option1 = "%{FIELD=value}"; String option2 = "%{key=other}"; Files.write(testFile, Arrays.asList(option1, option2)); Map<String, String> results = subject.parseFile(testFile).get().getFields(); assertThat(results) .containsKeys("FIELD", "KEY") .containsValues("value", "other") .hasSize(2); }
@Override public Optional<Profile> parseFile(Path path) { log.entry(path); try { List<String> lines = Files .lines(path) .map(String::trim) .filter(this::isNotCommentLine) .collect(Collectors.toList()); return log.exit(Optional.of( Profile.builder() .arguments(lines.stream() .filter(this::isNotFieldLine) .collect(Collectors.toList())) .fields(lines.stream() .filter(this::isFieldLine) .collect(Collectors.toMap(this::extractKey, this::extractValue))) .location(path) .build())); } catch (IOException e) { log.catching(XLogger.Level.WARN, e); return log.exit(Optional.empty()); } }
ProfileParserImpl implements ProfileParser { @Override public Optional<Profile> parseFile(Path path) { log.entry(path); try { List<String> lines = Files .lines(path) .map(String::trim) .filter(this::isNotCommentLine) .collect(Collectors.toList()); return log.exit(Optional.of( Profile.builder() .arguments(lines.stream() .filter(this::isNotFieldLine) .collect(Collectors.toList())) .fields(lines.stream() .filter(this::isFieldLine) .collect(Collectors.toMap(this::extractKey, this::extractValue))) .location(path) .build())); } catch (IOException e) { log.catching(XLogger.Level.WARN, e); return log.exit(Optional.empty()); } } }
ProfileParserImpl implements ProfileParser { @Override public Optional<Profile> parseFile(Path path) { log.entry(path); try { List<String> lines = Files .lines(path) .map(String::trim) .filter(this::isNotCommentLine) .collect(Collectors.toList()); return log.exit(Optional.of( Profile.builder() .arguments(lines.stream() .filter(this::isNotFieldLine) .collect(Collectors.toList())) .fields(lines.stream() .filter(this::isFieldLine) .collect(Collectors.toMap(this::extractKey, this::extractValue))) .location(path) .build())); } catch (IOException e) { log.catching(XLogger.Level.WARN, e); return log.exit(Optional.empty()); } }  }
ProfileParserImpl implements ProfileParser { @Override public Optional<Profile> parseFile(Path path) { log.entry(path); try { List<String> lines = Files .lines(path) .map(String::trim) .filter(this::isNotCommentLine) .collect(Collectors.toList()); return log.exit(Optional.of( Profile.builder() .arguments(lines.stream() .filter(this::isNotFieldLine) .collect(Collectors.toList())) .fields(lines.stream() .filter(this::isFieldLine) .collect(Collectors.toMap(this::extractKey, this::extractValue))) .location(path) .build())); } catch (IOException e) { log.catching(XLogger.Level.WARN, e); return log.exit(Optional.empty()); } }  @Override Optional<Profile> parseFile(Path path); }
ProfileParserImpl implements ProfileParser { @Override public Optional<Profile> parseFile(Path path) { log.entry(path); try { List<String> lines = Files .lines(path) .map(String::trim) .filter(this::isNotCommentLine) .collect(Collectors.toList()); return log.exit(Optional.of( Profile.builder() .arguments(lines.stream() .filter(this::isNotFieldLine) .collect(Collectors.toList())) .fields(lines.stream() .filter(this::isFieldLine) .collect(Collectors.toMap(this::extractKey, this::extractValue))) .location(path) .build())); } catch (IOException e) { log.catching(XLogger.Level.WARN, e); return log.exit(Optional.empty()); } }  @Override Optional<Profile> parseFile(Path path); static final Pattern FORMAT_PATTERN; }