/*
 * Copyright 2014 Red Hat, Inc.
 *
 * Red Hat licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package io.vertx.reactivex.ext.mongo;

import io.vertx.reactivex.RxHelper;
import io.vertx.reactivex.ObservableHelper;
import io.vertx.reactivex.FlowableHelper;
import io.vertx.reactivex.impl.AsyncResultMaybe;
import io.vertx.reactivex.impl.AsyncResultSingle;
import io.vertx.reactivex.impl.AsyncResultCompletable;
import io.vertx.reactivex.WriteStreamObserver;
import io.vertx.reactivex.WriteStreamSubscriber;
import java.util.Map;
import java.util.Set;
import java.util.List;
import java.util.Iterator;
import java.util.function.Function;
import java.util.stream.Collectors;
import io.vertx.core.Handler;
import io.vertx.core.AsyncResult;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import io.vertx.lang.rx.RxGen;
import io.vertx.lang.rx.TypeArg;
import io.vertx.lang.rx.MappingIterator;


@RxGen(io.vertx.ext.mongo.MongoGridFsClient.class)
public class MongoGridFsClient {

  @Override
  public String toString() {
    return delegate.toString();
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    MongoGridFsClient that = (MongoGridFsClient) o;
    return delegate.equals(that.delegate);
  }
  
  @Override
  public int hashCode() {
    return delegate.hashCode();
  }

  public static final TypeArg<MongoGridFsClient> __TYPE_ARG = new TypeArg<>(    obj -> new MongoGridFsClient((io.vertx.ext.mongo.MongoGridFsClient) obj),
    MongoGridFsClient::getDelegate
  );

  private final io.vertx.ext.mongo.MongoGridFsClient delegate;
  
  public MongoGridFsClient(io.vertx.ext.mongo.MongoGridFsClient delegate) {
    this.delegate = delegate;
  }

  public MongoGridFsClient(Object delegate) {
    this.delegate = (io.vertx.ext.mongo.MongoGridFsClient)delegate;
  }

  public io.vertx.ext.mongo.MongoGridFsClient getDelegate() {
    return delegate;
  }

  
Deletes a file by it's ID
Params:
  • id – the identifier of the file
  • resultHandler – will be called when the file is deleted
Returns:
/** * Deletes a file by it's ID * @param id the identifier of the file * @param resultHandler will be called when the file is deleted * @return */
public io.vertx.reactivex.ext.mongo.MongoGridFsClient delete(String id, Handler<AsyncResult<Void>> resultHandler) { delegate.delete(id, resultHandler); return this; }
Deletes a file by it's ID
Params:
  • id – the identifier of the file
Returns:
/** * Deletes a file by it's ID * @param id the identifier of the file * @return */
public io.vertx.reactivex.ext.mongo.MongoGridFsClient delete(String id) { return delete(id, ar -> { }); }
Deletes a file by it's ID
Params:
  • id – the identifier of the file
Returns:
/** * Deletes a file by it's ID * @param id the identifier of the file * @return */
public io.reactivex.Completable rxDelete(String id) { return AsyncResultCompletable.toCompletable($handler -> { delete(id, $handler); }); } public io.vertx.reactivex.ext.mongo.MongoGridFsClient downloadByFileName(io.vertx.reactivex.core.streams.WriteStream<io.vertx.reactivex.core.buffer.Buffer> stream, String fileName, Handler<AsyncResult<Long>> resultHandler) { delegate.downloadByFileName(stream.getDelegate(), fileName, resultHandler); return this; } public io.vertx.reactivex.ext.mongo.MongoGridFsClient downloadByFileName(io.vertx.reactivex.core.streams.WriteStream<io.vertx.reactivex.core.buffer.Buffer> stream, String fileName) { return downloadByFileName(stream, fileName, ar -> { }); } public io.reactivex.Single<Long> rxDownloadByFileName(io.vertx.reactivex.core.streams.WriteStream<io.vertx.reactivex.core.buffer.Buffer> stream, String fileName) { return AsyncResultSingle.toSingle($handler -> { downloadByFileName(stream, fileName, $handler); }); } public io.vertx.reactivex.ext.mongo.MongoGridFsClient downloadByFileNameWithOptions(io.vertx.reactivex.core.streams.WriteStream<io.vertx.reactivex.core.buffer.Buffer> stream, String fileName, io.vertx.ext.mongo.GridFsDownloadOptions options, Handler<AsyncResult<Long>> resultHandler) { delegate.downloadByFileNameWithOptions(stream.getDelegate(), fileName, options, resultHandler); return this; } public io.vertx.reactivex.ext.mongo.MongoGridFsClient downloadByFileNameWithOptions(io.vertx.reactivex.core.streams.WriteStream<io.vertx.reactivex.core.buffer.Buffer> stream, String fileName, io.vertx.ext.mongo.GridFsDownloadOptions options) { return downloadByFileNameWithOptions(stream, fileName, options, ar -> { }); } public io.reactivex.Single<Long> rxDownloadByFileNameWithOptions(io.vertx.reactivex.core.streams.WriteStream<io.vertx.reactivex.core.buffer.Buffer> stream, String fileName, io.vertx.ext.mongo.GridFsDownloadOptions options) { return AsyncResultSingle.toSingle($handler -> { downloadByFileNameWithOptions(stream, fileName, options, $handler); }); } public io.vertx.reactivex.ext.mongo.MongoGridFsClient downloadById(io.vertx.reactivex.core.streams.WriteStream<io.vertx.reactivex.core.buffer.Buffer> stream, String id, Handler<AsyncResult<Long>> resultHandler) { delegate.downloadById(stream.getDelegate(), id, resultHandler); return this; } public io.vertx.reactivex.ext.mongo.MongoGridFsClient downloadById(io.vertx.reactivex.core.streams.WriteStream<io.vertx.reactivex.core.buffer.Buffer> stream, String id) { return downloadById(stream, id, ar -> { }); } public io.reactivex.Single<Long> rxDownloadById(io.vertx.reactivex.core.streams.WriteStream<io.vertx.reactivex.core.buffer.Buffer> stream, String id) { return AsyncResultSingle.toSingle($handler -> { downloadById(stream, id, $handler); }); }
Downloads a file.
Params:
  • fileName – the name of the file to download
  • resultHandler – called when the file is downloaded and returns the length in bytes
Returns:
/** * Downloads a file. * @param fileName the name of the file to download * @param resultHandler called when the file is downloaded and returns the length in bytes * @return */
public io.vertx.reactivex.ext.mongo.MongoGridFsClient downloadFile(String fileName, Handler<AsyncResult<Long>> resultHandler) { delegate.downloadFile(fileName, resultHandler); return this; }
Downloads a file.
Params:
  • fileName – the name of the file to download
Returns:
/** * Downloads a file. * @param fileName the name of the file to download * @return */
public io.vertx.reactivex.ext.mongo.MongoGridFsClient downloadFile(String fileName) { return downloadFile(fileName, ar -> { }); }
Downloads a file.
Params:
  • fileName – the name of the file to download
Returns:
/** * Downloads a file. * @param fileName the name of the file to download * @return */
public io.reactivex.Single<Long> rxDownloadFile(String fileName) { return AsyncResultSingle.toSingle($handler -> { downloadFile(fileName, $handler); }); }
Downloads a file and gives it a new name.
Params:
  • fileName – the name of the file to download
  • newFileName – the name the file should be saved as
  • resultHandler – called when the file is downloaded and returns the length in bytes
Returns:
/** * Downloads a file and gives it a new name. * @param fileName the name of the file to download * @param newFileName the name the file should be saved as * @param resultHandler called when the file is downloaded and returns the length in bytes * @return */
public io.vertx.reactivex.ext.mongo.MongoGridFsClient downloadFileAs(String fileName, String newFileName, Handler<AsyncResult<Long>> resultHandler) { delegate.downloadFileAs(fileName, newFileName, resultHandler); return this; }
Downloads a file and gives it a new name.
Params:
  • fileName – the name of the file to download
  • newFileName – the name the file should be saved as
Returns:
/** * Downloads a file and gives it a new name. * @param fileName the name of the file to download * @param newFileName the name the file should be saved as * @return */
public io.vertx.reactivex.ext.mongo.MongoGridFsClient downloadFileAs(String fileName, String newFileName) { return downloadFileAs(fileName, newFileName, ar -> { }); }
Downloads a file and gives it a new name.
Params:
  • fileName – the name of the file to download
  • newFileName – the name the file should be saved as
Returns:
/** * Downloads a file and gives it a new name. * @param fileName the name of the file to download * @param newFileName the name the file should be saved as * @return */
public io.reactivex.Single<Long> rxDownloadFileAs(String fileName, String newFileName) { return AsyncResultSingle.toSingle($handler -> { downloadFileAs(fileName, newFileName, $handler); }); }
Downloads a file using the ID generated by GridFs.
Params:
  • id – the GridFs Object ID of the file to download
  • fileName –
  • resultHandler – called when the file is downloaded and returns the length in bytes
Returns:
/** * Downloads a file using the ID generated by GridFs. * @param id the GridFs Object ID of the file to download * @param fileName * @param resultHandler called when the file is downloaded and returns the length in bytes * @return */
public io.vertx.reactivex.ext.mongo.MongoGridFsClient downloadFileByID(String id, String fileName, Handler<AsyncResult<Long>> resultHandler) { delegate.downloadFileByID(id, fileName, resultHandler); return this; }
Downloads a file using the ID generated by GridFs.
Params:
  • id – the GridFs Object ID of the file to download
  • fileName –
Returns:
/** * Downloads a file using the ID generated by GridFs. * @param id the GridFs Object ID of the file to download * @param fileName * @return */
public io.vertx.reactivex.ext.mongo.MongoGridFsClient downloadFileByID(String id, String fileName) { return downloadFileByID(id, fileName, ar -> { }); }
Downloads a file using the ID generated by GridFs.
Params:
  • id – the GridFs Object ID of the file to download
  • fileName –
Returns:
/** * Downloads a file using the ID generated by GridFs. * @param id the GridFs Object ID of the file to download * @param fileName * @return */
public io.reactivex.Single<Long> rxDownloadFileByID(String id, String fileName) { return AsyncResultSingle.toSingle($handler -> { downloadFileByID(id, fileName, $handler); }); }
Drops the entire file bucket with all of its contents
Params:
  • resultHandler – called when the bucket is dropped
Returns:
/** * Drops the entire file bucket with all of its contents * @param resultHandler called when the bucket is dropped * @return */
public io.vertx.reactivex.ext.mongo.MongoGridFsClient drop(Handler<AsyncResult<Void>> resultHandler) { delegate.drop(resultHandler); return this; }
Drops the entire file bucket with all of its contents
Returns:
/** * Drops the entire file bucket with all of its contents * @return */
public io.vertx.reactivex.ext.mongo.MongoGridFsClient drop() { return drop(ar -> { }); }
Drops the entire file bucket with all of its contents
Returns:
/** * Drops the entire file bucket with all of its contents * @return */
public io.reactivex.Completable rxDrop() { return AsyncResultCompletable.toCompletable($handler -> { drop($handler); }); }
Finds all file ids in the bucket
Params:
  • resultHandler – called when the list of file ids is available
Returns:
/** * Finds all file ids in the bucket * @param resultHandler called when the list of file ids is available * @return */
public io.vertx.reactivex.ext.mongo.MongoGridFsClient findAllIds(Handler<AsyncResult<List<String>>> resultHandler) { delegate.findAllIds(resultHandler); return this; }
Finds all file ids in the bucket
Returns:
/** * Finds all file ids in the bucket * @return */
public io.vertx.reactivex.ext.mongo.MongoGridFsClient findAllIds() { return findAllIds(ar -> { }); }
Finds all file ids in the bucket
Returns:
/** * Finds all file ids in the bucket * @return */
public io.reactivex.Single<List<String>> rxFindAllIds() { return AsyncResultSingle.toSingle($handler -> { findAllIds($handler); }); }
Finds all file ids that match a query.
Params:
  • query – a bson query expressed as json that will be used to match files
  • resultHandler – called when the list of file ids is available
Returns:
/** * Finds all file ids that match a query. * @param query a bson query expressed as json that will be used to match files * @param resultHandler called when the list of file ids is available * @return */
public io.vertx.reactivex.ext.mongo.MongoGridFsClient findIds(JsonObject query, Handler<AsyncResult<List<String>>> resultHandler) { delegate.findIds(query, resultHandler); return this; }
Finds all file ids that match a query.
Params:
  • query – a bson query expressed as json that will be used to match files
Returns:
/** * Finds all file ids that match a query. * @param query a bson query expressed as json that will be used to match files * @return */
public io.vertx.reactivex.ext.mongo.MongoGridFsClient findIds(JsonObject query) { return findIds(query, ar -> { }); }
Finds all file ids that match a query.
Params:
  • query – a bson query expressed as json that will be used to match files
Returns:
/** * Finds all file ids that match a query. * @param query a bson query expressed as json that will be used to match files * @return */
public io.reactivex.Single<List<String>> rxFindIds(JsonObject query) { return AsyncResultSingle.toSingle($handler -> { findIds(query, $handler); }); } public io.vertx.reactivex.ext.mongo.MongoGridFsClient uploadByFileName(io.vertx.reactivex.core.streams.ReadStream<io.vertx.reactivex.core.buffer.Buffer> stream, String fileName, Handler<AsyncResult<String>> resultHandler) { delegate.uploadByFileName(stream.getDelegate(), fileName, resultHandler); return this; } public io.vertx.reactivex.ext.mongo.MongoGridFsClient uploadByFileName(io.vertx.reactivex.core.streams.ReadStream<io.vertx.reactivex.core.buffer.Buffer> stream, String fileName) { return uploadByFileName(stream, fileName, ar -> { }); } public io.reactivex.Single<String> rxUploadByFileName(io.vertx.reactivex.core.streams.ReadStream<io.vertx.reactivex.core.buffer.Buffer> stream, String fileName) { return AsyncResultSingle.toSingle($handler -> { uploadByFileName(stream, fileName, $handler); }); } public io.vertx.reactivex.ext.mongo.MongoGridFsClient uploadByFileName(io.reactivex.Flowable<io.vertx.reactivex.core.buffer.Buffer> stream, String fileName, Handler<AsyncResult<String>> resultHandler) { delegate.uploadByFileName(io.vertx.reactivex.impl.ReadStreamSubscriber.asReadStream(stream, obj -> obj.getDelegate()).resume(), fileName, resultHandler); return this; } public io.vertx.reactivex.ext.mongo.MongoGridFsClient uploadByFileName(io.reactivex.Flowable<io.vertx.reactivex.core.buffer.Buffer> stream, String fileName) { return uploadByFileName(stream, fileName, ar -> { }); } public io.reactivex.Single<String> rxUploadByFileName(io.reactivex.Flowable<io.vertx.reactivex.core.buffer.Buffer> stream, String fileName) { return AsyncResultSingle.toSingle($handler -> { uploadByFileName(stream, fileName, $handler); }); } public io.vertx.reactivex.ext.mongo.MongoGridFsClient uploadByFileNameWithOptions(io.vertx.reactivex.core.streams.ReadStream<io.vertx.reactivex.core.buffer.Buffer> stream, String fileName, io.vertx.ext.mongo.GridFsUploadOptions options, Handler<AsyncResult<String>> resultHandler) { delegate.uploadByFileNameWithOptions(stream.getDelegate(), fileName, options, resultHandler); return this; } public io.vertx.reactivex.ext.mongo.MongoGridFsClient uploadByFileNameWithOptions(io.vertx.reactivex.core.streams.ReadStream<io.vertx.reactivex.core.buffer.Buffer> stream, String fileName, io.vertx.ext.mongo.GridFsUploadOptions options) { return uploadByFileNameWithOptions(stream, fileName, options, ar -> { }); } public io.reactivex.Single<String> rxUploadByFileNameWithOptions(io.vertx.reactivex.core.streams.ReadStream<io.vertx.reactivex.core.buffer.Buffer> stream, String fileName, io.vertx.ext.mongo.GridFsUploadOptions options) { return AsyncResultSingle.toSingle($handler -> { uploadByFileNameWithOptions(stream, fileName, options, $handler); }); } public io.vertx.reactivex.ext.mongo.MongoGridFsClient uploadByFileNameWithOptions(io.reactivex.Flowable<io.vertx.reactivex.core.buffer.Buffer> stream, String fileName, io.vertx.ext.mongo.GridFsUploadOptions options, Handler<AsyncResult<String>> resultHandler) { delegate.uploadByFileNameWithOptions(io.vertx.reactivex.impl.ReadStreamSubscriber.asReadStream(stream, obj -> obj.getDelegate()).resume(), fileName, options, resultHandler); return this; } public io.vertx.reactivex.ext.mongo.MongoGridFsClient uploadByFileNameWithOptions(io.reactivex.Flowable<io.vertx.reactivex.core.buffer.Buffer> stream, String fileName, io.vertx.ext.mongo.GridFsUploadOptions options) { return uploadByFileNameWithOptions(stream, fileName, options, ar -> { }); } public io.reactivex.Single<String> rxUploadByFileNameWithOptions(io.reactivex.Flowable<io.vertx.reactivex.core.buffer.Buffer> stream, String fileName, io.vertx.ext.mongo.GridFsUploadOptions options) { return AsyncResultSingle.toSingle($handler -> { uploadByFileNameWithOptions(stream, fileName, options, $handler); }); }
Upload a file to gridfs
Params:
  • fileName – the name of the file to store in gridfs
  • resultHandler – the id of the file that was uploaded
Returns:
/** * Upload a file to gridfs * @param fileName the name of the file to store in gridfs * @param resultHandler the id of the file that was uploaded * @return */
public io.vertx.reactivex.ext.mongo.MongoGridFsClient uploadFile(String fileName, Handler<AsyncResult<String>> resultHandler) { delegate.uploadFile(fileName, resultHandler); return this; }
Upload a file to gridfs
Params:
  • fileName – the name of the file to store in gridfs
Returns:
/** * Upload a file to gridfs * @param fileName the name of the file to store in gridfs * @return */
public io.vertx.reactivex.ext.mongo.MongoGridFsClient uploadFile(String fileName) { return uploadFile(fileName, ar -> { }); }
Upload a file to gridfs
Params:
  • fileName – the name of the file to store in gridfs
Returns:
/** * Upload a file to gridfs * @param fileName the name of the file to store in gridfs * @return */
public io.reactivex.Single<String> rxUploadFile(String fileName) { return AsyncResultSingle.toSingle($handler -> { uploadFile(fileName, $handler); }); }
Upload a file to gridfs with options
Params:
  • fileName – the name of the file to store in gridfs
  • options – GridFsUploadOptions for specifying metadata and chunk size
  • resultHandler – the id of the file that was uploaded
Returns:
/** * Upload a file to gridfs with options * @param fileName the name of the file to store in gridfs * @param options {@link io.vertx.ext.mongo.GridFsUploadOptions} for specifying metadata and chunk size * @param resultHandler the id of the file that was uploaded * @return */
public io.vertx.reactivex.ext.mongo.MongoGridFsClient uploadFileWithOptions(String fileName, io.vertx.ext.mongo.GridFsUploadOptions options, Handler<AsyncResult<String>> resultHandler) { delegate.uploadFileWithOptions(fileName, options, resultHandler); return this; }
Upload a file to gridfs with options
Params:
  • fileName – the name of the file to store in gridfs
  • options – GridFsUploadOptions for specifying metadata and chunk size
Returns:
/** * Upload a file to gridfs with options * @param fileName the name of the file to store in gridfs * @param options {@link io.vertx.ext.mongo.GridFsUploadOptions} for specifying metadata and chunk size * @return */
public io.vertx.reactivex.ext.mongo.MongoGridFsClient uploadFileWithOptions(String fileName, io.vertx.ext.mongo.GridFsUploadOptions options) { return uploadFileWithOptions(fileName, options, ar -> { }); }
Upload a file to gridfs with options
Params:
  • fileName – the name of the file to store in gridfs
  • options – GridFsUploadOptions for specifying metadata and chunk size
Returns:
/** * Upload a file to gridfs with options * @param fileName the name of the file to store in gridfs * @param options {@link io.vertx.ext.mongo.GridFsUploadOptions} for specifying metadata and chunk size * @return */
public io.reactivex.Single<String> rxUploadFileWithOptions(String fileName, io.vertx.ext.mongo.GridFsUploadOptions options) { return AsyncResultSingle.toSingle($handler -> { uploadFileWithOptions(fileName, options, $handler); }); }
Close the client and release its resources
/** * Close the client and release its resources */
public void close() { delegate.close(); } public static MongoGridFsClient newInstance(io.vertx.ext.mongo.MongoGridFsClient arg) { return arg != null ? new MongoGridFsClient(arg) : null; } }