Created
December 21, 2020 14:32
-
-
Save fd00/ebf8c444bd4bc2cae5f546c9b51c50d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.example.demo; | |
| import com.google.common.io.ByteSource; | |
| import org.springframework.web.bind.annotation.RequestMapping; | |
| import org.springframework.web.bind.annotation.RequestMethod; | |
| import org.springframework.web.bind.annotation.RestController; | |
| import java.io.IOException; | |
| import java.io.InputStream; | |
| import java.nio.charset.StandardCharsets; | |
| import java.util.Optional; | |
| import java.util.UUID; | |
| import java.util.stream.IntStream; | |
| @RequestMapping("/") | |
| @RestController | |
| public class DemoController { | |
| @RequestMapping(method = RequestMethod.GET) | |
| public Optional<String> index() { | |
| return IntStream.range(0, 10).mapToObj((i) -> UUID.randomUUID().toString()).parallel().reduce((a, b) -> { | |
| ByteSource byteSource = new ByteSource() { | |
| @Override | |
| public InputStream openStream() { | |
| return Thread.currentThread().getContextClassLoader().getResourceAsStream("hello.txt"); | |
| } | |
| }; | |
| try { | |
| return byteSource.asCharSource(StandardCharsets.UTF_8).read(); | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| return null; | |
| } | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment