robe-common/src/main/java/io/robe/common/service/stream/BufferedStreamingOutput.java
@Override
    public void write(OutputStream output) throws IOException, WebApplicationException {
        //Write until available bytes are less than buffer.
        while (bufferedInputStream.available() > buffer.length) {
            bufferedInputStream.read(buffer);
            output.write(buffer);
        }
        //Write one more time to finish and exit.
        buffer = new byte[bufferedInputStream.available()];
        bufferedInputStream.read(buffer);
        output.write(buffer);
        bufferedInputStream.close();
    }
@Override
    public void write(OutputStream output) throws IOException, WebApplicationException {
        //Write until available bytes are less than buffer.
        while (bufferedInputStream.available() > buffer.length) {
            bufferedInputStream.read(buffer);
            output.write(buffer);
        }
        //Write one more time to finish and exit.
        buffer = new byte[bufferedInputStream.available()];
        bufferedInputStream.read(buffer);
        output.write(buffer);
        bufferedInputStream.close();
    }
@ Override public void write ( OutputStream output ) throws IOException , WebApplicationException { //Write until available bytes are less than buffer. while ( bufferedInputStream . available ( ) > buffer . length ) { bufferedInputStream . read ( buffer ) ; output . write ( buffer ) ; } //Write one more time to finish and exit. buffer = new byte [ bufferedInputStream . available ( ) ] ; bufferedInputStream . read ( buffer ) ; output . write ( buffer ) ; bufferedInputStream . close ( ) ; }
Called to write the message body.

@param output the OutputStream to write to.
@throws java.io.IOException                 if an IO error is encountered
@throws javax.ws.rs.WebApplicationException if a specific
HTTP error response needs to be produced. Only effective if thrown prior
to any bytes being written to output.
Called to write the message body .