本文整理汇总了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;
}
示例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: 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();
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
};
}
}
示例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;
}
示例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();
}
示例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;
}
示例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();
}
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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;
}