Example usage for com.mongodb.client.gridfs GridFSBucket downloadToStreamByName

List of usage examples for com.mongodb.client.gridfs GridFSBucket downloadToStreamByName

Introduction

In this page you can find the example usage for com.mongodb.client.gridfs GridFSBucket downloadToStreamByName.

Prototype

@Deprecated
void downloadToStreamByName(String filename, OutputStream destination);

Source Link

Document

Downloads the contents of the latest version of the stored file specified by filename and writes the contents to the destination Stream.

Usage

From source file:net.liaocy.ml4j.nlp.word2vec.Predict.java

private void load(String modelName) throws IOException {
    MongoDatabase db = Mongo.getDB();/*  w w  w  .  j a va  2  s.c o m*/
    GridFSBucket gridFSBucket = GridFSBuckets.create(db, "word2vecmodels");
    File file = File.createTempFile(modelName, ".w2v");
    OutputStream os = new FileOutputStream(file);
    gridFSBucket.downloadToStreamByName(modelName, os);
    os.close();
    this.vec = WordVectorSerializer.readWord2VecModel(file);
    //        System.out.println(file.getAbsolutePath());
    if (!file.delete()) {
        file.deleteOnExit();
    }
}