本文整理汇总了Java中org.ektorp.AttachmentInputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java AttachmentInputStream.close方法的具体用法?Java AttachmentInputStream.close怎么用?Java AttachmentInputStream.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ektorp.AttachmentInputStream
的用法示例。
在下文中一共展示了AttachmentInputStream.close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}