Stop Boundary I/O Streams Released!

What if the stream continues further without containing any sub-stream? In this case we can use the new released Stop Boundary Stream feature from the same library to ignore the rest of the stream after a boundary was reached.


To stop consuming a stream after a boundary was reached it is possible to use the StopBoundaryInputStream class and the convenience class StopBoundaryOutputStream to generate such a stream. The stop boundary streaming is still using a boundary to separate sub-streams, but when a stop boundary occurs the rest of the input stream is ignored.

Let's take a look at a simple example: 

String[] values = {
    "abcde", "ABCDE", "12345"

byte[] boundary = "|".getBytes();
byte[] stopBoundary = "#".getBytes();

ByteArrayOutputStream bytes = new ByteArrayOutputStream();

StopBoundaryOutputStream out = new StopBoundaryOutputStream(bytes, boundary, stopBoundary);

for (String s : values) {
out.write("xyz".getBytes());    // some junk at the end

//System.out.println(bytes);    // prints `abcde|ABCDE|12345|#xyz`

StopBoundaryInputStream in = new StopBoundaryInputStream(
        new ByteArrayInputStream(bytes.toByteArray()), boundary, stopBoundary);

for (InputStream is : in) {
    int b;
    while ((b = != -1) {
        System.out.print((char) b);

// close streams...

The code above prints:


Previous post about the library: Boundary I/O Streams Released!

All about:

Happy streaming!