Java Code Examples for com.mongodb.gridfs.GridFS#findOne()
The following examples show how to use
com.mongodb.gridfs.GridFS#findOne() .
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: MongoTest.java From pampas with Apache License 2.0 | 6 votes |
@Test @Ignore public void storeFile() throws IOException { File file = new File("/home/darrenfu/IdeaProjects/pampas/pampas-grpc/df/open/grpc/hello/grpc-test-229014610914606914.jar"); GridFS gridFS = new GridFS(datastore.getDB()); GridFSInputFile gridFSInputFile = gridFS.createFile(file); if (gridFS.findOne(file.getName()) == null) { gridFSInputFile.setId(file.getName()); gridFSInputFile.setMetaData(new BasicDBObject("version", "1.1.2")); gridFSInputFile.save(); } GridFSDBFile fsdbFile = gridFS.findOne(file.getName()); File newfile = new File("/home/darrenfu/IdeaProjects/pampas/pampas-grpc/df/open/grpc/hello/grpc-test-229014610914606914.new.jar"); if (newfile.exists()) { newfile.delete(); } newfile.createNewFile(); newfile.setWritable(true); fsdbFile.writeTo(newfile); System.out.println("done : " + fsdbFile.getFilename()); }
Example 2
Source File: Attachment.java From XBDD with Apache License 2.0 | 5 votes |
@GET @Path("/{id}") public Response getAttachment(@PathParam("id") final String id) throws IOException { final GridFS gridFS = new GridFS(this.mongoLegacyGrid); final GridFSDBFile file = gridFS.findOne(id); // log.info(file); if (file == null) { throw new WebApplicationException(404); } return Response.ok(org.apache.commons.io.IOUtils.toByteArray(file.getInputStream()), file.getContentType()).build(); }
Example 3
Source File: MapFileRepositoryCustomImpl.java From osiris with Apache License 2.0 | 5 votes |
private InputStream getMapFileByAppId(GridFS gridFS,String appIdentifier) throws MapFileNotExistsException{ InputStream fileMap=null; GridFSDBFile gridFSFileMap = gridFS.findOne(appIdentifier); if(gridFSFileMap==null){ throw new MapFileNotExistsException(); } fileMap=gridFSFileMap.getInputStream(); return fileMap; }
Example 4
Source File: GetMapFile.java From osiris with Apache License 2.0 | 4 votes |
private void removeFile(String appIdentifier,GridFS gridFS){ GridFSDBFile gridFSFileRemoveFile = gridFS.findOne(appIdentifier); if(gridFSFileRemoveFile!=null){ gridFS.remove(gridFSFileRemoveFile); } }
Example 5
Source File: GetMapFile.java From osiris with Apache License 2.0 | 4 votes |
private void removeFile(String appIdentifier,GridFS gridFS){ GridFSDBFile gridFSFileRemoveFile = gridFS.findOne(appIdentifier); if(gridFSFileRemoveFile!=null){ gridFS.remove(gridFSFileRemoveFile); } }
Example 6
Source File: ImportFilesRepositoryCustomImpl.java From osiris with Apache License 2.0 | 4 votes |
private void removeFile(String appIdentifier,GridFS gridFS){ GridFSDBFile gridFSFileRemoveFile = gridFS.findOne(appIdentifier); if(gridFSFileRemoveFile!=null){ gridFS.remove(gridFSFileRemoveFile); } }