olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chri...@apache.org
Subject olingo-odata4 git commit: [OLINGO-659] Fix minor stream issues
Date Mon, 17 Aug 2015 09:07:51 GMT
Repository: olingo-odata4
Updated Branches:
  refs/heads/master 5248f3421 -> 1dd3a583f


[OLINGO-659] Fix minor stream issues


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/1dd3a583
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/1dd3a583
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/1dd3a583

Branch: refs/heads/master
Commit: 1dd3a583fff08033b21a3dd6cbb74c663f982b2c
Parents: 5248f34
Author: Christian Amend <christian.amend@sap.com>
Authored: Mon Aug 17 10:22:07 2015 +0200
Committer: Christian Amend <christian.amend@sap.com>
Committed: Mon Aug 17 11:01:57 2015 +0200

----------------------------------------------------------------------
 .../tecsvc/client/SystemQueryOptionITCase.java  |   2 +-
 .../commons/core/edm/EdmEnumTypeImpl.java       |  16 ++
 .../serializer/AbstractODataSerializer.java     |   8 +-
 .../serializer/json/ODataJsonSerializer.java    | 111 +++++++-------
 .../core/serializer/xml/ODataXmlSerializer.java | 145 ++++++++++---------
 .../server/core/edm/provider/EdmEnumTest.java   |   6 +
 6 files changed, 161 insertions(+), 127 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/1dd3a583/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/SystemQueryOptionITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/SystemQueryOptionITCase.java
b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/SystemQueryOptionITCase.java
index 3944f34..09c7cc6 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/SystemQueryOptionITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/SystemQueryOptionITCase.java
@@ -311,7 +311,7 @@ public class SystemQueryOptionITCase extends AbstractBaseTestITCase {
   @Override
   protected ODataClient getClient() {
     ODataClient odata = ODataClientFactory.getClient();
-    odata.getConfiguration().setDefaultPubFormat(ContentType  .JSON);
+    odata.getConfiguration().setDefaultPubFormat(ContentType.JSON);
     return odata;
   }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/1dd3a583/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java
b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java
index f1311c1..9b56ed2 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java
@@ -265,4 +265,20 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType
{
   public FullQualifiedName getAnnotationsTargetFQN() {
     return getFullQualifiedName();
   }
+  
+  @Override
+  public boolean equals(Object obj){
+    if(obj == null){
+      return false;
+    }
+    
+    if(obj instanceof EdmEnumType){
+      EdmEnumType other = (EdmEnumType) obj;
+      if(this.getFullQualifiedName().equals(other.getFullQualifiedName())){
+        return true;
+      }
+    }
+    
+    return false;
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/1dd3a583/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/AbstractODataSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/AbstractODataSerializer.java
b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/AbstractODataSerializer.java
index e34817d..ee472c6 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/AbstractODataSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/AbstractODataSerializer.java
@@ -19,18 +19,18 @@
 package org.apache.olingo.server.core.serializer;
 
 import java.io.IOException;
+import java.io.OutputStream;
 
 import org.apache.olingo.server.api.serializer.ODataSerializer;
 import org.apache.olingo.server.api.serializer.SerializerException;
-import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
 
 public abstract class AbstractODataSerializer implements ODataSerializer {
 
-  protected void closeCircleStreamBufferOutput(CircleStreamBuffer buffer, SerializerException
cachedException)
+  protected void closeCircleStreamBufferOutput(OutputStream outputStream, SerializerException
cachedException)
       throws SerializerException {
-    if (buffer != null && buffer.getOutputStream() != null) {
+    if (outputStream != null) {
       try {
-        buffer.getOutputStream().close();
+        outputStream.close();
       } catch (IOException e) {
         if (cachedException != null) {
           throw cachedException;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/1dd3a583/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
index c7bd383..8c18f8f 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
@@ -19,6 +19,7 @@
 package org.apache.olingo.server.core.serializer.json;
 
 import java.io.IOException;
+import java.io.OutputStream;
 import java.util.Collections;
 import java.util.List;
 import java.util.Set;
@@ -81,23 +82,24 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
   @Override
   public SerializerResult serviceDocument(final ServiceMetadata metadata, final String serviceRoot)
       throws SerializerException {
-    CircleStreamBuffer buffer = null;
+    OutputStream outputStream = null;
     SerializerException cachedException = null;
 
     try {
-      buffer = new CircleStreamBuffer();
-      JsonGenerator json = new JsonFactory().createGenerator(buffer.getOutputStream());
+      CircleStreamBuffer buffer = new CircleStreamBuffer();
+      outputStream = buffer.getOutputStream();
+      JsonGenerator json = new JsonFactory().createGenerator(outputStream);
       new ServiceDocumentJsonSerializer(metadata, serviceRoot, isODataMetadataNone).writeServiceDocument(json);
 
       json.close();
-      buffer.getOutputStream().close();
+      outputStream.close();
       return SerializerResultImpl.with().content(buffer.getInputStream()).build();
     } catch (final IOException e) {
       cachedException =
           new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
       throw cachedException;
     } finally {
-      closeCircleStreamBufferOutput(buffer, cachedException);
+      closeCircleStreamBufferOutput(outputStream, cachedException);
     }
   }
 
@@ -109,22 +111,23 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
 
   @Override
   public SerializerResult error(final ODataServerError error) throws SerializerException
{
-    CircleStreamBuffer buffer = null;
+    OutputStream outputStream = null;
     SerializerException cachedException = null;
     try {
-      buffer = new CircleStreamBuffer();
-      JsonGenerator json = new JsonFactory().createGenerator(buffer.getOutputStream());
+      CircleStreamBuffer buffer = new CircleStreamBuffer();
+      outputStream = buffer.getOutputStream();
+      JsonGenerator json = new JsonFactory().createGenerator(outputStream);
       new ODataErrorSerializer().writeErrorDocument(json, error);
 
       json.close();
-      buffer.getOutputStream().close();
+      outputStream.close();
       return SerializerResultImpl.with().content(buffer.getInputStream()).build();
     } catch (final IOException e) {
       cachedException =
           new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
       throw cachedException;
     } finally {
-      closeCircleStreamBufferOutput(buffer, cachedException);
+      closeCircleStreamBufferOutput(outputStream, cachedException);
     }
   }
 
@@ -132,11 +135,12 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
   public SerializerResult entityCollection(final ServiceMetadata metadata,
       final EdmEntityType entityType, final EntityCollection entitySet,
       final EntityCollectionSerializerOptions options) throws SerializerException {
-    CircleStreamBuffer buffer = null;
+    OutputStream outputStream = null;
     SerializerException cachedException = null;
     try {
-      buffer = new CircleStreamBuffer();
-      JsonGenerator json = new JsonFactory().createGenerator(buffer.getOutputStream());
+      CircleStreamBuffer buffer = new CircleStreamBuffer();
+      outputStream = buffer.getOutputStream();
+      JsonGenerator json = new JsonFactory().createGenerator(outputStream);
       json.writeStartObject();
 
       final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
@@ -157,26 +161,27 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
       writeNextLink(entitySet, json);
 
       json.close();
-      buffer.getOutputStream().close();
+      outputStream.close();
       return SerializerResultImpl.with().content(buffer.getInputStream()).build();
     } catch (final IOException e) {
       cachedException =
           new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
       throw cachedException;
     } finally {
-      closeCircleStreamBufferOutput(buffer, cachedException);
+      closeCircleStreamBufferOutput(outputStream, cachedException);
     }
   }
 
   @Override
   public SerializerResult entity(final ServiceMetadata metadata, final EdmEntityType entityType,
       final Entity entity, final EntitySerializerOptions options) throws SerializerException
{
-    CircleStreamBuffer buffer = null;
+    OutputStream outputStream = null;
     SerializerException cachedException = null;
     try {
       final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
-      buffer = new CircleStreamBuffer();
-      JsonGenerator json = new JsonFactory().createGenerator(buffer.getOutputStream());
+      CircleStreamBuffer buffer = new CircleStreamBuffer();
+      outputStream = buffer.getOutputStream();
+      JsonGenerator json = new JsonFactory().createGenerator(outputStream);
       writeEntity(metadata, entityType, entity, contextURL,
           options == null ? null : options.getExpand(),
           options == null ? null : options.getSelect(),
@@ -184,14 +189,14 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
           json);
 
       json.close();
-      buffer.getOutputStream().close();
+      outputStream.close();
       return SerializerResultImpl.with().content(buffer.getInputStream()).build();
     } catch (final IOException e) {
       cachedException =
           new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
       throw cachedException;
     } finally {
-      closeCircleStreamBufferOutput(buffer, cachedException);
+      closeCircleStreamBufferOutput(outputStream, cachedException);
     }
   }
 
@@ -540,12 +545,13 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
   @Override
   public SerializerResult primitive(final ServiceMetadata metadata, final EdmPrimitiveType
type,
       final Property property, final PrimitiveSerializerOptions options) throws SerializerException
{
-    CircleStreamBuffer buffer = null;
+    OutputStream outputStream = null;
     SerializerException cachedException = null;
     try {
       final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
-      buffer = new CircleStreamBuffer();
-      JsonGenerator json = new JsonFactory().createGenerator(buffer.getOutputStream());
+      CircleStreamBuffer buffer = new CircleStreamBuffer();
+      outputStream = buffer.getOutputStream();
+      JsonGenerator json = new JsonFactory().createGenerator(outputStream);
       json.writeStartObject();
       writeContextURL(contextURL, json);
       writeMetadataETag(metadata, json);
@@ -563,7 +569,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
       json.writeEndObject();
 
       json.close();
-      buffer.getOutputStream().close();
+      outputStream.close();
       return SerializerResultImpl.with().content(buffer.getInputStream()).build();
     } catch (final IOException e) {
       cachedException =
@@ -575,19 +581,20 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
           property.getName(), property.getValue().toString());
       throw cachedException;
     } finally {
-      closeCircleStreamBufferOutput(buffer, cachedException);
+      closeCircleStreamBufferOutput(outputStream, cachedException);
     }
   }
 
   @Override
   public SerializerResult complex(final ServiceMetadata metadata, final EdmComplexType type,
       final Property property, final ComplexSerializerOptions options) throws SerializerException
{
-    CircleStreamBuffer buffer = null;
+    OutputStream outputStream = null;
     SerializerException cachedException = null;
     try {
       final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
-      buffer = new CircleStreamBuffer();
-      JsonGenerator json = new JsonFactory().createGenerator(buffer.getOutputStream());
+      CircleStreamBuffer buffer = new CircleStreamBuffer();
+      outputStream = buffer.getOutputStream();
+      JsonGenerator json = new JsonFactory().createGenerator(outputStream);
       json.writeStartObject();
       writeContextURL(contextURL, json);
       writeMetadataETag(metadata, json);
@@ -605,26 +612,27 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
       json.writeEndObject();
 
       json.close();
-      buffer.getOutputStream().close();
+      outputStream.close();
       return SerializerResultImpl.with().content(buffer.getInputStream()).build();
     } catch (final IOException e) {
       cachedException =
           new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
       throw cachedException;
     } finally {
-      closeCircleStreamBufferOutput(buffer, cachedException);
+      closeCircleStreamBufferOutput(outputStream, cachedException);
     }
   }
 
   @Override
   public SerializerResult primitiveCollection(final ServiceMetadata metadata, final EdmPrimitiveType
type,
       final Property property, final PrimitiveSerializerOptions options) throws SerializerException
{
-    CircleStreamBuffer buffer = null;
+    OutputStream outputStream = null;
     SerializerException cachedException = null;
     try {
       final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
-      buffer = new CircleStreamBuffer();
-      JsonGenerator json = new JsonFactory().createGenerator(buffer.getOutputStream());
+      CircleStreamBuffer buffer = new CircleStreamBuffer();
+      outputStream = buffer.getOutputStream();
+      JsonGenerator json = new JsonFactory().createGenerator(outputStream);
       json.writeStartObject();
       writeContextURL(contextURL, json);
       writeMetadataETag(metadata, json);
@@ -638,26 +646,27 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
       json.writeEndObject();
 
       json.close();
-      buffer.getOutputStream().close();
+      outputStream.close();
       return SerializerResultImpl.with().content(buffer.getInputStream()).build();
     } catch (final IOException e) {
       cachedException =
           new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
       throw cachedException;
     } finally {
-      closeCircleStreamBufferOutput(buffer, cachedException);
+      closeCircleStreamBufferOutput(outputStream, cachedException);
     }
   }
 
   @Override
   public SerializerResult complexCollection(final ServiceMetadata metadata, final EdmComplexType
type,
       final Property property, final ComplexSerializerOptions options) throws SerializerException
{
-    CircleStreamBuffer buffer = null;
+    OutputStream outputStream = null;
     SerializerException cachedException = null;
     try {
       final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
-      buffer = new CircleStreamBuffer();
-      JsonGenerator json = new JsonFactory().createGenerator(buffer.getOutputStream());
+      CircleStreamBuffer buffer = new CircleStreamBuffer();
+      outputStream = buffer.getOutputStream();
+      JsonGenerator json = new JsonFactory().createGenerator(outputStream);
       json.writeStartObject();
       writeContextURL(contextURL, json);
       writeMetadataETag(metadata, json);
@@ -666,28 +675,29 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
       json.writeEndObject();
 
       json.close();
-      buffer.getOutputStream().close();
+      outputStream.close();
       return SerializerResultImpl.with().content(buffer.getInputStream()).build();
     } catch (final IOException e) {
       cachedException =
           new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
       throw cachedException;
     } finally {
-      closeCircleStreamBufferOutput(buffer, cachedException);
+      closeCircleStreamBufferOutput(outputStream, cachedException);
     }
   }
 
   @Override
   public SerializerResult reference(final ServiceMetadata metadata, final EdmEntitySet edmEntitySet,
       final Entity entity, final ReferenceSerializerOptions options) throws SerializerException
{
-    CircleStreamBuffer buffer = null;
+    OutputStream outputStream = null;
     SerializerException cachedException = null;
 
     try {
       final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
-      buffer = new CircleStreamBuffer();
+      CircleStreamBuffer buffer = new CircleStreamBuffer();
       final UriHelper uriHelper = new UriHelperImpl();
-      final JsonGenerator json = new JsonFactory().createGenerator(buffer.getOutputStream());
+      outputStream = buffer.getOutputStream();
+      final JsonGenerator json = new JsonFactory().createGenerator(outputStream);
 
       json.writeStartObject();
       writeContextURL(contextURL, json);
@@ -695,14 +705,14 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
       json.writeEndObject();
 
       json.close();
-      buffer.getOutputStream().close();
+      outputStream.close();
       return SerializerResultImpl.with().content(buffer.getInputStream()).build();
     } catch (final IOException e) {
       cachedException =
           new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
       throw cachedException;
     } finally {
-      closeCircleStreamBufferOutput(buffer, cachedException);
+      closeCircleStreamBufferOutput(outputStream, cachedException);
     }
   }
 
@@ -710,14 +720,15 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
   public SerializerResult referenceCollection(final ServiceMetadata metadata, final EdmEntitySet
edmEntitySet,
       final EntityCollection entityCollection, final ReferenceCollectionSerializerOptions
options)
       throws SerializerException {
-    CircleStreamBuffer buffer = null;
+    OutputStream outputStream = null;
     SerializerException cachedException = null;
 
     try {
       final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
-      buffer = new CircleStreamBuffer();
+      CircleStreamBuffer buffer = new CircleStreamBuffer();
       final UriHelper uriHelper = new UriHelperImpl();
-      final JsonGenerator json = new JsonFactory().createGenerator(buffer.getOutputStream());
+      outputStream = buffer.getOutputStream();
+      final JsonGenerator json = new JsonFactory().createGenerator(outputStream);
       json.writeStartObject();
 
       writeContextURL(contextURL, json);
@@ -738,14 +749,14 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
       json.writeEndObject();
 
       json.close();
-      buffer.getOutputStream().close();
+      outputStream.close();
       return SerializerResultImpl.with().content(buffer.getInputStream()).build();
     } catch (final IOException e) {
       cachedException =
           new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
       throw cachedException;
     } finally {
-      closeCircleStreamBufferOutput(buffer, cachedException);
+      closeCircleStreamBufferOutput(outputStream, cachedException);
     }
 
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/1dd3a583/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
index e7d60c0..547c45f 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
@@ -19,6 +19,7 @@
 package org.apache.olingo.server.core.serializer.xml;
 
 import java.io.IOException;
+import java.io.OutputStream;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
@@ -85,18 +86,18 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
   @Override
   public SerializerResult serviceDocument(final ServiceMetadata metadata, final String serviceRoot)
       throws SerializerException {
-    CircleStreamBuffer buffer = null;
+    OutputStream outputStream = null;
     SerializerException cachedException = null;
     try {
-      buffer = new CircleStreamBuffer();
-      XMLStreamWriter xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(buffer.getOutputStream(),
-          DEFAULT_CHARSET);
+      CircleStreamBuffer buffer = new CircleStreamBuffer();
+      outputStream = buffer.getOutputStream();
+      XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream,
DEFAULT_CHARSET);
       ServiceDocumentXmlSerializer serializer = new ServiceDocumentXmlSerializer(metadata,
serviceRoot);
-      serializer.writeServiceDocument(xmlStreamWriter);
+      serializer.writeServiceDocument(writer);
 
-      xmlStreamWriter.flush();
-      xmlStreamWriter.close();
-      buffer.getOutputStream().close();
+      writer.flush();
+      writer.close();
+      outputStream.close();
 
       return SerializerResultImpl.with().content(buffer.getInputStream()).build();
     } catch (final XMLStreamException e) {
@@ -108,24 +109,24 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
           new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
       throw cachedException;
     } finally {
-      closeCircleStreamBufferOutput(buffer, cachedException);
+      closeCircleStreamBufferOutput(outputStream, cachedException);
     }
   }
 
   @Override
   public SerializerResult metadataDocument(final ServiceMetadata serviceMetadata) throws
SerializerException {
-    CircleStreamBuffer buffer = null;
+    OutputStream outputStream = null;
     SerializerException cachedException = null;
     try {
-      buffer = new CircleStreamBuffer();
-      XMLStreamWriter xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(buffer.getOutputStream(),
-          DEFAULT_CHARSET);
+      CircleStreamBuffer buffer = new CircleStreamBuffer();
+      outputStream = buffer.getOutputStream();
+      XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream,
DEFAULT_CHARSET);
       MetadataDocumentXmlSerializer serializer = new MetadataDocumentXmlSerializer(serviceMetadata);
-      serializer.writeMetadataDocument(xmlStreamWriter);
+      serializer.writeMetadataDocument(writer);
 
-      xmlStreamWriter.flush();
-      xmlStreamWriter.close();
-      buffer.getOutputStream().close();
+      writer.flush();
+      writer.close();
+      outputStream.close();
 
       return SerializerResultImpl.with().content(buffer.getInputStream()).build();
     } catch (final XMLStreamException e) {
@@ -137,7 +138,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
           new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
       throw cachedException;
     } finally {
-      closeCircleStreamBufferOutput(buffer, cachedException);
+      closeCircleStreamBufferOutput(outputStream, cachedException);
     }
   }
 
@@ -148,12 +149,12 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
           SerializerException.MessageKeys.NULL_INPUT);
     }
 
-    CircleStreamBuffer buffer = null;
+    OutputStream outputStream = null;
     SerializerException cachedException = null;
     try {
-      buffer = new CircleStreamBuffer();
-      XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(buffer.getOutputStream(),
-          DEFAULT_CHARSET);
+      CircleStreamBuffer buffer = new CircleStreamBuffer();
+      outputStream = buffer.getOutputStream();
+      XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream,
DEFAULT_CHARSET);
       writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
 
       writer.writeStartElement("error");
@@ -171,7 +172,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
 
       writer.flush();
       writer.close();
-      buffer.getOutputStream().close();
+      outputStream.close();
 
       return SerializerResultImpl.with().content(buffer.getInputStream()).build();
     } catch (final XMLStreamException e) {
@@ -183,7 +184,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
           new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
       throw cachedException;
     } finally {
-      closeCircleStreamBufferOutput(buffer, cachedException);
+      closeCircleStreamBufferOutput(outputStream, cachedException);
     }
   }
 
@@ -218,12 +219,12 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
       return entityReferenceCollection(metadata, entityType, entitySet, rso);
     }
 
-    CircleStreamBuffer buffer = null;
+    OutputStream outputStream = null;
     SerializerException cachedException = null;
     try {
-      buffer = new CircleStreamBuffer();
-      XMLStreamWriter writer =
-          XMLOutputFactory.newInstance().createXMLStreamWriter(buffer.getOutputStream(),
DEFAULT_CHARSET);
+      CircleStreamBuffer buffer = new CircleStreamBuffer();
+      outputStream = buffer.getOutputStream();
+      XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream,
DEFAULT_CHARSET);
       writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
       writer.writeStartElement(ATOM, "feed", NS_ATOM);
       writer.writeNamespace(ATOM, NS_ATOM);
@@ -260,7 +261,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
 
       writer.flush();
       writer.close();
-      buffer.getOutputStream().close();
+      outputStream.close();
 
       return SerializerResultImpl.with().content(buffer.getInputStream()).build();
     } catch (final XMLStreamException e) {
@@ -272,7 +273,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
           new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
       throw cachedException;
     } finally {
-      closeCircleStreamBufferOutput(buffer, cachedException);
+      closeCircleStreamBufferOutput(outputStream, cachedException);
     }
   }
 
@@ -287,12 +288,12 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
       return entityReference(metadata, entityType, entity, rso);
     }
 
-    CircleStreamBuffer buffer = null;
+    OutputStream outputStream = null;
     SerializerException cachedException = null;
     try {
-      buffer = new CircleStreamBuffer();
-      XMLStreamWriter writer =
-          XMLOutputFactory.newInstance().createXMLStreamWriter(buffer.getOutputStream(),
DEFAULT_CHARSET);
+      CircleStreamBuffer buffer = new CircleStreamBuffer();
+      outputStream = buffer.getOutputStream();
+      XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream,
DEFAULT_CHARSET);
       writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
       writeEntity(metadata, entityType, entity, contextURL,
           options == null ? null : options.getExpand(),
@@ -302,7 +303,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
 
       writer.flush();
       writer.close();
-      buffer.getOutputStream().close();
+      outputStream.close();
 
       return SerializerResultImpl.with().content(buffer.getInputStream()).build();
     } catch (final XMLStreamException e) {
@@ -314,7 +315,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
           new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
       throw cachedException;
     } finally {
-      closeCircleStreamBufferOutput(buffer, cachedException);
+      closeCircleStreamBufferOutput(outputStream, cachedException);
     }
   }
 
@@ -802,12 +803,12 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
       final Property property, final PrimitiveSerializerOptions options) throws SerializerException
{
     final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
 
-    CircleStreamBuffer buffer = null;
+    OutputStream outputStream = null;
     SerializerException cachedException = null;
     try {
-      buffer = new CircleStreamBuffer();
-      XMLStreamWriter writer =
-          XMLOutputFactory.newInstance().createXMLStreamWriter(buffer.getOutputStream(),
DEFAULT_CHARSET);
+      CircleStreamBuffer buffer = new CircleStreamBuffer();
+      outputStream = buffer.getOutputStream();
+      XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream,
DEFAULT_CHARSET);
 
       writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
       writer.writeStartElement(METADATA, "value", NS_METADATA);
@@ -832,7 +833,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
       writer.writeEndDocument();
       writer.flush();
       writer.close();
-      buffer.getOutputStream().close();
+      outputStream.close();
 
       return SerializerResultImpl.with().content(buffer.getInputStream()).build();
     } catch (final XMLStreamException e) {
@@ -849,7 +850,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
           new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
       throw cachedException;
     } finally {
-      closeCircleStreamBufferOutput(buffer, cachedException);
+      closeCircleStreamBufferOutput(outputStream, cachedException);
     }
   }
 
@@ -858,13 +859,13 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
       final Property property, final ComplexSerializerOptions options) throws SerializerException
{
     final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
 
-    CircleStreamBuffer buffer = null;
+    OutputStream outputStream = null;
     SerializerException cachedException = null;
     try {
       EdmComplexType resolvedType = resolveComplexType(metadata, type, property.getType());
-      buffer = new CircleStreamBuffer();
-      XMLStreamWriter writer =
-          XMLOutputFactory.newInstance().createXMLStreamWriter(buffer.getOutputStream(),
DEFAULT_CHARSET);
+      CircleStreamBuffer buffer = new CircleStreamBuffer();
+      outputStream = buffer.getOutputStream();
+      XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream,
DEFAULT_CHARSET);
       writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
       writer.writeStartElement(METADATA, "value", NS_METADATA);
       writer.writeNamespace(METADATA, NS_METADATA);
@@ -883,7 +884,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
       writer.writeEndDocument();
       writer.flush();
       writer.close();
-      buffer.getOutputStream().close();
+      outputStream.close();
 
       return SerializerResultImpl.with().content(buffer.getInputStream()).build();
     } catch (final XMLStreamException e) {
@@ -895,7 +896,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
           new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
       throw cachedException;
     } finally {
-      closeCircleStreamBufferOutput(buffer, cachedException);
+      closeCircleStreamBufferOutput(outputStream, cachedException);
     }
   }
 
@@ -904,12 +905,12 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
       final Property property, final PrimitiveSerializerOptions options) throws SerializerException
{
     final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
 
-    CircleStreamBuffer buffer = null;
+    OutputStream outputStream = null;
     SerializerException cachedException = null;
     try {
-      buffer = new CircleStreamBuffer();
-      XMLStreamWriter writer =
-          XMLOutputFactory.newInstance().createXMLStreamWriter(buffer.getOutputStream(),
DEFAULT_CHARSET);
+      CircleStreamBuffer buffer = new CircleStreamBuffer();
+      outputStream = buffer.getOutputStream();
+      XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream,
DEFAULT_CHARSET);
 
       writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
       writer.writeStartElement(METADATA, "value", NS_METADATA);
@@ -931,7 +932,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
       writer.writeEndDocument();
       writer.flush();
       writer.close();
-      buffer.getOutputStream().close();
+      outputStream.close();
 
       return SerializerResultImpl.with().content(buffer.getInputStream()).build();
     } catch (final XMLStreamException e) {
@@ -948,7 +949,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
           new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
       throw cachedException;
     } finally {
-      closeCircleStreamBufferOutput(buffer, cachedException);
+      closeCircleStreamBufferOutput(outputStream, cachedException);
     }
   }
 
@@ -957,12 +958,12 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
       final Property property, final ComplexSerializerOptions options) throws SerializerException
{
     final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
 
-    CircleStreamBuffer buffer = null;
+    OutputStream outputStream = null;
     SerializerException cachedException = null;
     try {
-      buffer = new CircleStreamBuffer();
-      XMLStreamWriter writer =
-          XMLOutputFactory.newInstance().createXMLStreamWriter(buffer.getOutputStream(),
DEFAULT_CHARSET);
+      CircleStreamBuffer buffer = new CircleStreamBuffer();
+      outputStream = buffer.getOutputStream();
+      XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream,
DEFAULT_CHARSET);
 
       writer.writeStartElement(METADATA, "value", NS_METADATA);
       writer.writeNamespace(METADATA, NS_METADATA);
@@ -976,7 +977,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
       writer.writeEndDocument();
       writer.flush();
       writer.close();
-      buffer.getOutputStream().close();
+      outputStream.close();
       return SerializerResultImpl.with().content(buffer.getInputStream()).build();
     } catch (final XMLStreamException e) {
       cachedException =
@@ -987,7 +988,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
           new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
       throw cachedException;
     } finally {
-      closeCircleStreamBufferOutput(buffer, cachedException);
+      closeCircleStreamBufferOutput(outputStream, cachedException);
     }
   }
 
@@ -999,18 +1000,18 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
 
   protected SerializerResult entityReference(final ServiceMetadata metadata, final EdmEntityType
entityType,
       final Entity entity, ReferenceSerializerOptions options) throws SerializerException
{
-    CircleStreamBuffer buffer = null;
+    OutputStream outputStream = null;
     SerializerException cachedException = null;
     try {
-      buffer = new CircleStreamBuffer();
-      XMLStreamWriter writer =
-          XMLOutputFactory.newInstance().createXMLStreamWriter(buffer.getOutputStream(),
DEFAULT_CHARSET);
+      CircleStreamBuffer buffer = new CircleStreamBuffer();
+      outputStream = buffer.getOutputStream();
+      XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream,
DEFAULT_CHARSET);
       writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
       writeReference(metadata, entityType, entity, options == null ? null : options.getContextURL(),
writer, true);
       writer.writeEndDocument();
       writer.flush();
       writer.close();
-      buffer.getOutputStream().close();
+      outputStream.close();
 
       return SerializerResultImpl.with().content(buffer.getInputStream()).build();
     } catch (final XMLStreamException e) {
@@ -1022,7 +1023,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
           new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
       throw cachedException;
     } finally {
-      closeCircleStreamBufferOutput(buffer, cachedException);
+      closeCircleStreamBufferOutput(outputStream, cachedException);
     }
   }
 
@@ -1050,12 +1051,12 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
   protected SerializerResult entityReferenceCollection(final ServiceMetadata metadata,
       final EdmEntityType entityType, final EntityCollection entitySet,
       ReferenceCollectionSerializerOptions options) throws SerializerException {
-    CircleStreamBuffer buffer = null;
+    OutputStream outputStream = null;
     SerializerException cachedException = null;
     try {
-      buffer = new CircleStreamBuffer();
-      XMLStreamWriter writer =
-          XMLOutputFactory.newInstance().createXMLStreamWriter(buffer.getOutputStream(),
DEFAULT_CHARSET);
+      CircleStreamBuffer buffer = new CircleStreamBuffer();
+      outputStream = buffer.getOutputStream();
+      XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream,
DEFAULT_CHARSET);
       writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
       writer.writeStartElement(ATOM, "feed", NS_ATOM);
       writer.writeNamespace(ATOM, NS_ATOM);
@@ -1078,7 +1079,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
       writer.writeEndDocument();
       writer.flush();
       writer.close();
-      buffer.getOutputStream().close();
+      outputStream.close();
 
       return SerializerResultImpl.with().content(buffer.getInputStream()).build();
     } catch (final XMLStreamException e) {
@@ -1090,7 +1091,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
           new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
       throw cachedException;
     } finally {
-      closeCircleStreamBufferOutput(buffer, cachedException);
+      closeCircleStreamBufferOutput(outputStream, cachedException);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/1dd3a583/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java
b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java
index f87c47f..25dcb03 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java
@@ -51,6 +51,7 @@ import org.mockito.Mockito;
 public class EdmEnumTest {
 
   private final EdmEnumType instance;
+  private final EdmEnumType otherInstance;
   private final EdmEnumType nonFlagsInstance;
   private final EdmEnumType int16EnumType;
   private final EdmEnumType int32EnumType;
@@ -66,6 +67,10 @@ public class EdmEnumTest {
     instance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName,
         new CsdlEnumType().setName("name").setMembers(memberList).setFlags(true)
             .setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName()));
+    
+    otherInstance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName,
+        new CsdlEnumType().setName("name").setMembers(memberList).setFlags(true)
+            .setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName()));
 
     nonFlagsInstance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName,
         new CsdlEnumType().setName("name").setMembers(memberList).setFlags(false)
@@ -128,6 +133,7 @@ public class EdmEnumTest {
   @Test
   public void compatibility() {
     assertTrue(instance.isCompatible(instance));
+    assertTrue(instance.isCompatible(otherInstance));
     assertFalse(instance.isCompatible(instance.getUnderlyingType()));
   }
 


Mime
View raw message