Java Code Examples for com.mongodb.gridfs.GridFSInputFile#setFilename()

The following examples show how to use com.mongodb.gridfs.GridFSInputFile#setFilename() . 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: ImageDao.java    From XBDD with Apache License 2.0 6 votes vote down vote up
public String saveImageAndReturnFilename(final JUnitEmbedding embedding, final Coordinates coordinates, final String featureId,
		final String scenarioId) {
	final GridFS gridFS = getGridFS();

	try {
		final GridFSInputFile image = gridFS
				.createFile(Base64.decodeBase64((embedding.getData()).getBytes()));

		image.setFilename(UUID.randomUUID().toString());

		final BasicDBObject metadata = new BasicDBObject().append("product", coordinates.getProduct())
				.append("major", coordinates.getMajor()).append("minor", coordinates.getMinor())
				.append("servicePack", coordinates.getServicePack()).append("build", coordinates.getBuild())
				.append("feature", featureId)
				.append("scenario", scenarioId);
		image.setMetaData(metadata);
		image.setContentType(embedding.getMime_type());
		image.save();

		return image.getFilename();

	} catch (final ClassCastException e) {
		LOGGER.warn("Embedding was malformed and will be skipped");
		return null;
	}
}
 
Example 2
Source File: GridFSFileBuilder.java    From ymate-platform-v2 with Apache License 2.0 5 votes vote down vote up
public GridFSInputFile build(IGridFSSession gridFS) throws Exception {
    GridFSInputFile _inFile = null;
    switch (__type) {
        case 1:
            // is File
            _inFile = gridFS.getGridFS().createFile((File) __targetObject);
            break;
        case 2:
            // is InputStream
            _inFile = gridFS.getGridFS().createFile((InputStream) __targetObject);
            break;
        case 3:
            // is Array
            _inFile = gridFS.getGridFS().createFile((byte[]) __targetObject);
            break;
        default:
    }
    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;
}
 
Example 3
Source File: BuguFS.java    From bugu-mongo with Apache License 2.0 5 votes vote down vote up
public String save(File file, String filename, Map<String, Object> attributes){
    GridFSInputFile f = null;
    try{
        f = fs.createFile(file);
    }catch(IOException ex){
        throw new BuguFSException(ex.getMessage());
    }
    if(f != null){
        f.setChunkSize(chunkSize);
        f.setFilename(filename);
        setAttributes(f, attributes);
        f.save();
    }
    return f.getId().toString();
}
 
Example 4
Source File: BuguFS.java    From bugu-mongo with Apache License 2.0 5 votes vote down vote up
public String save(InputStream is, String filename, Map<String, Object> attributes){
    GridFSInputFile f = fs.createFile(is);
    f.setChunkSize(chunkSize);
    f.setFilename(filename);
    setAttributes(f, attributes);
    f.save();
    return f.getId().toString();
}
 
Example 5
Source File: BuguFS.java    From bugu-mongo with Apache License 2.0 5 votes vote down vote up
public String save(byte[] data, String filename, Map<String, Object> attributes){
    GridFSInputFile f = fs.createFile(data);
    f.setChunkSize(chunkSize);
    f.setFilename(filename);
    setAttributes(f, attributes);
    f.save();
    return f.getId().toString();
}
 
Example 6
Source File: GetMapFile.java    From osiris with Apache License 2.0 4 votes vote down vote up
private void saveFile(String appIdentifier, File file, GridFS gridFS) throws IOException{
	GridFSInputFile gridFSInputFile = gridFS.createFile(file);
	gridFSInputFile.setFilename(appIdentifier);
	gridFSInputFile.save();
}
 
Example 7
Source File: GetMapFile.java    From osiris with Apache License 2.0 4 votes vote down vote up
private void saveFile(String appIdentifier, File file, GridFS gridFS) throws IOException{
	GridFSInputFile gridFSInputFile = gridFS.createFile(file);
	gridFSInputFile.setFilename(appIdentifier);
	gridFSInputFile.save();
}
 
Example 8
Source File: ImportFilesRepositoryCustomImpl.java    From osiris with Apache License 2.0 4 votes vote down vote up
private void saveFile(String appIdentifier, File file, GridFS gridFS) throws IOException{
	GridFSInputFile gridFSInputFile = gridFS.createFile(file);
	gridFSInputFile.setFilename(appIdentifier);
	gridFSInputFile.save();
}
 
Example 9
Source File: Add.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
public cfData execute(cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException {
	
	// Get the necessary Mongo references
	DB db	= getDB(_session,argStruct);
	
	GridFS	gridfs	= getGridFS(_session, argStruct, db);
	GridFSInputFile fsInputFile = null;
	
	// Get the file information
	String filename	= getNamedStringParam(argStruct, "filename", null);
	if ( filename == null )
		throwException(_session, "please specify a filename");
	
	try{
		
		cfData	ftmp	= getNamedParam(argStruct, "file", null);
		if ( ftmp.getDataType() == cfData.CFBINARYDATA ){
			fsInputFile	= gridfs.createFile( ((cfBinaryData)ftmp).getByteArray() );
		}else{
			// The 'file' parameter is a string, which means it is a path to a file
			
			File	inputFile	= new File( ftmp.getString() );
			if ( !inputFile.exists() )
				throwException(_session, "File:" + inputFile + " does not exist" );
			
			if ( !inputFile.isFile() )
				throwException(_session, "File:" + inputFile + " is not a valid file" );
			
			fsInputFile	= gridfs.createFile(inputFile);
		}
		
	} catch (IOException e) {
		throwException(_session, e.getMessage() );
	}
	
	fsInputFile.setFilename(filename);
	
	String contenttype	= getNamedStringParam(argStruct, "contenttype", null);		
	if ( contenttype != null )
		fsInputFile.setContentType(contenttype);

	
	String _id	= getNamedStringParam(argStruct, "_id", null);
	if ( _id != null )
		fsInputFile.setId( _id );

	
	// Get and set the metadata
	cfData mTmp	= getNamedParam(argStruct, "metadata", null);
	if ( mTmp != null )
		fsInputFile.setMetaData(getDBObject(mTmp));
	
	
	// Save the Object
	try{
		fsInputFile.save();
		return new cfStringData( fsInputFile.getId().toString() );
	} catch (MongoException me){
		throwException(_session, me.getMessage());
		return null;
	}
}
 
Example 10
Source File: MongoRepository.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
@Override
public RepositoryItem createRepositoryItem() {
  GridFSInputFile dbFile = gridFS.createFile();
  dbFile.setFilename(dbFile.getId().toString());
  return createRepositoryItem(dbFile);
}