@Override
public ODataResponse writeEntry(final EdmEntitySet entitySet, final Map<String, Object> data,
final EntityProviderWriteProperties properties) throws EntityProviderException {
final EntityInfoAggregator entityInfo = EntityInfoAggregator.create(entitySet, properties.getExpandSelectTree());
CircleStreamBuffer buffer = new CircleStreamBuffer();
try {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(buffer.getOutputStream(), DEFAULT_CHARSET));
JsonEntryEntityProducer producer = new JsonEntryEntityProducer(properties);
producer.append(writer, entityInfo, data, true);
writer.flush();
buffer.closeWrite();
return ODataResponse.entity(buffer.getInputStream())
.eTag(producer.getETag())
.idLiteral(producer.getLocation())
.build();
} catch (EntityProviderException e) {
buffer.close();
throw e;
} catch (Exception e) {
buffer.close();
throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass()
.getSimpleName()), e);
}
}