Example usage for org.springframework.boot ApplicationArguments containsOption

List of usage examples for org.springframework.boot ApplicationArguments containsOption

Introduction

In this page you can find the example usage for org.springframework.boot ApplicationArguments containsOption.

Prototype

boolean containsOption(String name);

Source Link

Document

Return whether the set of option arguments parsed from the arguments contains an option with the given name.

Usage

From source file:com.crossover.trial.weather.util.AirportLoader.java

@Override
public void run(ApplicationArguments args) throws Exception {
    if (args.containsOption("airports") && !args.getOptionValues("airports").isEmpty()) {
        File dataFile = new File(args.getOptionValues("airports").get(0));
        if (dataFile.canRead() && dataFile.isFile() && dataFile.exists()) {
            log.info("Loading airports from [{}]", dataFile);

            try (Stream<String> lines = Files.lines(dataFile.toPath())) {
                lines.map(Row::new).filter(Row::expectedTotalColumns).filter(Row::expectedColumnsFilled)
                        .map(Row::parse).filter(airport -> airport != null).forEach(airportRepository::save);
            }//  w w  w  . j  a v a 2  s.c om

        } else
            log.error("Specified airports data file is not readable [{}]", dataFile.toPath());

    }
}