To copy from a stream into a file:

import java.nio.file.Files;
import java.nio.file.Path;

Files.copy(inputStream, path);

To copy from a stream into another stream, assuming you’re using Spring:

import org.springframework.util.StreamUtils;

StreamUtils.copy(inputStream, outputStream);