public static AsyncOutputStream toAsyncOutputStream(final OutputStream outputStream) {
    """
	Converts a {@link OutputStream} into a {@link AsyncOutputStream}
	
	@param outputStream the OutputStream
	@return the AsyncOutputStream
    """
        notNull("outputStream", outputStream);
        return new AsyncOutputStream() {
            @Override
            public void write(final ByteBuffer srcByteBuffer, final SingleResultCallback<Integer> callback) {
                notNull("src", srcByteBuffer);
                notNull("callback", callback);
                if (!srcByteBuffer.hasRemaining()) {
                    callback.onResult(-1, null);
                    return;
                }

                int amount = srcByteBuffer.remaining();
                byte[] bytes = new byte[amount];
                try {
                    srcByteBuffer.get(bytes);
                    outputStream.write(bytes);
                } catch (Throwable t) {
                    callback.onResult(null, new MongoGridFSException("Error reading from input stream", t));
                    return;
                }
                callback.onResult(amount, null);
            }

            @Override
            public void close(final SingleResultCallback<Void> callback) {
                try {
                    outputStream.close();
                } catch (Throwable t) {
                    callback.onResult(null, new MongoGridFSException("Error closing from output stream", t));
                    return;
                }
                callback.onResult(null, null);
            }
        };
    }
public static AsyncOutputStream toAsyncOutputStream(final OutputStream outputStream) {
        notNull("outputStream", outputStream);
        return new AsyncOutputStream() {
            @Override
            public void write(final ByteBuffer srcByteBuffer, final SingleResultCallback<Integer> callback) {
                notNull("src", srcByteBuffer);
                notNull("callback", callback);
                if (!srcByteBuffer.hasRemaining()) {
                    callback.onResult(-1, null);
                    return;
                }

                int amount = srcByteBuffer.remaining();
                byte[] bytes = new byte[amount];
                try {
                    srcByteBuffer.get(bytes);
                    outputStream.write(bytes);
                } catch (Throwable t) {
                    callback.onResult(null, new MongoGridFSException("Error reading from input stream", t));
                    return;
                }
                callback.onResult(amount, null);
            }

            @Override
            public void close(final SingleResultCallback<Void> callback) {
                try {
                    outputStream.close();
                } catch (Throwable t) {
                    callback.onResult(null, new MongoGridFSException("Error closing from output stream", t));
                    return;
                }
                callback.onResult(null, null);
            }
        };
    }
public static AsyncOutputStream toAsyncOutputStream ( final OutputStream outputStream ) { notNull ( "outputStream" , outputStream ) ; return new AsyncOutputStream ( ) { @ Override public void write ( final ByteBuffer srcByteBuffer , final SingleResultCallback < Integer > callback ) { notNull ( "src" , srcByteBuffer ) ; notNull ( "callback" , callback ) ; if ( ! srcByteBuffer . hasRemaining ( ) ) { callback . onResult ( - 1 , null ) ; return ; } int amount = srcByteBuffer . remaining ( ) ; byte [ ] bytes = new byte [ amount ] ; try { srcByteBuffer . get ( bytes ) ; outputStream . write ( bytes ) ; } catch ( Throwable t ) { callback . onResult ( null , new MongoGridFSException ( "Error reading from input stream" , t ) ) ; return ; } callback . onResult ( amount , null ) ; } @ Override public void close ( final SingleResultCallback < Void > callback ) { try { outputStream . close ( ) ; } catch ( Throwable t ) { callback . onResult ( null , new MongoGridFSException ( "Error closing from output stream" , t ) ) ; return ; } callback . onResult ( null , null ) ; } } ; }
Converts a {@link OutputStream} into a {@link AsyncOutputStream}

@param outputStream the OutputStream
@return the AsyncOutputStream
Converts a { @link OutputStream } into a { @link AsyncOutputStream }