Skip to content

Commit 3575d54

Browse files
committed
DATAMONGO-1695 - Polishing.
Javadoc. Variable names. Move off deprecated methods. Removed obsolete private method.
1 parent 4fa09d8 commit 3575d54

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsResource.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ public GridFsResource(GridFSFile file) {
4646
this(file, new ByteArrayInputStream(new byte[] {}));
4747
}
4848

49+
/**
50+
* Creates a new {@link GridFsResource} from the given {@link GridFSDBFile} and {@link InputStream}.
51+
*
52+
* @param file must not be {@literal null}.
53+
* @param inputStream must not be {@literal null}.
54+
*/
4955
public GridFsResource(GridFSFile file, InputStream inputStream) {
5056

5157
super(inputStream);

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,10 @@ public ObjectId store(InputStream content, String filename, String contentType,
162162

163163
Assert.notNull(content, "InputStream must not be null!");
164164

165-
GridFSUploadOptions opts = new GridFSUploadOptions();
165+
GridFSUploadOptions options = new GridFSUploadOptions();
166166

167167
Document mData = new Document();
168+
168169
if (StringUtils.hasText(contentType)) {
169170
mData.put(GridFsResource.CONTENT_TYPE_FIELD, contentType);
170171
}
@@ -173,9 +174,9 @@ public ObjectId store(InputStream content, String filename, String contentType,
173174
mData.putAll(metadata);
174175
}
175176

176-
opts.metadata(mData);
177+
options.metadata(mData);
177178

178-
return getGridFs().uploadFromStream(filename, content, opts);
179+
return getGridFs().uploadFromStream(filename, content, options);
179180
}
180181

181182
/*
@@ -228,7 +229,7 @@ public ClassLoader getClassLoader() {
228229
public GridFsResource getResource(String location) {
229230

230231
GridFSFile file = findOne(query(whereFilename().is(location)));
231-
return file != null ? new GridFsResource(file, getGridFs().openDownloadStreamByName(location)) : null;
232+
return file != null ? new GridFsResource(file, getGridFs().openDownloadStream(location)) : null;
232233
}
233234

234235
/*
@@ -249,7 +250,7 @@ public GridFsResource[] getResources(String locationPattern) {
249250
List<GridFsResource> resources = new ArrayList<GridFsResource>();
250251

251252
for (GridFSFile file : files) {
252-
resources.add(new GridFsResource(file, getGridFs().openDownloadStreamByName(file.getFilename())));
253+
resources.add(new GridFsResource(file, getGridFs().openDownloadStream(file.getFilename())));
253254
}
254255

255256
return resources.toArray(new GridFsResource[resources.size()]);
@@ -258,10 +259,6 @@ public GridFsResource[] getResources(String locationPattern) {
258259
return new GridFsResource[] { getResource(locationPattern) };
259260
}
260261

261-
private Document getMappedQuery(Query query) {
262-
return query == null ? new Query().getQueryObject() : getMappedQuery(query.getQueryObject());
263-
}
264-
265262
private Document getMappedQuery(Document query) {
266263
return query == null ? null : queryMapper.getMappedObject(query, Optional.empty());
267264
}

0 commit comments

Comments
 (0)