List of usage examples for com.mongodb.gridfs GridFSInputFile setChunkSize
public void setChunkSize(final long chunkSize)
From source file:com.bugull.mongo.fs.BuguFS.java
License:Apache License
public void save(File file, String filename, Map<String, Object> attributes) { GridFSInputFile f = null; try {//from w w w .j a va 2 s . c om f = fs.createFile(file); } catch (IOException ex) { logger.error("Can not create GridFSInputFile", ex); } f.setChunkSize(chunkSize); f.setFilename(filename); setAttributes(f, attributes); f.save(); }
From source file:com.bugull.mongo.fs.BuguFS.java
License:Apache License
public void save(InputStream is, String filename, Map<String, Object> attributes) { GridFSInputFile f = fs.createFile(is); f.setChunkSize(chunkSize); f.setFilename(filename);/*from w w w . j a va 2 s . c om*/ setAttributes(f, attributes); f.save(); }
From source file:com.bugull.mongo.fs.BuguFS.java
License:Apache License
public void save(byte[] data, String filename, Map<String, Object> attributes) { GridFSInputFile f = fs.createFile(data); f.setChunkSize(chunkSize); f.setFilename(filename);/* w w w .j a va 2s .co m*/ setAttributes(f, attributes); f.save(); }
From source file:com.englishtown.integration.java.IntegrationTestHelper.java
License:Open Source License
public static String createFile(JsonObject config, String bucket) { GridFS gridFS = IntegrationTestHelper.getGridFS(config, bucket); GridFSInputFile inputFile = gridFS .createFile(IntegrationTestHelper.class.getResourceAsStream("/EF_Labs_ENG_logo.JPG")); inputFile.setContentType(DEFAULT_CONTENT_TYPE); inputFile.setFilename(DEFAULT_FILENAME); inputFile.setChunkSize(DEFAULT_CHUNK_SIZE); inputFile.setMetaData(DEFAULT_METADATA); inputFile.save();//from w w w .ja va 2s .c om return inputFile.getId().toString(); }
From source file:net.tooan.ynpay.third.mongodb.fs.BuguFS.java
License:Apache License
public void save(File file, String filename, Map<String, Object> params) { GridFSInputFile f = null; try {//from w w w .j av a2 s .co m f = fs.createFile(file); } catch (IOException ex) { logger.error("Can not create GridFSInputFile", ex); } f.setChunkSize(chunkSize); f.setFilename(filename); setParams(f, params); f.save(); }
From source file:net.tooan.ynpay.third.mongodb.fs.BuguFS.java
License:Apache License
public void save(InputStream is, String filename, Map<String, Object> params) { GridFSInputFile f = fs.createFile(is); f.setChunkSize(chunkSize); f.setFilename(filename);//www .j av a 2s . c o m setParams(f, params); f.save(); }
From source file:net.tooan.ynpay.third.mongodb.fs.BuguFS.java
License:Apache License
public void save(byte[] data, String filename, Map<String, Object> params) { GridFSInputFile f = fs.createFile(data); f.setChunkSize(chunkSize); f.setFilename(filename);/*w ww . j ava 2 s . c o m*/ setParams(f, params); f.save(); }
From source file:net.ymate.platform.persistence.mongodb.support.GridFSFileBuilder.java
License:Apache License
public GridFSInputFile build(IGridFSSession gridFS) throws Exception { GridFSInputFile _inFile = null; switch (__type) { case 1: // is File _inFile = gridFS.getGridFS().createFile((File) __targetObject); break;/*from w ww . ja v a 2s . c om*/ case 2: // is InputStream _inFile = gridFS.getGridFS().createFile((InputStream) __targetObject); break; case 3: // is Array _inFile = gridFS.getGridFS().createFile((byte[]) __targetObject); } if (_inFile != null) { _inFile.setFilename(__filename); _inFile.setContentType(__contentType); if (__chunkSize > 0) { _inFile.setChunkSize(__chunkSize); } if (!__attributes.isEmpty()) { for (Map.Entry<String, Object> _entry : __attributes.entrySet()) { _inFile.put(_entry.getKey(), _entry.getValue()); } } } return _inFile; }
From source file:org.apache.camel.component.gridfs.GridFsProducer.java
License:Apache License
public void process(Exchange exchange) throws Exception { String operation = endpoint.getOperation(); if (operation == null) { operation = exchange.getIn().getHeader(GridFsEndpoint.GRIDFS_OPERATION, String.class); }// w w w .j a v a 2s . com if (operation == null || "create".equals(operation)) { final String filename = exchange.getIn().getHeader(Exchange.FILE_NAME, String.class); Long chunkSize = exchange.getIn().getHeader(GridFsEndpoint.GRIDFS_CHUNKSIZE, Long.class); InputStream ins = exchange.getIn().getMandatoryBody(InputStream.class); GridFSInputFile gfsFile = endpoint.getGridFs().createFile(ins, filename, true); if (chunkSize != null && chunkSize > 0) { gfsFile.setChunkSize(chunkSize); } final String ct = exchange.getIn().getHeader(Exchange.CONTENT_TYPE, String.class); if (ct != null) { gfsFile.setContentType(ct); } String metaData = exchange.getIn().getHeader(GridFsEndpoint.GRIDFS_METADATA, String.class); DBObject dbObject = (DBObject) JSON.parse(metaData); gfsFile.setMetaData(dbObject); gfsFile.save(); exchange.getIn().setHeader(Exchange.FILE_NAME_PRODUCED, gfsFile.getFilename()); } else if ("remove".equals(operation)) { final String filename = exchange.getIn().getHeader(Exchange.FILE_NAME, String.class); endpoint.getGridFs().remove(filename); } else if ("findOne".equals(operation)) { final String filename = exchange.getIn().getHeader(Exchange.FILE_NAME, String.class); GridFSDBFile file = endpoint.getGridFs().findOne(filename); if (file != null) { exchange.getIn().setHeader(GridFsEndpoint.GRIDFS_METADATA, JSON.serialize(file.getMetaData())); exchange.getIn().setHeader(Exchange.FILE_CONTENT_TYPE, file.getContentType()); exchange.getIn().setHeader(Exchange.FILE_LENGTH, file.getLength()); exchange.getIn().setHeader(Exchange.FILE_LAST_MODIFIED, file.getUploadDate()); exchange.getIn().setBody(file.getInputStream(), InputStream.class); } else { throw new FileNotFoundException("No GridFS file for " + filename); } } else if ("listAll".equals(operation)) { final String filename = exchange.getIn().getHeader(Exchange.FILE_NAME, String.class); DBCursor cursor; if (filename == null) { cursor = endpoint.getGridFs().getFileList(); } else { cursor = endpoint.getGridFs().getFileList(new BasicDBObject("filename", filename)); } exchange.getIn().setBody(new DBCursorFilenameReader(cursor), Reader.class); } else if ("count".equals(operation)) { final String filename = exchange.getIn().getHeader(Exchange.FILE_NAME, String.class); DBCursor cursor; if (filename == null) { cursor = endpoint.getGridFs().getFileList(); } else { cursor = endpoint.getGridFs().getFileList(new BasicDBObject("filename", filename)); } exchange.getIn().setBody(cursor.count(), Integer.class); } }