@Override public void onComplete() { if (onShouldRead()) { emitNext(sink); } } }
/** * Stores the given content into a file with the given name. * * @param content must not be {@literal null}. * @param filename must not be {@literal null} or empty. * @return a {@link Mono} emitting the {@link ObjectId} of the {@link com.mongodb.client.gridfs.model.GridFSFile} just * created. */ default Mono<ObjectId> store(Publisher<DataBuffer> content, String filename) { return store(content, filename, (Object) null); }
@Override public void onComplete() { AsyncInputStreamAdapter.this.complete = true; terminatePendingReads(); } }
public GridFsResource getResource(String location) { return Optional.ofNullable(findOne(query(whereFilename().is(location)))) // .map(this::getResource) // .orElseGet(() -> GridFsResource.absent(location)); }
@Override public Flux<ReactiveGridFsResource> getResources(String locationPattern) { if (!StringUtils.hasText(locationPattern)) { return Flux.empty(); } AntPath path = new AntPath(locationPattern); if (path.isPattern()) { Flux<GridFSFile> files = find(query(whereFilename().regex(path.toRegex()))); return files.flatMap(this::getResource); } return getResource(locationPattern).flux(); }
@Override public Mono<ReactiveGridFsResource> getResource(String location) { Assert.notNull(location, "Filename must not be null!"); return findOne(query(whereFilename().is(location))).flatMap(this::getResource) .defaultIfEmpty(ReactiveGridFsResource.absent(location)); }
public ObjectId store(InputStream content, String filename) { return store(content, filename, (Object) null); }
boolean onShouldRead() { return !isClosed() && getDemand() > 0 && onWantRead(); }
@Override public Mono<ReactiveGridFsResource> getResource(GridFSFile file) { Assert.notNull(file, "GridFSFile must not be null!"); return Mono.fromSupplier(() -> { GridFSDownloadStream stream = getGridFs().openDownloadStream(file.getObjectId()); return new ReactiveGridFsResource(file, BinaryStreamAdapters.toPublisher(stream, dataBufferFactory)); }); }
/** * Creates a {@link GridFsCriteria} for restrictions on the file's metadata. * * @return */ public static GridFsCriteria whereMetaData() { return new GridFsCriteria("metadata"); }
@Override public InputStream getInputStream() throws IOException, IllegalStateException { verifyExists(); return super.getInputStream(); }
/** * Returns whether the path is a pattern. * * @return */ public boolean isPattern() { String path = stripPrefix(this.path); return (path.indexOf('*') != -1 || path.indexOf('?') != -1); }
@Override public long contentLength() throws IOException { verifyExists(); return file.getLength(); }
void request(FluxSink<DataBuffer> sink, long n) { Operators.addCap(DEMAND, this, n); if (onShouldRead()) { emitNext(sink); } }
/** * Stores the given content into a file applying the given metadata. * * @param content must not be {@literal null}. * @param metadata can be {@literal null}. * @return a {@link Mono} emitting the {@link ObjectId} of the {@link com.mongodb.client.gridfs.model.GridFSFile} just * created. */ default Mono<ObjectId> store(Publisher<DataBuffer> content, @Nullable Object metadata) { return store(content, null, metadata); }
@Override public void onError(Throwable t) { if (AsyncInputStreamAdapter.this.cancelled || AsyncInputStreamAdapter.this.complete) { Operators.onErrorDropped(t, AsyncInputStreamAdapter.this.subscriberContext); return; } AsyncInputStreamAdapter.this.error = t; AsyncInputStreamAdapter.this.complete = true; terminatePendingReads(); }
/** * Creates a {@link GridFsCriteria} for restrictions on the file's name. * * @return */ public static GridFsCriteria whereFilename() { return new GridFsCriteria("filename"); }
@Override public long contentLength() throws IOException { verifyExists(); return file.getLength(); }
/** * Stores the given content into a file applying the given metadata. * * @param content must not be {@literal null}. * @param metadata can be {@literal null}. * @return a {@link Mono} emitting the {@link ObjectId} of the {@link com.mongodb.client.gridfs.model.GridFSFile} just * created. */ default Mono<ObjectId> store(Publisher<DataBuffer> content, @Nullable Document metadata) { return store(content, null, metadata); }
/** * Stores the given content into a file with the given name and content type. * * @param content must not be {@literal null}. * @param filename must not be {@literal null} or empty. * @param contentType can be {@literal null}. * @return a {@link Mono} emitting the {@link ObjectId} of the {@link com.mongodb.client.gridfs.model.GridFSFile} just * created. */ default Mono<ObjectId> store(Publisher<DataBuffer> content, @Nullable String filename, @Nullable String contentType) { return store(content, filename, contentType, (Object) null); }