Example usage for com.mongodb.gridfs GridFSFile getLength

List of usage examples for com.mongodb.gridfs GridFSFile getLength

Introduction

In this page you can find the example usage for com.mongodb.gridfs GridFSFile getLength.

Prototype

public long getLength() 

Source Link

Document

Gets the file's length.

Usage

From source file:com.kurento.kmf.repository.internal.repoimpl.mongo.MongoRepositoryItem.java

License:Open Source License

private static RepositoryItemAttributes loadAttributes(GridFSFile file) {

    RepositoryItemAttributes attributes = new RepositoryItemAttributes();

    attributes.setContentLength(file.getLength());
    attributes.setLastModified(file.getUploadDate().getTime());
    attributes.setMimeType(file.getContentType());

    return attributes;
}

From source file:org.craftercms.commons.mongo.FileInfo.java

License:Open Source License

FileInfo(final GridFSFile savedFile, final boolean withInputStream) {
    this.md5 = savedFile.getMD5();
    this.fileId = (ObjectId) savedFile.getId();
    this.contentType = savedFile.getContentType();
    this.fileSize = FileUtils.readableFileSize(savedFile.getLength());
    this.storeName = savedFile.getFilename();
    this.savedDate = savedFile.getUploadDate();
    this.fileSizeBytes = savedFile.getLength();
    if (withInputStream && savedFile instanceof GridFSDBFile) {
        this.inputStream = ((GridFSDBFile) savedFile).getInputStream();
    }/*from   www.  j  av  a2 s .co m*/
    attributes = new HashMap<>();
}

From source file:org.craftercms.studio.impl.repository.mongodb.services.impl.NodeServiceImpl.java

License:Open Source License

private CoreMetadata createNodeMetadata(final String fileName, final String creatorName,
        final InputStream content, final String folderLabel) throws MongoRepositoryException {
    CoreMetadata coreMetadata = createBasicMetadata(fileName, creatorName, folderLabel);
    try {//from  w  w  w .  j a  va 2s.c om
        GridFSFile savedFile = gridFSService.saveFile(fileName, content);
        coreMetadata.setSize(savedFile.getLength());
        coreMetadata.setFileId(savedFile.getId().toString());
    } catch (DataAccessException ex) {
        log.error("Unable to save {} file due a DataAccessException", fileName);
        log.error("DataAccessException thrown ", ex);
        throw new MongoRepositoryException("Unable to save file due a DataAccessException", ex);
    }
    return coreMetadata;
}

From source file:org.eclipse.hawkbit.artifact.repository.ArtifactStore.java

License:Open Source License

/**
 * Maps a single {@link GridFSFile} to {@link DbArtifact}.
 *
 * @param tenant/*w ww  . ja  v a 2  s . c o m*/
 *            the tenant
 * @param dbFile
 *            the mongoDB gridFs file.
 * @return a mapped artifact from the given dbFile
 */
private static GridFsArtifact map(final GridFSFile fsFile) {
    if (fsFile == null) {
        return null;
    }
    final GridFsArtifact artifact = new GridFsArtifact(fsFile);
    artifact.setArtifactId(fsFile.getId().toString());
    artifact.setSize(fsFile.getLength());
    artifact.setContentType(fsFile.getContentType());
    artifact.setHashes(new DbArtifactHash(fsFile.getFilename(), fsFile.getMD5()));
    return artifact;
}