Migrate from GitHub to SourceForge with this tool. Check out all of SourceForge's recent improvements.
Close

Stopable InputStream

StopableInputStream can be used to stop passed Streams. For example if you like to pass in your web service a InputStream to a Blob-Object from a database, you can decorate original InputStream with StopableStream and stop the download process of the client anytime you wish.
Above you can see a code-snippet how an InputStream can be stopped from another thread.

Thread-1
InputStream is = 
//decorate inputStream with BlockingInputStream
final StopableInputStream_1x2 sis = StopableInputStream_1x2.of(is);
int b;
int index = 0;
try{
    do{
        b = sis.read();
        Thread.sleep(10);//slow down the read process
        System.out.println(index++ + " bytes read");
    }
    while(b!=-1);
}
finally{
    sis.close();
}
Thread-2
sis.stop();

See for examples in Example section