flume-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject [10/24] git commit: FLUME-1662: Convert null body in events into zero length arrays
Date Tue, 30 Oct 2012 22:59:40 GMT
FLUME-1662: Convert null body in events into zero length arrays

(Hari Shreedharan via Brock Noland)


Project: http://git-wip-us.apache.org/repos/asf/flume/repo
Commit: http://git-wip-us.apache.org/repos/asf/flume/commit/8f6d1a1d
Tree: http://git-wip-us.apache.org/repos/asf/flume/tree/8f6d1a1d
Diff: http://git-wip-us.apache.org/repos/asf/flume/diff/8f6d1a1d

Branch: refs/heads/FLUME-1502
Commit: 8f6d1a1df59fef97755ed5158b87bf723a2660f7
Parents: 5416e77
Author: Brock Noland <brock@apache.org>
Authored: Thu Oct 25 11:41:00 2012 -0500
Committer: Brock Noland <brock@apache.org>
Committed: Thu Oct 25 11:41:00 2012 -0500

----------------------------------------------------------------------
 .../apache/flume/source/http/TestJSONHandler.java  |    4 ++--
 .../java/org/apache/flume/event/EventBuilder.java  |    3 +++
 .../java/org/apache/flume/event/JSONEvent.java     |    8 ++++++--
 .../java/org/apache/flume/event/SimpleEvent.java   |    5 ++++-
 4 files changed, 15 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flume/blob/8f6d1a1d/flume-ng-core/src/test/java/org/apache/flume/source/http/TestJSONHandler.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/http/TestJSONHandler.java
b/flume-ng-core/src/test/java/org/apache/flume/source/http/TestJSONHandler.java
index e8f256b..455781c 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/source/http/TestJSONHandler.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/source/http/TestJSONHandler.java
@@ -113,7 +113,7 @@ public class TestJSONHandler {
     List<Event> deserialized = handler.getEvents(req);
     Event e = deserialized.get(0);
     Assert.assertEquals("b", e.getHeaders().get("a"));
-    Assert.assertTrue(e.getBody() == null);
+    Assert.assertTrue(e.getBody().length == 0);
     e = deserialized.get(1);
     Assert.assertEquals("f", e.getHeaders().get("e"));
     Assert.assertEquals("rand\"om_body2", new String(e.getBody(),"UTF-8"));
@@ -127,7 +127,7 @@ public class TestJSONHandler {
     List<Event> deserialized = handler.getEvents(req);
     Event e = deserialized.get(0);
     Assert.assertEquals("b", e.getHeaders().get("a"));
-    Assert.assertTrue(e.getBody() == null);
+    Assert.assertTrue(e.getBody().length == 0);
     e = deserialized.get(1);
     Assert.assertEquals("f", e.getHeaders().get("e"));
     Assert.assertEquals("random_body2", new String(e.getBody(),"UTF-8"));

http://git-wip-us.apache.org/repos/asf/flume/blob/8f6d1a1d/flume-ng-sdk/src/main/java/org/apache/flume/event/EventBuilder.java
----------------------------------------------------------------------
diff --git a/flume-ng-sdk/src/main/java/org/apache/flume/event/EventBuilder.java b/flume-ng-sdk/src/main/java/org/apache/flume/event/EventBuilder.java
index 4d96114..a5e01fc 100644
--- a/flume-ng-sdk/src/main/java/org/apache/flume/event/EventBuilder.java
+++ b/flume-ng-sdk/src/main/java/org/apache/flume/event/EventBuilder.java
@@ -37,6 +37,9 @@ public class EventBuilder {
   public static Event withBody(byte[] body, Map<String, String> headers) {
     Event event = new SimpleEvent();
 
+    if(body == null) {
+      body = new byte[0];
+    }
     event.setBody(body);
 
     if (headers != null) {

http://git-wip-us.apache.org/repos/asf/flume/blob/8f6d1a1d/flume-ng-sdk/src/main/java/org/apache/flume/event/JSONEvent.java
----------------------------------------------------------------------
diff --git a/flume-ng-sdk/src/main/java/org/apache/flume/event/JSONEvent.java b/flume-ng-sdk/src/main/java/org/apache/flume/event/JSONEvent.java
index e62f689..5c6c0d4 100644
--- a/flume-ng-sdk/src/main/java/org/apache/flume/event/JSONEvent.java
+++ b/flume-ng-sdk/src/main/java/org/apache/flume/event/JSONEvent.java
@@ -50,14 +50,18 @@ public class JSONEvent implements Event{
         return null;
       }
     } else {
-      return null;
+      return new byte[0];
     }
 
   }
 
   @Override
   public void setBody(byte[] body) {
-    this.body = new String(body);
+    if(body != null) {
+      this.body = new String(body);
+    } else {
+      this.body = "";
+    }
   }
 
   public void setCharset(String charset) {

http://git-wip-us.apache.org/repos/asf/flume/blob/8f6d1a1d/flume-ng-sdk/src/main/java/org/apache/flume/event/SimpleEvent.java
----------------------------------------------------------------------
diff --git a/flume-ng-sdk/src/main/java/org/apache/flume/event/SimpleEvent.java b/flume-ng-sdk/src/main/java/org/apache/flume/event/SimpleEvent.java
index fed7bb6..a7ac36f 100644
--- a/flume-ng-sdk/src/main/java/org/apache/flume/event/SimpleEvent.java
+++ b/flume-ng-sdk/src/main/java/org/apache/flume/event/SimpleEvent.java
@@ -31,7 +31,7 @@ public class SimpleEvent implements Event {
 
   public SimpleEvent() {
     headers = new HashMap<String, String>();
-    body = null;
+    body = new byte[0];
   }
 
   @Override
@@ -51,6 +51,9 @@ public class SimpleEvent implements Event {
 
   @Override
   public void setBody(byte[] body) {
+    if(body == null){
+      body = new byte[0];
+    }
     this.body = body;
   }
 


Mime
View raw message