Skip to content

Commit

Permalink
fix : issue with loading all data
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Dec 5, 2024
1 parent e011b6f commit 6337a58
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,19 @@ public RestaurantService(
}

public Flux<Restaurant> loadData() {
return DataBufferUtils.read(
new ClassPathResource("restaurants.json"),
new DefaultDataBufferFactory(),
4096)
return DataBufferUtils.join(
DataBufferUtils.read(
new ClassPathResource("restaurants.json"),
new DefaultDataBufferFactory(),
4096))
.map(
dataBuffer -> {
byte[] bytes = new byte[dataBuffer.readableByteCount()];
dataBuffer.read(bytes);
DataBufferUtils.release(dataBuffer);
return new String(bytes, StandardCharsets.UTF_8);
})
.flatMap(
.flatMapMany(
fileContent -> {
List<String> restaurantArray = Arrays.asList(fileContent.split("\n"));
return this.saveAll(restaurantArray);
Expand Down

0 comments on commit 6337a58

Please sign in to comment.