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


Java GridFSDBFile.getInputStream方法代碼示例

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


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

示例1: getBlob

import com.mongodb.gridfs.GridFSDBFile; //導入方法依賴的package包/類
@Override
public InputStream getBlob(CallingContext context, String docPath) {
    GridFS gridFS = getGridFS();
    String lockKey = createLockKey(gridFS, docPath);
    LockHandle lockHandle = grabLock(context, lockKey);
    InputStream retVal = null;
    try {
        GridFSDBFile file = gridFS.findOne(docPath);
        if (file != null) {
            retVal = file.getInputStream();
        }
    } finally {
        releaseLock(context, lockKey, lockHandle);
    }
    return retVal;
}
 
開發者ID:RapturePlatform,項目名稱:Rapture,代碼行數:17,代碼來源:GridFSBlobHandler.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: readFile

import com.mongodb.gridfs.GridFSDBFile; //導入方法依賴的package包/類
private boolean readFile(GridFSDBFile dbFile, OutputStream os) throws IOException {
	InputStream is = null;
	try {
		is = dbFile.getInputStream();
		byte data[] = new byte[4096];
		int len = 0;
		while ((len = is.read(data, 0, data.length)) > 0) {
			os.write(data, 0, len);
		}
		return true;
	} finally {
		if (is != null) {
			is.close();
		}
	}
}
 
開發者ID:hulop,項目名稱:BLELocalization,代碼行數:17,代碼來源:MongoService.java

示例4: nextTeiDocument

import com.mongodb.gridfs.GridFSDBFile; //導入方法依賴的package包/類
public TEIFile nextTeiDocument() {
    InputStream teiStream = null;
    TEIFile tei = new TEIFile();
    DBObject obj = cursor.next();
    tei.setRepositoryDocId((String) obj.get("repositoryDocId"));
    tei.setFileName(tei.getRepositoryDocId() + ".tei.xml");
    tei.setDocumentType((String) obj.get("documentType"));
    tei.setAnhalyticsId((String) obj.get("anhalyticsId"));
    tei.setSource((String) obj.get("source"));
    tei.setRepositoryDocVersion((String) obj.get("version"));
    GridFSDBFile binaryfile = gfs.findOne(tei.getFileName());

    tei.setFileType((String) binaryfile.getContentType());
    indexFile++;
    teiStream = binaryfile.getInputStream();
    try {
        tei.setTei(IOUtils.toString(teiStream));
        teiStream.close();
    } catch (IOException ex) {
        logger.error(ex.getMessage(), ex.getCause());
    }
    return tei;
}
 
開發者ID:anHALytics,項目名稱:anhalytics-core,代碼行數:24,代碼來源:MongoFileManager.java

示例5: 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

示例6: readFileFromGridFS

import com.mongodb.gridfs.GridFSDBFile; //導入方法依賴的package包/類
public static byte[] readFileFromGridFS(GridFSDBFile file) {
	InputStream is = file.getInputStream();
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	try {

		byte bytes[] = new byte[BUFFER_SIZE];
		int read = -1;

		while ((read = is.read(bytes)) != -1) {
			baos.write(bytes, 0, read);
		}

		return baos.toByteArray();
	}
	catch (Exception e) {
	}
	return null;
}
 
開發者ID:lumongo,項目名稱:lumongo,代碼行數:19,代碼來源:MongoConstants.java

示例7: 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

示例8: execute

import com.mongodb.gridfs.GridFSDBFile; //導入方法依賴的package包/類
public String execute() throws IOException {
    String fid = httpServletRequest.getParameter("fid");
    GridFSDBFile gridFSDBFile = boxService.download(fid);
    inputStream = gridFSDBFile.getInputStream();
    filename = gridFSDBFile.getFilename();
    return SUCCESS;
}
 
開發者ID:0x603,項目名稱:SixBox,代碼行數:8,代碼來源:DownloadFile.java

示例9: getFile

import com.mongodb.gridfs.GridFSDBFile; //導入方法依賴的package包/類
public InputStream getFile(String filename) {
    GridFS gridFS = getInstance();
    GridFSDBFile _current = gridFS.findOne(filename);
    if(_current == null) {
        return null;
    }
    return _current.getInputStream();
}
 
開發者ID:javahongxi,項目名稱:whatsmars,代碼行數:9,代碼來源:GridFSClient.java

示例10: getImage

import com.mongodb.gridfs.GridFSDBFile; //導入方法依賴的package包/類
public InputStream getImage(String filename,String path) throws Exception{
    //獲取最大邊,等比縮放
    if(ImageSizeEnum.valueOfPath(path) == null) {
        return null;
    }

    GridFS gridFS = getInstance();
    GridFSDBFile _current = gridFS.findOne(filename);
    if(_current == null) {
        return null;
    }

    int size = ImageSizeEnum.valueOfPath(path).size;

    int max = (Integer)_current.get("max");//圖片的實際尺寸

    InputStream result = null;
    //裁剪
    if(size < max) {
        InputStream inputStream = _current.getInputStream();
        BufferedImage image = ImageIO.read(inputStream);

        inputStream.close();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        BufferedImage thumbnail = Scalr.resize(image, size);//保留最大尺寸
        String format = (String) _current.get("format");
        ImageIO.write(thumbnail, format, bos);
        result = new ByteArrayInputStream(bos.toByteArray());
    } else {
        result = _current.getInputStream();
    }

    return result;
}
 
開發者ID:javahongxi,項目名稱:whatsmars,代碼行數:35,代碼來源:GridFSClient.java

示例11: read

import com.mongodb.gridfs.GridFSDBFile; //導入方法依賴的package包/類
@Override
public byte[] read(String filename) throws IOException {
	GridFSDBFile file = getGridFS().findOne(filename);
	if (file == null) {
		throw new FileNotFoundException(filename);
	}
	InputStream input = file.getInputStream();
	try {
		return IOUtils.toByteArray(input);
	}
	finally {
		input.close();
	}
}
 
開發者ID:tanhaichao,項目名稱:leopard,代碼行數:15,代碼來源:DfsGridImpl.java

示例12: get

import com.mongodb.gridfs.GridFSDBFile; //導入方法依賴的package包/類
@Override
public T get(String keyText) throws IOException, ClassNotFoundException {
    GridFSDBFile objFile = gridfs.findOne(DigestUtils.sha256Hex(keyText));
    if (objFile == null) {
        return null;
    }
    ObjectInputStream objectInput = new ObjectInputStream(objFile.getInputStream());
    T annotation = (T) objectInput.readObject();
    objectInput.close();
    return annotation;
}
 
開發者ID:oaqa,項目名稱:LiveQA,代碼行數:12,代碼來源:MongoPojoCache.java

示例13: parse

import com.mongodb.gridfs.GridFSDBFile; //導入方法依賴的package包/類
@Override
public void parse(GridFSDBFile input, ParserCallback<String> callback)
    throws IOException {
  final Instant time = new Instant(input.getUploadDate().getTime());
  try (BufferedReader reader =
    new BufferedReader(new InputStreamReader(input.getInputStream()))) {
    for (String line = reader.readLine(); line != null; line = reader.readLine()) {
      callback.output(line, time);
    }
  }
}
 
開發者ID:apache,項目名稱:beam,代碼行數:12,代碼來源:MongoDbGridFSIO.java

示例14: getArtifact

import com.mongodb.gridfs.GridFSDBFile; //導入方法依賴的package包/類
@Override
public Artifact getArtifact(DBKey dbKey, String objectID) {
  Artifact artifact = null;

  GridFS gfs = getGridFS(dbKey);
  BasicDBObject query = new BasicDBObject();
  query.put(ID_FIELD_NAME, new ObjectId(objectID));
  GridFSDBFile file = gfs.findOne(query);
  if (file != null) {
    artifact = new Artifact(file.getInputStream(), file.getContentType());
  }
  return artifact;
}
 
開發者ID:Cognifide,項目名稱:aet,代碼行數:14,代碼來源:ArtifactsDAOMongoDBImpl.java

示例15: getStreamByFilename

import com.mongodb.gridfs.GridFSDBFile; //導入方法依賴的package包/類
@Nullable
private InputStream getStreamByFilename(String fname)
{
    GridFSDBFile file = getGridFsTemplate().findOne(new Query().addCriteria(Criteria.where("filename").is(fname)));

    return file != null ? file.getInputStream() : null;
}
 
開發者ID:d0k1,項目名稱:jsflight,代碼行數:8,代碼來源:MongoDbStorageService.java


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