I have a method in a Service that retrieve the courses objects from database. Before sending it to Controller I need to uncompress the field byte[] logo. Logo is a image that needs to be uncompress from database before rendering to front-end. I'm trying to do this with streams but without any success. map() method not working after forEach() method.
public List<CourseDto> getCoureses() {
List<Courses> courses = courseRepositoryDao.findAllByIsCourseFreeAndIsCourseActive(true, true);
List<CourseDto> coursesNameDto = courses
.stream()
.forEach(course-> course.setLogo(decompressZLib(course.getLogo()))
.map(course -> modelMapper.map(CourseMapper.toUserDtoFreeCourses(course), CourseDto.class))
.collect(Collectors.toList());
return coursesNameDto;
}