https://github.com/megaprog/stream-util
The helper class for working with Java 8 streams
https://github.com/megaprog/stream-util
collections java java8 streams-api
Last synced: 5 months ago
JSON representation
The helper class for working with Java 8 streams
- Host: GitHub
- URL: https://github.com/megaprog/stream-util
- Owner: Megaprog
- License: apache-2.0
- Created: 2015-10-17T06:54:17.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2021-02-13T15:57:50.000Z (almost 5 years ago)
- Last Synced: 2025-08-12T19:45:07.144Z (5 months ago)
- Topics: collections, java, java8, streams-api
- Language: Java
- Size: 57.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://maven-badges.herokuapp.com/maven-central/org.jmmo/stream-util)
# Stream Utility
The helper class for working with Java 8 streams. It allows to create streams from Optional, from Supplier, from Matcher etc.
## How to use it?
To create stream from supplier function:
```java
Stream stream = StreamUtil.supply(() -> hasData() ? read() : null);
```
To create files stream (all files in directory and subdirectories):
```java
Stream files = StreamUtil.files("myDirectory");
```
To wrap lambdas throws checked exceptions:
```java
void method(int a, String b) throws IOException, InterruptedException { }
boolean isSomething(int a, String b) throws IOException, TimeoutException { return true; }
public void testUnchecked_Throw() throws Exception {
Stream.of(1)
.filter(i1 -> StreamUtil.unchecked(() -> isSomething(i1, "1")))
.forEach(i2 -> StreamUtil.unchecked(() -> method(i2, "2")));
}
```
To wrap lambdas throws InterruptedException:
```java
StreamUtil.uninterrupted(() -> Thread.sleep(1));
```
To logging expensive expressions:
```java
log.debug("Debugging of {}", LazyToString.of(() -> "some expensive expression"));
```