Package com.mongodb.gridfs

Examples of com.mongodb.gridfs.GridFSInputFile.save()


            is.close();
            return md5;
        }

        GridFSInputFile gridFSInputFile = gridFS.createFile(bis, true);
        gridFSInputFile.save();
        return gridFSInputFile.getMD5();
    }

    private static String calculateMd5(BufferedInputStream bis) throws IOException {
        bis.mark(Integer.MAX_VALUE);
View Full Code Here


  public void storeAttachment(AttachmentId attachmentId, InputStream data)
      throws IOException {
    GridFSInputFile file = getAttachmentGrid().createFile(data, attachmentId.serialise());

    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();
View Full Code Here

        File file = createRandomFile();
        String hash = sha256(file);

        GridFSInputFile inputFile = gridFS.createFile(new FileInputStream(file));
        inputFile.put("_id", hash);
        inputFile.save();

        InputStream dbInputStream = dao.findOne(hash);

        assertNotNull(dbInputStream, "Expected to find file with name " + hash);
        File actualFile = new File(dataDir, "findFile.actual");
View Full Code Here

    }

    public void save(File file) throws IOException {
        GridFSInputFile inputFile = gridFS.createFile(new BufferedInputStream(new FileInputStream(file)));
        inputFile.put("_id", file.getName());
        inputFile.save();
    }
   
    public void delete(String id) {
        gridFS.remove(new BasicDBObject("_id", id));
    }
View Full Code Here

            is.close();
            return md5;
        }

        GridFSInputFile gridFSInputFile = gridFS.createFile(bis, true);
        gridFSInputFile.save();
        return gridFSInputFile.getMD5();
    }

    private static String calculateMd5(BufferedInputStream bis) throws IOException {
        bis.mark(Integer.MAX_VALUE);
View Full Code Here

        GridFS gridFs = new GridFS(mongoTemplate.getDb(), folder);
        GridFSInputFile gfsFile = gridFs.createFile(file.getFileItem()
            .getInputStream());

        gfsFile.setFilename(originalFilename);
        gfsFile.save();

      } catch (IllegalStateException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
View Full Code Here

    }

    public String writeBlob(InputStream in) throws Exception {
        GridFSInputFile f = fs.createFile(in, true);
        //f.save(0x20000);   // save in 128k chunks
        f.save();

        IOUtils.closeQuietly(in);

        return f.getId().toString();
    }
View Full Code Here

      gridFile.put("timestamp", System.currentTimeMillis());
      gridFile.put("uniqueId", UidGenerator.generateUid());


      gridFile.setFilename(renameTo);
      gridFile.save(chunkSize);
      gridFile.validate();
    }
    catch(IOException e)
    {
      throw new DBException("Failed to read input file: "
View Full Code Here

   
    // set a filename for identification purposes. We use the previously created UUID
    gfsInputFile.setFilename(uuid);
   
    // save the file file into mongoDB and disconnect
    gfsInputFile.save();
    this.mongoConn.disconnect();
   
    this.logger.info("[File][GridFS] File with " + uuid + "UUID data Stored");
   
    return uuid;
View Full Code Here

        tags.add("Singing");
        tags.add("Opera");
        meta.append("tags", tags);

        video.setMetaData(meta);
        video.save();

        System.out.println("Object ID in Files Collection: " +  video.get("_id"));


        System.out.println("Saved the file to MongoDB");
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.