You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2015/07/16 07:54:04 UTC
olingo-odata2 git commit: [OLINGO-725] Improved use buffer
Repository: olingo-odata2
Updated Branches:
refs/heads/master 03273ef15 -> ea04bfc91
[OLINGO-725] Improved use buffer
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/ea04bfc9
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/ea04bfc9
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/ea04bfc9
Branch: refs/heads/master
Commit: ea04bfc91daa26686a0e9f874f941e0e37712c9f
Parents: 03273ef
Author: Michael Bolz <mi...@sap.com>
Authored: Thu Jul 16 07:53:52 2015 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Thu Jul 16 07:53:52 2015 +0200
----------------------------------------------------------------------
.../apache/olingo/odata2/api/processor/ODataResponse.java | 9 +++++----
.../org/apache/olingo/odata2/core/servlet/ODataServlet.java | 6 ++++--
2 files changed, 9 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/ea04bfc9/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/processor/ODataResponse.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/processor/ODataResponse.java b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/processor/ODataResponse.java
index 2035b25..7d3ea77 100644
--- a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/processor/ODataResponse.java
+++ b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/processor/ODataResponse.java
@@ -58,11 +58,12 @@ public abstract class ODataResponse {
* @throws ODataException throws ODataException in case of entity is not a stream (internal ClassCastException)
*/
public InputStream getEntityAsStream() throws ODataException {
- try {
- return (InputStream) getEntity();
- } catch (ClassCastException e) {
- throw new ODataException(e);
+ Object obj = getEntity();
+ if(obj instanceof InputStream) {
+ return (InputStream) obj;
}
+ throw new ODataException("Entity is not an instance of an InputStream (entity class: " +
+ (obj == null ? "NULL": obj.getClass()) + ")");
}
/**
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/ea04bfc9/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
index ddce4fb..f3c8a20 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
@@ -249,11 +249,11 @@ public class ODataServlet extends HttpServlet {
Object entity = response.getEntity();
if (entity != null) {
ServletOutputStream out = resp.getOutputStream();
- int len;
int contentLength = 0;
- byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
if (entity instanceof InputStream) {
+ int len;
+ byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
InputStream stream = (InputStream) entity;
while ((len = stream.read(buffer)) != -1) {
contentLength += len;
@@ -265,6 +265,8 @@ public class ODataServlet extends HttpServlet {
final byte[] entityBytes = body.getBytes(DEFAULT_READ_CHARSET);
out.write(entityBytes);
contentLength = entityBytes.length;
+ } else {
+ throw new IOException("Illegal entity object in ODataResponse of type '" + entity.getClass() + "'.");
}
if (response.getHeader(HttpHeaders.CONTENT_LENGTH) != null) {