當前位置: 首頁>>代碼示例>>Java>>正文


Java GridFSDBFile.getLength方法代碼示例

本文整理匯總了Java中com.mongodb.gridfs.GridFSDBFile.getLength方法的典型用法代碼示例。如果您正苦於以下問題:Java GridFSDBFile.getLength方法的具體用法?Java GridFSDBFile.getLength怎麽用?Java GridFSDBFile.getLength使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.mongodb.gridfs.GridFSDBFile的用法示例。


在下文中一共展示了GridFSDBFile.getLength方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getEstimatedSizeBytes

import com.mongodb.gridfs.GridFSDBFile; //導入方法依賴的package包/類
@Override
public long getEstimatedSizeBytes(PipelineOptions options) throws Exception {
  Mongo mongo = spec.connectionConfiguration().setupMongo();
  try {
    GridFS gridfs = spec.connectionConfiguration().setupGridFS(mongo);
    DBCursor cursor = createCursor(gridfs);
    long size = 0;
    while (cursor.hasNext()) {
      GridFSDBFile file = (GridFSDBFile) cursor.next();
      size += file.getLength();
    }
    return size;
  } finally {
    mongo.close();
  }
}
 
開發者ID:apache,項目名稱:beam,代碼行數:17,代碼來源:MongoDbGridFSIO.java

示例2: getAttachment

import com.mongodb.gridfs.GridFSDBFile; //導入方法依賴的package包/類
@Override
public AttachmentData getAttachment(AttachmentId attachmentId) {

  final GridFSDBFile attachment = getAttachmentGrid().findOne(attachmentId.serialise());

  if (attachment == null) {
    return null;
  } else {
    return new AttachmentData() {

      @Override
      public InputStream getInputStream() throws IOException {
        return attachment.getInputStream();
      }

      @Override
      public long getSize() {
        return attachment.getLength();
      }
    };
  }
}
 
開發者ID:jorkey,項目名稱:Wiab.pro,代碼行數:23,代碼來源:MongoDbStore.java

示例3: fetchBlobFromMongo

import com.mongodb.gridfs.GridFSDBFile; //導入方法依賴的package包/類
private int fetchBlobFromMongo() throws Exception {
    GridFSDBFile gridFile = gridFS.findOne(new BasicDBObject("md5", blobId));
    long fileLength = gridFile.getLength();
    long start = blobOffset;
    long end = blobOffset + length;
    if (end > fileLength) {
        end = fileLength;
    }
    length = (int) (end - start);

    if (start < end) {
        InputStream is = gridFile.getInputStream();
        if (blobOffset > 0) {
            IOUtils.skipFully(is, blobOffset);
        }
        IOUtils.readFully(is, buffer, bufferOffset, length);
        is.close();
        return length;
    }
    return -1;
}
 
開發者ID:denismo,項目名稱:jackrabbit-dynamodb-store,代碼行數:22,代碼來源:ReadBlobCommandGridFS.java

示例4: fileToAttachmentData

import com.mongodb.gridfs.GridFSDBFile; //導入方法依賴的package包/類
private AttachmentData fileToAttachmentData(final GridFSDBFile attachmant) {
  if (attachmant == null) {
    return null;
  } else {
    return new AttachmentData() {

      @Override
      public InputStream getInputStream() throws IOException {
        return attachmant.getInputStream();
      }

      @Override
      public long getSize() {
        return attachmant.getLength();
      }
    };
  }
}
 
開發者ID:apache,項目名稱:incubator-wave,代碼行數:19,代碼來源:MongoDbStore.java

示例5: prefetchData

import com.mongodb.gridfs.GridFSDBFile; //導入方法依賴的package包/類
public DataAddress prefetchData(DataAddress givenAddress, ServerAddress destAddress) throws IOException {
	logger.info("yo2");
	ServerAddress givenServer = new ServerAddress(givenAddress.hostname, givenAddress.port);
	GridFS givenDatabase = connectToDatabase(givenServer);
	
	logger.info("yo");
            		
       GridFSDBFile givenPackage = givenDatabase.findOne(new BasicDBObject("_id", givenAddress.ID));
       ByteArrayOutputStream baos = new ByteArrayOutputStream((int)givenPackage.getLength());
       givenPackage.writeTo(baos);
              
       logger.info("Prefetched");
                                     
       GridFS destDatabase = connectToDatabase(destAddress);
       GridFSInputFile destPackage = destDatabase.createFile(baos.toByteArray());
       int newID = getNextId(destDatabase);
       logger.info("Got new id for prefetched package: " + newID);
       destPackage.put("_id", newID);
       destPackage.save();
       
       logger.info("after save");
       
       DataAddress ret = new DataAddress();
       ret.hostname = destAddress.getHost();
       ret.port = destAddress.getPort();
       ret.ID = newID;            
       return ret;        
}
 
開發者ID:roscisz,項目名稱:KernelHive,代碼行數:29,代碼來源:DataManager.java

示例6: split

import com.mongodb.gridfs.GridFSDBFile; //導入方法依賴的package包/類
@Override
public List<? extends BoundedSource<ObjectId>> split(
    long desiredBundleSizeBytes, PipelineOptions options) throws Exception {
  Mongo mongo = spec.connectionConfiguration().setupMongo();
  try {
    GridFS gridfs = spec.connectionConfiguration().setupGridFS(mongo);
    DBCursor cursor = createCursor(gridfs);
    long size = 0;
    List<BoundedGridFSSource> list = new ArrayList<>();
    List<ObjectId> objects = new ArrayList<>();
    while (cursor.hasNext()) {
      GridFSDBFile file = (GridFSDBFile) cursor.next();
      long len = file.getLength();
      if ((size + len) > desiredBundleSizeBytes && !objects.isEmpty()) {
        list.add(new BoundedGridFSSource(spec, objects));
        size = 0;
        objects = new ArrayList<>();
      }
      objects.add((ObjectId) file.getId());
      size += len;
    }
    if (!objects.isEmpty() || list.isEmpty()) {
      list.add(new BoundedGridFSSource(spec, objects));
    }
    return list;
  } finally {
    mongo.close();
  }
}
 
開發者ID:apache,項目名稱:beam,代碼行數:30,代碼來源:MongoDbGridFSIO.java

示例7: download

import com.mongodb.gridfs.GridFSDBFile; //導入方法依賴的package包/類
@Override
public ContentResource download(String mediaId) {
    GridFSDBFile file = gridFsTemplate.findOne(Query.query(Criteria.where("_id").is(mediaId)));
    if (null == file) {
        return null;
    }
    GridFsResource gridFsResource = new GridFsResource(file);
    return new ContentResource(gridFsResource.getContentType(), file.getLength(), gridFsResource);
}
 
開發者ID:swarmcom,項目名稱:jSynapse,代碼行數:10,代碼來源:ContentRepositoryImpl.java

示例8: execute

import com.mongodb.gridfs.GridFSDBFile; //導入方法依賴的package包/類
@Override
public Long execute() throws Exception {
    GridFSDBFile gridFSDBFile = gridFS.findOne(new BasicDBObject("md5", blobId));
    if (gridFSDBFile == null) {
        throw new Exception("Blob does not exist");
    }
    return gridFSDBFile.getLength();
}
 
開發者ID:denismo,項目名稱:jackrabbit-dynamodb-store,代碼行數:9,代碼來源:GetBlobLengthCommandGridFS.java

示例9: getFileContentLength

import com.mongodb.gridfs.GridFSDBFile; //導入方法依賴的package包/類
/**
 * get the file content length after saved to MongoDB.
 * @return 
 */
public long getFileContentLength() {
    BuguFS fs = BuguFSFactory.getInstance().create(connection, bucket, chunkSize);
    GridFSDBFile f = fs.findOneById(fileId);
    return f.getLength();
}
 
開發者ID:xbwen,項目名稱:bugu-mongo,代碼行數:10,代碼來源:Uploader.java


注:本文中的com.mongodb.gridfs.GridFSDBFile.getLength方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。