public static int flush ( final BufferByteOutput < ? > output , final WritableByteChannel channel ) throws IOException { final ByteBuffer buffer = output . getTarget ( ) ; if ( buffer == null ) { return 0 ; } int written = 0 ; for ( buffer . flip ( ) ; buffer . hasRemaining ( ) ; ) { written += channel . write ( buffer ) ; } buffer . clear ( ) ; // position -> zero; limit -> capacity return written ; }
Flushes the internal byte buffer of given byte output to specified channel and returns the number of bytes written .