Skip to content

Instantly share code, notes, and snippets.

@fd00
Created December 21, 2020 14:32
Show Gist options
  • Select an option

  • Save fd00/ebf8c444bd4bc2cae5f546c9b51c50d1 to your computer and use it in GitHub Desktop.

Select an option

Save fd00/ebf8c444bd4bc2cae5f546c9b51c50d1 to your computer and use it in GitHub Desktop.
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