@ -227,9 +227,7 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver
* @see org . springframework . core . io . ResourceLoader # getResource ( java . lang . String )
* @see org . springframework . core . io . ResourceLoader # getResource ( java . lang . String )
* /
* /
public GridFsResource getResource ( String location ) {
public GridFsResource getResource ( String location ) {
return Optional . ofNullable ( findOne ( query ( whereFilename ( ) . is ( location ) ) ) ) . map ( this : : getResource ) . orElse ( null ) ;
GridFSFile file = findOne ( query ( whereFilename ( ) . is ( location ) ) ) ;
return file ! = null ? getResource ( file ) : null ;
}
}
/ *
/ *
@ -238,6 +236,8 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver
* /
* /
public GridFsResource getResource ( GridFSFile file ) {
public GridFsResource getResource ( GridFSFile file ) {
Assert . notNull ( file , "GridFSFile must not be null!" ) ;
return new GridFsResource ( file , getGridFs ( ) . openDownloadStream ( file . getFilename ( ) ) ) ;
return new GridFsResource ( file , getGridFs ( ) . openDownloadStream ( file . getFilename ( ) ) ) ;
}
}
@ -256,13 +256,13 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver
if ( path . isPattern ( ) ) {
if ( path . isPattern ( ) ) {
GridFSFindIterable files = find ( query ( whereFilename ( ) . regex ( path . toRegex ( ) ) ) ) ;
GridFSFindIterable files = find ( query ( whereFilename ( ) . regex ( path . toRegex ( ) ) ) ) ;
List < GridFsResource > resources = new ArrayList < GridFsResource > ( ) ;
List < GridFsResource > resources = new ArrayList < > ( ) ;
for ( GridFSFile file : files ) {
for ( GridFSFile file : files ) {
resources . add ( new GridFsResource ( file , getGridFs ( ) . openDownloadStream ( file . getFilename ( ) ) ) ) ;
resources . add ( new GridFsResource ( file , getGridFs ( ) . openDownloadStream ( file . getFilename ( ) ) ) ) ;
}
}
return resources . toArray ( new GridFsResource [ resources . size ( ) ] ) ;
return resources . toArray ( new GridFsResource [ 0 ] ) ;
}
}
return new GridFsResource [ ] { getResource ( locationPattern ) } ;
return new GridFsResource [ ] { getResource ( locationPattern ) } ;