List of usage examples for com.mongodb.gridfs GridFSInputFile save
@Override public void save()
From source file:org.waveprotocol.wave.examples.fedone.persistence.mongodb.MongoDbStore.java
License:Apache License
@Override public boolean storeAttachment(String id, InputStream data) throws IOException { // This method returns false if the attachment is already in the database. // Unfortunately, as far as I can tell the only way to do this is to perform // a second database query. if (getAttachment(id) != null) { return false; } else {/*from w w w .j a v a 2 s. c o m*/ GridFSInputFile file = getAttachmentGrid().createFile(data, id); try { file.save(); } catch (MongoException e) { // Unfortunately, file.save() wraps any IOException thrown in a // 'MongoException'. Since the interface explicitly throws IOExceptions, // we unwrap any IOExceptions thrown. Throwable innerException = e.getCause(); if (innerException instanceof IOException) { throw (IOException) innerException; } else { throw e; } } return true; } }
From source file:rapture.blob.mongodb.GridFSBlobHandler.java
License:Open Source License
protected GridFSInputFile createNewFile(String docPath, InputStream content) { GridFSInputFile file = getGridFS().createFile(content, docPath); if (file != null) { file.save(); }//from w w w. j a va2 s . com return file; }
From source file:rmi_video.VideoServer.java
@Override public boolean addVideo(VideoData d) throws RemoteException { try {//w ww . j av a2s. c o m //Conexao com mongoDB MongoClient mongoClient = new MongoClient("localhost", 27017); DB db = mongoClient.getDB("VideoDatabase"); try (FileOutputStream fos = new FileOutputStream("/Users/philcr/Documents/" + d.getFileName())) { fos.write(d.getData()); } File videoFile = new File("/Users/philcr/Documents/" + d.getFileName()); GridFS gfsVideo = new GridFS(db, "video"); //Cria e salva o arquivo no DB pelo GridFS GridFSInputFile gfsFile = gfsVideo.createFile(videoFile); gfsFile.setId(new ObjectId()); //Utiliza a criao de ID do mongo gfsFile.put("videoId", d.getId()); //Utiliza nosso metodo de ID gfsFile.setFilename(d.getFileName()); gfsFile.save(); //Exclui o arquivo local boolean deletedFlag = videoFile.delete(); if (!deletedFlag) { System.err.println("File could not be deleted!"); } mongoClient.close(); return true; } catch (UnknownHostException ex) { Logger.getLogger(VideoServer.class.getName()).log(Level.SEVERE, null, ex); return false; } catch (FileNotFoundException ex) { Logger.getLogger(VideoServer.class.getName()).log(Level.SEVERE, null, ex); return false; } catch (IOException ex) { Logger.getLogger(VideoServer.class.getName()).log(Level.SEVERE, null, ex); return false; } }
From source file:se.inera.axel.shs.broker.messagestore.internal.MongoMessageStoreService.java
License:Open Source License
private void saveFile(String id, InputStream messageStream) { GridFSInputFile input = gridFs.createFile(messageStream, id, true); input.save(); }
From source file:streamflow.datastore.mongodb.impl.MongoGridFsFileContentDao.java
License:Apache License
@Override public FileContent save(FileContent entity) { GridFSInputFile inputFile = gridFs.createFile(entity.getData()); inputFile.setId(entity.getId());//from ww w . j a va 2 s .co m inputFile.save(); return entity; }
From source file:streamflow.datastore.mongodb.impl.MongoGridFsFileContentDao.java
License:Apache License
@Override public FileContent update(FileContent entity) { GridFSInputFile inputFile = gridFs.createFile(entity.getData()); inputFile.setId(entity.getId());/*from ww w . j a v a 2 s .co m*/ inputFile.save(); return entity; }
From source file:tango.mongo.ImageManager.java
License:Open Source License
public synchronized boolean saveInputImage(ObjectId xpId, ObjectId field_id, int fileRank, ImageHandler img, boolean flushImage) { if (img == null) return false; //IJ.log("file: "+img.getTitle()+" size:"+img.getSizeInMb()+ " available memory:"+Core.getAvailableMemory()+ " please free memory"); double scaleZ = img.getScaleZ(); String unit = img.getUnit();//from w w w . j a v a 2 s .co m String title = img.getTitle(); MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean(); try { byte[] data = img.getBinaryData(); if (data == null) { IJ.log("couldn't save image:" + title); return false; } if (flushImage) img.flush(); GridFSInputFile gfi = this.gfsField.get(xpId).createFile(data); data = null; gfi.setFilename(title); gfi.put("field_id", field_id); gfi.put("fileRank", fileRank); gfi.put("pixelDepth", scaleZ); gfi.put("unit", unit); removeInputImage(xpId, field_id, fileRank); gfi.save(); gfi.getOutputStream().close(); return true; } catch (Exception e) { exceptionPrinter.print(e, "Error while saving image: " + title, true); } catch (OutOfMemoryError e) { int MEGABYTE = (1024 * 1024); MemoryUsage heapUsage = memoryBean.getHeapMemoryUsage(); long maxMemory = heapUsage.getMax() / MEGABYTE; long usedMemory = heapUsage.getUsed() / MEGABYTE; IJ.log("Error while saving image:" + title + " Out of memory. Memory Use :" + usedMemory + "M/" + maxMemory + "M"); } return false; }
From source file:tango.mongo.ImageManager.java
License:Open Source License
public synchronized void saveFieldThumbnail(ObjectId field_id, ImageHandler img, int sizeX, int sizeY) { GridFSInputFile gfi = this.gfsFieldThumbnail.createFile(img.getThumbNail(sizeX, sizeY)); BasicDBObject query = new BasicDBObject("field_id", field_id); gfsFieldThumbnail.remove(query);/*from w ww . j a v a2s. c om*/ gfi.put("field_id", field_id); gfi.save(); try { gfi.getOutputStream().close(); } catch (Exception e) { exceptionPrinter.print(e, "", Core.GUIMode); } }
From source file:tango.mongo.ImageManager.java
License:Open Source License
public synchronized void saveNucleusImage(ObjectId xpId, ObjectId nucleus_id, int fileIdx, int fileType, ImageHandler img) {// w w w . j a va 2 s.com if (img == null) return; removeNucleusImage(xpId, nucleus_id, fileIdx, fileType); try { GridFSInputFile gfi = this.gfsNucleus.get(xpId).createFile(img.getBinaryData()); gfi.setFilename(img.getImagePlus().getShortTitle()); gfi.put("nucleus_id", nucleus_id); gfi.put("fileIdx", fileIdx); gfi.put("fileType", fileType); gfi.put("pixelDepth", img.getScaleZ()); gfi.put("unit", img.getUnit()); gfi.save(); if (gfi != null) gfi.getOutputStream().close(); } catch (Exception e) { exceptionPrinter.print(e, "Error while saving image:" + img.getTitle(), Core.GUIMode); } }
From source file:tango.mongo.ImageManager.java
License:Open Source License
public synchronized void saveChannelImageThumbnail(ObjectId nucleus_id, int fileIdx, ImageHandler img, int sizeX, int sizeY, ImageInt mask) { GridFSInputFile gfi = this.gfsNucleusThumbnail.createFile(img.getThumbNail(sizeX, sizeY, mask)); BasicDBObject query = new BasicDBObject("nucleus_id", nucleus_id).append("fileRank", fileIdx); gfsNucleusThumbnail.remove(query);/*from w ww. j ava 2 s .c o m*/ gfi.put("nucleus_id", nucleus_id); gfi.put("fileRank", fileIdx); gfi.save(); try { gfi.getOutputStream().close(); } catch (Exception e) { exceptionPrinter.print(e, "", Core.GUIMode); } }