}
@Override
public ODataResponse writeEntry(final EdmEntitySet entitySet, final Map<String, Object> data,
final EntityProviderWriteProperties properties) throws EntityProviderException {
CircleStreamBuffer csb = new CircleStreamBuffer();
try {
OutputStream outStream = csb.getOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outStream, DEFAULT_CHARSET);
writer.writeStartDocument(DEFAULT_CHARSET, XML_VERSION);
AtomEntryEntityProducer as = new AtomEntryEntityProducer(properties);
EntityInfoAggregator eia = EntityInfoAggregator.create(entitySet, properties.getExpandSelectTree());
as.append(writer, eia, data, true, false);
writer.flush();
csb.closeWrite();
ODataResponseBuilder response = ODataResponse.entity(csb.getInputStream())
.eTag(as.getETag())
.idLiteral(as.getLocation());
return response.build();
} catch (EntityProviderException e) {
csb.close();
throw e;
} catch (Exception e) {
csb.close();
throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass()
.getSimpleName()), e);
}
}