https://github.com/fmbenhassine/unix-stream
Turn Java 8 Streams into Unix like pipelines
https://github.com/fmbenhassine/unix-stream
java-8 pipeline unix unix-command
Last synced: 16 days ago
JSON representation
Turn Java 8 Streams into Unix like pipelines
- Host: GitHub
- URL: https://github.com/fmbenhassine/unix-stream
- Owner: fmbenhassine
- License: mit
- Created: 2015-10-07T04:37:57.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-12-12T22:07:13.000Z (over 6 years ago)
- Last Synced: 2025-04-10T00:41:29.917Z (16 days ago)
- Topics: java-8, pipeline, unix, unix-command
- Language: Java
- Homepage: https://github.com/benas/unix-stream/wiki
- Size: 1.73 MB
- Stars: 123
- Watchers: 11
- Forks: 15
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# What is UnixStream?
[](https://gitter.im/benas/unix-stream?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[](http://opensource.org/licenses/MIT)
[](http://search.maven.org/#artifactdetails|io.github.benas|unix-stream|0.5|)
[](https://travis-ci.org/benas/unix-stream)
[](https://coveralls.io/github/benas/unix-stream?branch=master)UnixStream is an extension of the Java 8 Stream API to process data pipelines the Unix way.
It provides a set of components that mimic Unix commands (and more).# Features
* 100% compatible with Java 8 Streams
* Intuitive, flexible and extensible API
* A toolbox of reusable components
* No dependencies
* Free and open source# How to use it?
You can use UnixStream in 3 ways:
#### 1. Either unixify your stream and process it the unix way:
```java
Stream stream = Stream.of("foo", "bar", "bar", "baz");UnixStream.unixify(stream)
.grep("a")
.sort()
.uniq()
.nl()
.to(stdOut());
// prints:
// 1 bar
// 2 baz
```#### 2. Or write your pipelines as you read them:
```java
// cat input.txt | grep a | sort | uniq | nl > output.txtUnixStream.cat("input.txt")
.pipe(grep("a"))
.pipe(sort())
.pipe(uniq())
.pipe(nl())
.to(file("output.txt"));
```#### 3. Or use functions and predicates provided by UnixStream with the standard Stream API:
```java
Stream.of("1,foo", "2,bar")
.filter(grep("a"))
.map(cut(",", 2))
.forEach(System.out::println);
//prints:
//bar
```# Where to find it?
Add the following maven dependency to your project:
```xml
io.github.benas
unix-stream
0.5```
Or [download the jar file](https://oss.sonatype.org/content/groups/public/io/github/benas/unix-stream/0.5/unix-stream-0.5.jar) and add it to your application's classpath.
# Components library
UnixStream provides a toolbox of reusable components that mimic Unix commands (and more).
Components are inspired by the [Unix philosophy](https://en.wikipedia.org/wiki/Unix_philosophy#Mike_Gancarz:_The_UNIX_Philosophy) and are intended to be:* Small
* Portable
* Do one thing and do it well
* Side-effect freeHere are some of the built-in components:

You can find a complete reference of components in the [wiki page](https://github.com/benas/unix-stream/wiki).
# How to extend it ?
The `Stage` interface represents a stage of the pipeline:
```java
public interface Stage {Stream apply(Stream input);
}
```All built-in components are implemented as filters/transformers through this interface.
You can of course implement this interface to create your own components.# Contribution
There are a lot of options for current components that are not implemented yet.
You are welcome to improve existing components or add new ones to make the toolbox as rich as possible!# License
UnixStream is released under the [MIT License](http://opensource.org/licenses/mit-license.php/):
```
The MIT LicenseCopyright (c) 2018, Mahmoud Ben Hassine ([email protected])
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
```