Provide tools for simple transformations of stream data (e.g. map
, filter
, skip
).
For anything beyond simple transformations, consider using a Reactive Streams implementation like RxJava.
Import the io.github.tsegismont.streamutils.Streams
class.
Then use operators to transform streams.
Here’s an io.vertx.core.file.AsyncFile
transformation example:
// Splits file content into lines
RecordParser parser = RecordParser.newDelimited("\n", asyncFile);
// Transform line bytes to String
ReadStream<String> lines = Streams.map(parser, Buffer::toString);
// Get the line length
ReadStream<Integer> sizes = Streams.map(lines, String::length);
// Skip the first 50 lines
ReadStream<Integer> skipped = Streams.skip(sizes, 50);
// Limit result to 150 lines
ReadStream<Integer> result = Streams.limit(skipped, 150);
This library comes with a Groovy extension module that adds operators to Vert.x streams.
Here’s an io.vertx.core.file.AsyncFile
transformation example:
// Splits file content into lines
def parser = RecordParser.newDelimited("\n", asyncFile)
def result = parser
// Transform line bytes to String
.map { Buffer buffer -> buffer.toString() }
// Get the line length
.map { String line -> line.length() }
// Skip the first 50 lines
.skip(50)
// Limit result to 150 lines
.limit(150)
This library comes with Kotlin extension functions that add operators to Vert.x streams.
Here’s an io.vertx.core.file.AsyncFile
transformation example:
// Splits file content into lines
val parser = RecordParser.newDelimited("\n", asyncFile)
val result = parser
// Transform line bytes to String
.map(Buffer::toString)
// Get the line length
.map(String::length)
// Skip the first 50 lines
.skip(50)
// Limit result to 150 lines
.limit(150)