List of usage examples for com.mongodb.gridfs GridFSInputFile getOutputStream
public OutputStream getOutputStream()
From source file:tango.mongo.MongoConnector.java
License:Open Source License
public synchronized boolean saveInputImage(ObjectId field_id, int fileRank, ImageHandler img, boolean flushImage) { if (img == null) { return false; }// ww w. j ava 2 s. c o m //IJ.log("file: "+img.getTitle()+" size:"+img.getSizeInMb()+ " available memory:"+Core.getAvailableMemory()+ " please free memory"); double scaleZ = img.getScaleZ(); String unit = img.getUnit(); 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.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(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.MongoConnector.java
License:Open Source License
public synchronized void saveFieldThumbnail(ObjectId field_id, int fileIdx, byte[] thumbnail) { GridFSInputFile gfi = this.gfsFieldThumbnail.createFile(thumbnail); BasicDBObject query = new BasicDBObject("field_id", field_id).append("fileRank", fileIdx); gfsFieldThumbnail.remove(query);/* w w w. j av a2 s. c om*/ gfi.put("field_id", field_id); gfi.put("fileRank", fileIdx); gfi.save(); try { gfi.getOutputStream().close(); } catch (Exception e) { exceptionPrinter.print(e, "", Core.GUIMode); } }
From source file:tango.mongo.MongoConnector.java
License:Open Source License
public synchronized void saveNucleusImage(ObjectId nucleus_id, int fileIdx, int fileType, ImageHandler img) { removeNucleusImage(nucleus_id, fileIdx, fileType); if (img == null) { System.out.println("set nucleus image null"); return;//from www .j av a 2s . c o m } try { GridFSInputFile gfi = this.gfsNucleus.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.put("offsetX", img.offsetX); gfi.put("offsetY", img.offsetY); gfi.put("offsetZ", img.offsetZ); gfi.save(); if (gfi != null) { gfi.getOutputStream().close(); } } catch (Exception e) { exceptionPrinter.print(e, "Error while saving image:" + img.getTitle(), Core.GUIMode); } }