com.mongodb.client.gridfs.model.GridFSDownloadOptions Java Examples

The following examples show how to use com.mongodb.client.gridfs.model.GridFSDownloadOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GridFSTest.java    From mongo-java-driver-rx with Apache License 2.0 6 votes vote down vote up
private void doDownloadByName(final BsonDocument arguments, final BsonDocument assertion) {
    Throwable error = null;
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    try {
        GridFSDownloadOptions options = new GridFSDownloadOptions();
        if (arguments.containsKey("options")) {
            int revision = arguments.getDocument("options").getInt32("revision").getValue();
            options.revision(revision);
        }

        gridFSBucket.downloadToStream(arguments.getString("filename").getValue(), toAsyncOutputStream(outputStream),
                options).timeout(30, SECONDS).toList().toBlocking().first();
        outputStream.close();
    } catch (Throwable e) {
        error = e;
    }
    if (assertion.containsKey("result")) {
        assertNull("Should not have thrown an exception", error);
        assertEquals(DatatypeConverter.printHexBinary(outputStream.toByteArray()).toLowerCase(),
                assertion.getDocument("result").getString("$hex").getValue());
    } else if (assertion.containsKey("error")) {
        assertNotNull("Should have thrown an exception", error);
    }
}
 
Example #2
Source File: GridFSBucketImpl.java    From mongo-java-driver-rx with Apache License 2.0 5 votes vote down vote up
@Override
public Observable<Long> downloadToStream(final String filename, final AsyncOutputStream destination,
                                        final GridFSDownloadOptions options) {
    return RxObservables.create(Observables.observe(new Block<SingleResultCallback<Long>>() {
        @Override
        public void apply(final SingleResultCallback<Long> callback) {
            wrapped.downloadToStream(filename, toCallbackAsyncOutputStream(destination), options, callback);
        }
    }), observableAdapter);
}
 
Example #3
Source File: GridFSBucketImpl.java    From mongo-java-driver-reactivestreams with Apache License 2.0 5 votes vote down vote up
@Override
public Publisher<Long> downloadToStream(final ClientSession clientSession, final String filename,
                                        final com.mongodb.reactivestreams.client.gridfs.AsyncOutputStream destination,
                                        final GridFSDownloadOptions options) {
    return new ObservableToPublisher<Long>(com.mongodb.async.client.Observables.observe(
            new Block<com.mongodb.async.SingleResultCallback<Long>>() {
                @Override
                public void apply(final com.mongodb.async.SingleResultCallback<Long> callback) {
                    wrapped.downloadToStream(clientSession.getWrapped(), filename, toCallbackAsyncOutputStream(destination), options,
                            callback);
                }
            }));
}
 
Example #4
Source File: GridFSBucketImpl.java    From mongo-java-driver-reactivestreams with Apache License 2.0 5 votes vote down vote up
@Override
public Publisher<Long> downloadToStream(final String filename,
                                        final com.mongodb.reactivestreams.client.gridfs.AsyncOutputStream destination,
                                        final GridFSDownloadOptions options) {
    return new ObservableToPublisher<Long>(com.mongodb.async.client.Observables.observe(
            new Block<com.mongodb.async.SingleResultCallback<Long>>() {
                @Override
                public void apply(final com.mongodb.async.SingleResultCallback<Long> callback) {
                    wrapped.downloadToStream(filename, toCallbackAsyncOutputStream(destination), options, callback);
                }
            }));
}
 
Example #5
Source File: GridFSBucketImpl.java    From mongo-java-driver-reactivestreams with Apache License 2.0 4 votes vote down vote up
@Override
public com.mongodb.reactivestreams.client.gridfs.GridFSDownloadStream openDownloadStream(final String filename) {
    return openDownloadStream(filename, new GridFSDownloadOptions());
}
 
Example #6
Source File: MongoGridFsClientImpl.java    From vertx-mongo-client with Apache License 2.0 4 votes vote down vote up
@Override
public Future<Long> downloadByFileNameWithOptions(WriteStream<Buffer> stream, String fileName, GridFsDownloadOptions options) {
  GridFSDownloadOptions downloadOptions = new GridFSDownloadOptions();
  GridFSDownloadPublisher publisher = bucket.downloadToPublisher(fileName, downloadOptions);
  return handleDownload(publisher, stream);
}
 
Example #7
Source File: GridFSBucketImpl.java    From mongo-java-driver-reactivestreams with Apache License 2.0 4 votes vote down vote up
@Override
public GridFSDownloadPublisher downloadToPublisher(final ClientSession clientSession, final String filename,
                                                 final GridFSDownloadOptions options) {
    return executeDownloadToPublisher(openDownloadStream(clientSession, filename, options));
}
 
Example #8
Source File: GridFSBucketImpl.java    From mongo-java-driver-reactivestreams with Apache License 2.0 4 votes vote down vote up
@Override
public GridFSDownloadPublisher downloadToPublisher(final String filename, final GridFSDownloadOptions options) {
    return executeDownloadToPublisher(openDownloadStream(filename, options));
}
 
Example #9
Source File: GridFSBucketImpl.java    From mongo-java-driver-reactivestreams with Apache License 2.0 4 votes vote down vote up
@Override
public Publisher<Long> downloadToStream(final ClientSession clientSession, final String filename,
                                        final com.mongodb.reactivestreams.client.gridfs.AsyncOutputStream destination) {
    return downloadToStream(clientSession, filename, destination, new GridFSDownloadOptions());
}
 
Example #10
Source File: GridFSBucketImpl.java    From mongo-java-driver-reactivestreams with Apache License 2.0 4 votes vote down vote up
@Override
public Publisher<Long> downloadToStream(final String filename,
                                        final com.mongodb.reactivestreams.client.gridfs.AsyncOutputStream destination) {
    return downloadToStream(filename, destination, new GridFSDownloadOptions());
}
 
Example #11
Source File: GridFSBucketImpl.java    From mongo-java-driver-reactivestreams with Apache License 2.0 4 votes vote down vote up
@Override
public com.mongodb.reactivestreams.client.gridfs.GridFSDownloadStream
openDownloadStream(final ClientSession clientSession, final String filename, final GridFSDownloadOptions options) {
    return new GridFSDownloadStreamImpl(wrapped.openDownloadStream(clientSession.getWrapped(), filename, options));
}
 
Example #12
Source File: GridFSBucketImpl.java    From mongo-java-driver-reactivestreams with Apache License 2.0 4 votes vote down vote up
@Override
public com.mongodb.reactivestreams.client.gridfs.GridFSDownloadStream
openDownloadStream(final ClientSession clientSession, final String filename) {
    return openDownloadStream(clientSession, filename, new GridFSDownloadOptions());
}
 
Example #13
Source File: GridFSBucketImpl.java    From mongo-java-driver-reactivestreams with Apache License 2.0 4 votes vote down vote up
@Override
public com.mongodb.reactivestreams.client.gridfs.GridFSDownloadStream
openDownloadStream(final String filename, final GridFSDownloadOptions options) {
    return new GridFSDownloadStreamImpl(wrapped.openDownloadStream(filename, options));
}
 
Example #14
Source File: GridFSBucketImpl.java    From mongo-java-driver-rx with Apache License 2.0 4 votes vote down vote up
@Override
public GridFSDownloadStream openDownloadStream(final String filename, final GridFSDownloadOptions options) {
    return new GridFSDownloadStreamImpl(wrapped.openDownloadStream(filename, options), observableAdapter);
}
 
Example #15
Source File: GridFSBucket.java    From mongo-java-driver-rx with Apache License 2.0 2 votes vote down vote up
/**
 * Opens a Stream from which the application can read the contents of the stored file specified by {@code filename} and the revision
 * in {@code options}.
 *
 * @param filename the name of the file to be downloaded
 * @param options  the download options
 * @return the stream
 */
GridFSDownloadStream openDownloadStream(String filename, GridFSDownloadOptions options);
 
Example #16
Source File: GridFSBucket.java    From mongo-java-driver-reactivestreams with Apache License 2.0 2 votes vote down vote up
/**
 * Downloads the contents of the stored file specified by {@code filename} and by the revision in {@code options} into the
 * {@code Publisher}.
 *
 * @param clientSession the client session with which to associate this operation
 * @param filename    the name of the file to be downloaded
 * @param options     the download options
 * @return a Publisher with a single element, representing the amount of data written
 * @mongodb.server.release 3.6
 * @since 1.13
 */
GridFSDownloadPublisher downloadToPublisher(ClientSession clientSession, String filename, GridFSDownloadOptions options);
 
Example #17
Source File: GridFSBucket.java    From mongo-java-driver-reactivestreams with Apache License 2.0 2 votes vote down vote up
/**
 * Downloads the contents of the stored file specified by {@code filename} and by the revision in {@code options} into the
 * {@code Publisher}.
 *
 * @param filename    the name of the file to be downloaded
 * @param options     the download options
 * @return a Publisher with a single element, representing the amount of data written
 * @since 1.13
 */
GridFSDownloadPublisher downloadToPublisher(String filename, GridFSDownloadOptions options);
 
Example #18
Source File: GridFSBucket.java    From mongo-java-driver-reactivestreams with Apache License 2.0 2 votes vote down vote up
/**
 * Downloads the contents of the stored file specified by {@code filename} and by the revision in {@code options} and writes the
 * contents to the {@code destination} Stream.
 *
 * @param clientSession the client session with which to associate this operation
 * @param filename    the name of the file to be downloaded
 * @param destination the destination stream
 * @param options     the download options
 * @return a Publisher with a single element, representing the amount of data written
 * @mongodb.server.release 3.6
 * @since 1.7
 * @deprecated prefer {@link GridFSBucket#downloadToPublisher(ClientSession, String, GridFSDownloadOptions)} instead
 */
@Deprecated
Publisher<Long> downloadToStream(ClientSession clientSession, String filename, AsyncOutputStream destination,
                                 GridFSDownloadOptions options);
 
Example #19
Source File: GridFSBucket.java    From mongo-java-driver-reactivestreams with Apache License 2.0 2 votes vote down vote up
/**
 * Downloads the contents of the stored file specified by {@code filename} and by the revision in {@code options} and writes the
 * contents to the {@code destination} Stream.
 *
 * @param filename    the name of the file to be downloaded
 * @param destination the destination stream
 * @param options     the download options
 * @return a Publisher with a single element, representing the amount of data written
 * @deprecated prefer {@link GridFSBucket#downloadToPublisher(String, GridFSDownloadOptions)} instead
 */
@Deprecated
Publisher<Long> downloadToStream(String filename, AsyncOutputStream destination, GridFSDownloadOptions options);
 
Example #20
Source File: GridFSBucket.java    From mongo-java-driver-reactivestreams with Apache License 2.0 2 votes vote down vote up
/**
 * Opens a {@code AsyncInputStream} from which the application can read the contents of the stored file specified by
 * {@code filename} and the revision in {@code options}.
 *
 * @param clientSession the client session with which to associate this operation
 * @param filename the name of the file to be downloaded
 * @param options  the download options
 * @return the stream
 * @mongodb.server.release 3.6
 * @since 1.7
 * @deprecated prefer {@link GridFSBucket#downloadToPublisher(ClientSession, String, GridFSDownloadOptions)} instead
 */
@Deprecated
GridFSDownloadStream openDownloadStream(ClientSession clientSession, String filename, GridFSDownloadOptions options);
 
Example #21
Source File: GridFSBucket.java    From mongo-java-driver-reactivestreams with Apache License 2.0 2 votes vote down vote up
/**
 * Opens a {@code AsyncInputStream} from which the application can read the contents of the stored file specified by {@code filename}
 * and the revision in {@code options}.
 *
 * @param filename the name of the file to be downloaded
 * @param options  the download options
 * @return the stream
 * @deprecated prefer {@link GridFSBucket#downloadToPublisher(String, GridFSDownloadOptions)} instead
 */
@Deprecated
GridFSDownloadStream openDownloadStream(String filename, GridFSDownloadOptions options);
 
Example #22
Source File: GridFSBucket.java    From mongo-java-driver-rx with Apache License 2.0 2 votes vote down vote up
/**
 * Downloads the contents of the stored file specified by {@code filename} and by the revision in {@code options} and writes the
 * contents to the {@code destination} Stream.
 *
 * @param filename    the name of the file to be downloaded
 * @param destination the destination stream
 * @param options     the download options
 * @return an observable with a single element, representing the amount of data written
 */
Observable<Long> downloadToStream(String filename, AsyncOutputStream destination, GridFSDownloadOptions options);