A set of utilities for integrating Vert.x IO with Java IO.
In your pom.xml
add the Jitpack repository:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Then add a dependency on this library:
<dependency>
<groupId>com.github.cloudonix</groupId>
<artifactId>vertx-java.io</artifactId>
<version>1.4.0</version>
</dependency>
You need to read from a Vert.x IO stream and write into a Java OutputStream
, or read from a Java InputStream
and write into a Vert.x IO stream, when these utility classes are what you need:
-
OutputToReadStream
is an implementation of a JavaOutputStream
and a Vert.xReadStream<Buffer>
- data written to theOutputStream
API can be received from theReadStream<Buffer>
API. -
WriteToInputStream
is an implementation of a JavaInputStream
and a Vert.xWriteStream<Buffer>
- anything written to theWriteStream<Buffer>
API can be read from theInputStream
API.
In all cases, both Java's blocking semantics are observed (using the thread in which the blocking Java stream operation is executed) as well as Vert.x non-blocking API (using Context.runOnContext()
to execute Vert.x callbacks).
Using these classes and Vert.x and Java IO utility methods, it is also trivial to convert a Java InputStream
to a Vert.x ReadStream<Buffer>
or Java OutputStream
to a Vert.x WriteStream<Buffer>
and vice-versa. A minimal implementation is available as OutputToReadStream.wrap(InputStream)
and WriteInputStream.wrap(OutputStream)
- see the unit tests for usage examples and the source code as an example that you can customize for your needs.