Skip to content
Mahmoud Ben Hassine edited this page Feb 11, 2018 · 13 revisions

Welcome to UnixStream!

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:

Stream<String> 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

// cat input.txt | grep a | sort | uniq | nl > output.txt

UnixStream.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:

Stream.of("1,foo", "2,bar")
        .filter(grep("a"))
        .map(cut(",", 2))
        .forEach(System.out::println);
        
//prints:
//bar

Built-in components library

UnixStream provides a toolbox of reusable components that mimic Unix commands (and more). Components are inspired by the Unix philosophy and are intended to be:

  • Small
  • Portable
  • Do one thing and do it well
  • Side-effect free

You will find in this wiki a complete reference of all built-in components (see sidebar).

How to write components ?

The Stage interface represents a stage of the pipeline:

public interface Stage<I,O> {

  Stream<O> apply(Stream<I> input);

}

All built-in components are implemented as filters/transformers through this interface. You can implement this interface to create your own components.

Clone this wiki locally