Example usage for com.mongodb.gridfs GridFSDBFile getInputStream

List of usage examples for com.mongodb.gridfs GridFSDBFile getInputStream

Introduction

In this page you can find the example usage for com.mongodb.gridfs GridFSDBFile getInputStream.

Prototype

public InputStream getInputStream() 

Source Link

Document

Returns an InputStream from which data can be read.

Usage

From source file:org.opentestsystem.delivery.testreg.rest.FileUploadDataController.java

License:Open Source License

/**
 * Preview File./*from w w  w .j a  v  a  2s  .  co m*/
 *
 * @param gridFsId
 *        file to be retrieved for preview.
 * @return List<FilePreview> file preview.
 */
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/previewFile/{gridFsId}", method = RequestMethod.GET, produces = {
        MediaType.APPLICATION_JSON_VALUE })
@Secured({ "ROLE_Accommodations Upload", "ROLE_Student Upload", "ROLE_Entity Upload",
        "ROLE_StudentGroup Upload", "ROLE_User Upload", "ROLE_ExplicitEligibility Upload" })
@ResponseBody
public List<FilePreview> previewFile(@PathVariable final String gridFsId) throws Exception {
    final long start = System.currentTimeMillis();
    final GridFSDBFile file = getGridFSDBFile(gridFsId);
    this.metricClient.sendPerformanceMetricToMna(buildMetricMessage(gridFsId, "previewFile->getGridFSDBFile"),
            System.currentTimeMillis() - start);
    return FilePreviewHelper.extractDataForPreview(file.getInputStream(),
            retrieveFormatTypeFromFileMetadata(file), file.getFilename(), 7);
}

From source file:org.opentestsystem.delivery.testreg.rest.FileUploadDataController.java

License:Open Source License

/**
 * @param file/*from  ww  w  .  ja  v a 2  s.  com*/
 * @return
 */
private FileUploadSummary extractAccommodationData(GridFSDBFile file) throws Exception {
    return this.extractAccommodationFile(file.getFilename(), file.getInputStream(),
            retrieveFormatTypeFromFileMetadata(file));
}

From source file:org.opentestsystem.delivery.testreg.rest.FileUploadDataController.java

License:Open Source License

private ParserResult<Map<FormatType, List<TestRegistrationBase>>> extractFile(final GridFSDBFile file)
        throws Exception {
    return this.fileUploadUtils.extractFile(file.getFilename(), file.getInputStream(),
            retrieveFormatTypeFromFileMetadata(file));
}

From source file:org.rhq.enterprise.server.plugins.drift.mongodb.dao.FileDAO.java

License:Open Source License

public InputStream findOne(String hash) {
    GridFSDBFile dbFile = gridFS.findOne(new BasicDBObject("_id", hash));
    if (dbFile == null) {
        return null;
    }/* w w w.  j a  v a2s. c  o  m*/
    return dbFile.getInputStream();
}

From source file:org.rhq.enterprise.server.plugins.drift.mongodb.MongoDBDriftServer.java

License:Open Source License

@Override
public String getDriftFileBits(Subject subject, String hash) {
    GridFSDBFile file = fileDAO.findById(hash);
    if (file == null) {
        return null;
    }/*w ww.j  a va  2s .com*/
    return new String(StreamUtil.slurp(file.getInputStream()));
}

From source file:org.rhq.enterprise.server.plugins.drift.mongodb.MongoDBDriftServer.java

License:Open Source License

@Override
public byte[] getDriftFileAsByteArray(Subject subject, String hash) {
    GridFSDBFile file = fileDAO.findById(hash);
    if (file == null) {
        return null;
    }//from   ww w  .  j a va  2  s.com
    return StreamUtil.slurp(file.getInputStream());
}

From source file:org.s1.mongodb.cluster.GridFSFileStorage.java

License:Apache License

@Override
public FileStorage.FileReadBean read(Id id) throws NotFoundException {
    GridFS fs = new GridFS(MongoDBConnectionHelper.getConnection(id.getDatabase()), id.getCollection());
    GridFSDBFile o = fs.findOne(id.getEntity());
    if (o == null)
        throw new NotFoundException("GridFS file not found: " + id);
    FileStorage.FileMetaBean fb = new FileStorage.FileMetaBean();
    fb.fromMap(MongoDBFormat.toMap(o.getMetaData()));
    fb.setSize(o.getLength());/*  ww w.  j  a v  a 2 s. c o  m*/
    fb.setContentType(o.getContentType());
    if (LOG.isDebugEnabled())
        LOG.debug("Read file: " + id + ", meta:" + fb.toMap());
    return new FileStorage.FileReadBean(o.getInputStream(), fb);
}

From source file:org.sakaiproject.nakamura.lite.storage.mongo.GridFSContentHelper.java

License:Apache License

public InputStream readBody(String keySpace, String columnFamily, String contentBlockId, String streamId,
        Map<String, Object> content) throws IOException {
    // give me whatever is stored in the property _bodyLocation/streamId
    String path = (String) content.get(StorageClientUtils.getAltField(STORE_LOCATION_FIELD, streamId));
    LOGGER.debug("Reading from {} as body of {}:{}:{} ",
            new Object[] { path, keySpace, columnFamily, contentBlockId });
    GridFSDBFile file = contentBodies.findOne(path);
    if (file != null) {
        return file.getInputStream();
    } else {//w  ww.  j av  a 2  s .co  m
        return null;
    }
}

From source file:org.sipfoundry.commons.userdb.profile.UserProfileServiceImpl.java

License:Open Source License

@Override
public InputStream getAvatar(String userName) {
    GridFS avatarFS = new GridFS(m_template.getDb());
    GridFSDBFile imageForOutput = avatarFS.findOne(String.format(AVATAR_NAME, userName));
    if (imageForOutput != null) {
        return imageForOutput.getInputStream();
    }//from  w  w w.j av  a2s.c  om
    // try default avatar
    imageForOutput = avatarFS.findOne(String.format(AVATAR_NAME, "default"));
    if (imageForOutput != null) {
        return imageForOutput.getInputStream();
    }
    return null;
}

From source file:org.springframework.data.mongodb.gridfs.GridFsResource.java

License:Apache License

/**
 * Creates a new {@link GridFsResource} from the given {@link GridFSDBFile}.
 * //from w  ww. j  a  va 2s.  c  o m
 * @param file must not be {@literal null}.
 */
public GridFsResource(GridFSDBFile file) {
    super(file.getInputStream());
    this.file = file;
}