fluo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ktur...@apache.org
Subject incubator-fluo git commit: Added Append Method for BytesBuilder to take byte[], offset, and length. Added unit test to test method.
Date Tue, 26 Jul 2016 21:21:06 GMT
Repository: incubator-fluo
Updated Branches:
  refs/heads/master 19b64c115 -> 5ed9f2d86


Added Append Method for BytesBuilder to take byte[], offset, and length.
Added unit test to test method.


Project: http://git-wip-us.apache.org/repos/asf/incubator-fluo/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-fluo/commit/5ed9f2d8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-fluo/tree/5ed9f2d8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-fluo/diff/5ed9f2d8

Branch: refs/heads/master
Commit: 5ed9f2d8624a4c07f5d22718ca13af5c1f1d2b1d
Parents: 19b64c1
Author: Christopher McTague <cjmctague@vwc.edu>
Authored: Tue Jul 26 14:57:32 2016 -0400
Committer: Christopher McTague <cjmctague@vwc.edu>
Committed: Tue Jul 26 14:58:10 2016 -0400

----------------------------------------------------------------------
 .../org/apache/fluo/api/data/BytesBuilder.java     | 17 +++++++++++++++++
 .../apache/fluo/core/data/BytesBuilderTest.java    | 14 ++++++++++++++
 2 files changed, 31 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-fluo/blob/5ed9f2d8/modules/api/src/main/java/org/apache/fluo/api/data/BytesBuilder.java
----------------------------------------------------------------------
diff --git a/modules/api/src/main/java/org/apache/fluo/api/data/BytesBuilder.java b/modules/api/src/main/java/org/apache/fluo/api/data/BytesBuilder.java
index 549b9e9..1ca721c 100644
--- a/modules/api/src/main/java/org/apache/fluo/api/data/BytesBuilder.java
+++ b/modules/api/src/main/java/org/apache/fluo/api/data/BytesBuilder.java
@@ -90,6 +90,23 @@ public class BytesBuilder {
   }
 
   /**
+   * Append a section of bytes from array
+   * 
+   * @param bytes - bytes to be appended
+   * @param offset - start of bytes to be appended
+   * @param length - how many bytes from 'offset' to be appended
+   * @return self
+   */
+  public BytesBuilder append(byte[] bytes, int offset, int length) {
+    ensureCapacity(len + length);
+    System.arraycopy(bytes, offset, ba, len, length);
+    len += length;
+
+    return this;
+  }
+
+
+  /**
    * Sets the point at which appending will start. This method can shrink or grow the ByteBuilder
    * from its current state. If it grows it will zero pad.
    */

http://git-wip-us.apache.org/repos/asf/incubator-fluo/blob/5ed9f2d8/modules/core/src/test/java/org/apache/fluo/core/data/BytesBuilderTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/fluo/core/data/BytesBuilderTest.java b/modules/core/src/test/java/org/apache/fluo/core/data/BytesBuilderTest.java
index e543863..37c011f 100644
--- a/modules/core/src/test/java/org/apache/fluo/core/data/BytesBuilderTest.java
+++ b/modules/core/src/test/java/org/apache/fluo/core/data/BytesBuilderTest.java
@@ -71,6 +71,20 @@ public class BytesBuilderTest {
   }
 
   @Test
+  public void testArraySection() {
+    BytesBuilder bb = Bytes.newBuilder();
+
+    byte[] testing = new byte[] {'a', 'b', 'c', 'd', 'e'};
+
+    bb.append(testing, 0, 3);
+    bb.append(testing, 1, 3);
+    bb.append(testing, 2, 2);
+
+    Bytes bytes = bb.toBytes();
+    Assert.assertEquals(Bytes.of("abcbcdcd"), bytes);
+  }
+
+  @Test
   public void testIncreaseCapacity() {
 
     // test appending 3 chars at a time


Mime
View raw message