本文整理汇总了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);
}
}
示例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;
}
}
示例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();
}
示例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());
}
示例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;
}
示例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);
}
示例7: getAttachment
import org.ektorp.AttachmentInputStream; //导入依赖的package包/类
@Override
public AttachmentInputStream getAttachment(String id, String attachmentId) {
throw new UnsupportedOperationException("not implemented");
}
示例8: createAttachment
import org.ektorp.AttachmentInputStream; //导入依赖的package包/类
@Override
public String createAttachment(String docId, AttachmentInputStream data) {
throw new UnsupportedOperationException("not implemented");
}