本文整理匯總了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();
}
}
示例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();
}
};
}
}
示例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;
}
示例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();
}
};
}
}
示例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;
}
示例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();
}
}
示例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);
}
示例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();
}
示例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();
}