From 3575d5461e4b6e6c0d2cb118a161622c4dfe6f76 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 18 May 2017 13:27:46 +0200 Subject: [PATCH] DATAMONGO-1695 - Polishing. Javadoc. Variable names. Move off deprecated methods. Removed obsolete private method. --- .../data/mongodb/gridfs/GridFsResource.java | 6 ++++++ .../data/mongodb/gridfs/GridFsTemplate.java | 15 ++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsResource.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsResource.java index 0a07854bd..d839c57ff 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsResource.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsResource.java @@ -46,6 +46,12 @@ public class GridFsResource extends InputStreamResource { this(file, new ByteArrayInputStream(new byte[] {})); } + /** + * Creates a new {@link GridFsResource} from the given {@link GridFSDBFile} and {@link InputStream}. + * + * @param file must not be {@literal null}. + * @param inputStream must not be {@literal null}. + */ public GridFsResource(GridFSFile file, InputStream inputStream) { super(inputStream); diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java index a5df3598c..319386de5 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java @@ -162,9 +162,10 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver Assert.notNull(content, "InputStream must not be null!"); - GridFSUploadOptions opts = new GridFSUploadOptions(); + GridFSUploadOptions options = new GridFSUploadOptions(); Document mData = new Document(); + if (StringUtils.hasText(contentType)) { mData.put(GridFsResource.CONTENT_TYPE_FIELD, contentType); } @@ -173,9 +174,9 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver mData.putAll(metadata); } - opts.metadata(mData); + options.metadata(mData); - return getGridFs().uploadFromStream(filename, content, opts); + return getGridFs().uploadFromStream(filename, content, options); } /* @@ -228,7 +229,7 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver public GridFsResource getResource(String location) { GridFSFile file = findOne(query(whereFilename().is(location))); - return file != null ? new GridFsResource(file, getGridFs().openDownloadStreamByName(location)) : null; + return file != null ? new GridFsResource(file, getGridFs().openDownloadStream(location)) : null; } /* @@ -249,7 +250,7 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver List resources = new ArrayList(); for (GridFSFile file : files) { - resources.add(new GridFsResource(file, getGridFs().openDownloadStreamByName(file.getFilename()))); + resources.add(new GridFsResource(file, getGridFs().openDownloadStream(file.getFilename()))); } return resources.toArray(new GridFsResource[resources.size()]); @@ -258,10 +259,6 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver return new GridFsResource[] { getResource(locationPattern) }; } - private Document getMappedQuery(Query query) { - return query == null ? new Query().getQueryObject() : getMappedQuery(query.getQueryObject()); - } - private Document getMappedQuery(Document query) { return query == null ? null : queryMapper.getMappedObject(query, Optional.empty()); }