java connection 清空缓存_Java ObjectConnection.clear方法代码示例

该代码示例展示了如何使用Java解析JSONLD内容,通过RepositoryConnection和ObjectConnection进行处理,并在完成后调用clear方法清空缓存。
摘要由CSDN通过智能技术生成

import org.openrdf.repository.object.ObjectConnection; //导入方法依赖的package包/类

/**

* Used to parse a given text content, supported in a given serialization

* format.

*

* @param content The String representation of the textcontent.

* @param documentURL The basic URL used for namespaces.

* @param format The format of the given serialization. Needs to be

* supported of an instance of RDFFormat.

* @return A list of annotations

*/

private List parse(String content, URL url, RDFFormat format) {

List annos = new LinkedList<>();

List orig;

try {

// Use this connection for parsing the jsonld and create the annotation

RepositoryConnection con = _parseAnno4j.getRepository().getConnection();

RDFParser parser = Rio.createParser(format);

try {

StatementSailHandler handler = new StatementSailHandler(con);

parser.setRDFHandler(handler);

byte[] bytes = content.getBytes("UTF-8");

try (InputStream stream = new ByteArrayInputStream(bytes)) {

parser.parse(stream, url.toString());

}

} catch (RDFHandlerException | RDFParseException | IOException e) {

e.printStackTrace();

}

// Get objects now

ObjectConnection conObject = _parseAnno4j.getObjectRepository().getConnection();

orig = conObject.getObjects(Annotation.class).asList();

long t1 = System.currentTimeMillis();

for (Annotation old : orig) {

// Create a new annotation for our main repository

// Be careful. Make sure that the returned annotation is an

// updated object from our repository

Annotation anno = persistAnnotation(old, conObject, url);

annos.add(anno);

}

long t2 = System.currentTimeMillis();

System.out.println("Create new annotation " + (t2 - t1));

// Clear and close the alibaba object repository used for parsing

con.clear();

conObject.clear();

con.close();

conObject.close();

return annos;

} catch (RepositoryException | QueryEvaluationException ex) {

Logger.getLogger(Anno4jRepository.class.getName()).log(Level.SEVERE, null, ex);

}

return annos;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值