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) {