当前位置: 首页>>代码示例>>Java>>正文


Java AttachmentInputStream类代码示例

本文整理汇总了Java中org.ektorp.AttachmentInputStream的典型用法代码示例。如果您正苦于以下问题:Java AttachmentInputStream类的具体用法?Java AttachmentInputStream怎么用?Java AttachmentInputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AttachmentInputStream类属于org.ektorp包,在下文中一共展示了AttachmentInputStream类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateSchema

import org.ektorp.AttachmentInputStream; //导入依赖的package包/类
@Override
public void updateSchema(JsonNode oldSchema, JsonNode newSchema) {
    // store new version of the schema as newest revision of the document
    db.update(newSchema);
    
    // prepare old schema as stream
    byte[] bytes = jsonNodeToBytes(oldSchema);
    InputStream stream = new ByteArrayInputStream(bytes);
    String oldRev = oldSchema.get("_rev").textValue();
    
    // create attachment as stream 
    // id will be revision of old schema
    // data will be stored as application/json content type
    // note that this also increment revision of the document
    AttachmentInputStream data = new AttachmentInputStream(oldRev, stream, "application/json");
    String id = newSchema.get("_id").textValue();
    db.createAttachment(id, getCurrentRevision(id), data);  
    
    try {
        data.close();
    } catch (IOException ex) {
        logger.error(ex);
    }
}
 
开发者ID:martin-kanis,项目名称:relax-dms,代码行数:25,代码来源:CouchDbRepositoryImpl.java

示例2: getDocumentByIdAndRev

import org.ektorp.AttachmentInputStream; //导入依赖的package包/类
@Override
public JsonNode getDocumentByIdAndRev(String id, String rev) {
    String currentRev = getCurrentRevision(id);
    JsonNode schema = null;
    
    // current and needed revisions are the same so return current version of the schema
    if (currentRev.equals(rev)) {
        return this.find(id);
    } else {
        AttachmentInputStream ais = db.getAttachment(id, rev);
        try {
            byte[] data = IOUtils.toByteArray(ais);
            ObjectReader reader = (new ObjectMapper()).reader();
            schema = reader.readTree(new ByteArrayInputStream(data));
            ais.close();
        } catch (IOException ex) {
            logger.error(ex);
        }
        return schema;
    }
}
 
开发者ID:martin-kanis,项目名称:relax-dms,代码行数:22,代码来源:CouchDbRepositoryImpl.java

示例3: doGet

import org.ektorp.AttachmentInputStream; //导入依赖的package包/类
protected void doGet(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {

	String id = request.getParameter("id");
	if (id == null)
		return;
	if (id.equals(""))
		return;

	String contentType = "image/png";
	AttachmentInputStream data = DatabaseUtilities.getSingleton().getDB()
			.getAttachment(id, id);
	response.setContentType(contentType);
	response.setContentLength(longToInt(data.getContentLength()));
	OutputStream out = response.getOutputStream();
	byte[] buffer = new byte[1024];
	int count = 0;
	while ((count = data.read(buffer)) >= 0) {
		out.write(buffer, 0, count);
	}
	out.close();
	data.close();
}
 
开发者ID:IBM-Cloud,项目名称:drone-selfie,代码行数:24,代码来源:PictureServlet.java

示例4: testAttachments

import org.ektorp.AttachmentInputStream; //导入依赖的package包/类
public void testAttachments() throws IOException {

        HttpClient httpClient = new CBLiteHttpClient(manager);
        CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);

        CouchDbConnector dbConnector = dbInstance.createConnector(DEFAULT_TEST_DB, true);

        TestObject test = new TestObject(1, false, "ektorp");

        //create a document
        dbConnector.create(test);

        //attach file to it
        byte[] attach1 = "This is the body of attach1".getBytes();
        ByteArrayInputStream b = new ByteArrayInputStream(attach1);
        AttachmentInputStream a = new AttachmentInputStream("attach", b, "text/plain");
        dbConnector.createAttachment(test.getId(), test.getRevision(), a);

        AttachmentInputStream readAttachment = dbConnector.getAttachment(test.getId(), "attach");
        Assert.assertEquals("text/plain", readAttachment.getContentType());
        Assert.assertEquals("attach", readAttachment.getId());

        BufferedReader br = new BufferedReader(new InputStreamReader(readAttachment));
        Assert.assertEquals("This is the body of attach1", br.readLine());
    }
 
开发者ID:couchbaselabs,项目名称:couchbase-lite-android-ektorp,代码行数:26,代码来源:Attachments.java

示例5: tweet

import org.ektorp.AttachmentInputStream; //导入依赖的package包/类
private String tweet(String pictureId, String message) {
	String output = null;
	if (message == null) return null;
	if (message.equalsIgnoreCase("")) return null;
	
	try {
		String consumerKey = ConfigUtilities.getSingleton().getTwitterConsumerKey();
		String consumerSecret = ConfigUtilities.getSingleton().getTwitterConsumerSecret();
		String accessToken = ConfigUtilities.getSingleton().getTwitterAccessToken();
		String accessTokenSecret = ConfigUtilities.getSingleton().getTwitterAccessTokenSecret();
		
		TwitterFactory twitterFactory = new TwitterFactory();			 
        Twitter twitter = twitterFactory.getInstance();
        twitter.setOAuthConsumer(consumerKey, consumerSecret);
        twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));
 
        StatusUpdate statusUpdate = new StatusUpdate(message);
     
        AttachmentInputStream data = DatabaseUtilities.getSingleton().getDB().getAttachment(pictureId, pictureId);
        statusUpdate.setMedia("picture", data); 

        Status status = twitter.updateStatus(statusUpdate);
        if (status == null) return null;
        output = "https://twitter.com/bluedroneselfie/status/" + String.valueOf(status.getId());

		return output;
	} catch (Exception e) {
		e.printStackTrace();
	}

	return output;
}
 
开发者ID:IBM-Cloud,项目名称:drone-selfie,代码行数:33,代码来源:TwitterUtilities.java

示例6: addAttachment

import org.ektorp.AttachmentInputStream; //导入依赖的package包/类
public void addAttachment(PluginMetaDataDocument metaData, InputStream stream, String contentType) {
	AttachmentInputStream attachmentInputStream = new AttachmentInputStream(metaData.getValue().getId(), stream, contentType);
	connector.createAttachment(metaData.getId(), metaData.getRevision(), attachmentInputStream);
}
 
开发者ID:jvalue,项目名称:open-data-service,代码行数:5,代码来源:PluginMetaDataRepository.java

示例7: getAttachment

import org.ektorp.AttachmentInputStream; //导入依赖的package包/类
@Override
public AttachmentInputStream getAttachment(String id, String attachmentId) {
	throw new UnsupportedOperationException("not implemented");
}
 
开发者ID:arnaudsjs,项目名称:YCSB-couchdb-binding,代码行数:5,代码来源:LoadBalancedConnector.java

示例8: createAttachment

import org.ektorp.AttachmentInputStream; //导入依赖的package包/类
@Override
public String createAttachment(String docId, AttachmentInputStream data) {
	throw new UnsupportedOperationException("not implemented");
}
 
开发者ID:arnaudsjs,项目名称:YCSB-couchdb-binding,代码行数:5,代码来源:LoadBalancedConnector.java


注:本文中的org.ektorp.AttachmentInputStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。