You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@fluo.apache.org by gi...@git.apache.org on 2017/06/22 20:22:12 UTC

[GitHub] cjmctague commented on a change in pull request #875: fixes #830

cjmctague commented on a change in pull request #875: fixes #830
URL: https://github.com/apache/incubator-fluo/pull/875#discussion_r123612608
 
 

 ##########
 File path: modules/accumulo/src/main/java/org/apache/fluo/accumulo/util/ByteArrayUtil.java
 ##########
 @@ -98,21 +96,59 @@ public static long decodeLong(byte[] ba) {
    * @param listOfBytes Bytes objects to concatenate
    * @return Bytes
    */
-  public static final byte[] concat(Bytes... listOfBytes) {
-    try {
-      // TODO calculate exact array size needed
-      ByteArrayOutputStream baos = new ByteArrayOutputStream();
-      DataOutputStream dos = new DataOutputStream(baos);
-
-      for (Bytes b : listOfBytes) {
-        WritableUtils.writeVInt(dos, b.length());
-        b.writeTo(dos);
-      }
+  public static byte[] concat(Bytes... listOfBytes) {
+    int offset = 0;
+    int counter = 0;
 
-      dos.close();
-      return baos.toByteArray();
-    } catch (IOException e) {
-      throw new RuntimeException(e);
+    for (Bytes b : listOfBytes) {
+      counter += b.length() + 1;
 
 Review comment:
   The +1 always space to store the number from `writeVint` in `data[]` 
   
   
   ```
   Output of data[]:
   
   4 <- vInt
   115
   116
   114
   49
   7 <-vInt
   115
   116
   114
   105
   110
   103
   50
   2 <- vInt
   115
   51
   ```
   Wouldn't I still need the +1? with the implementation of vLen(int i)?
   ```
   for (Bytes b : listOfBytes) {
         counter += vLen(b.length()) + 1;
   }
   ```
   I'm probably just not understanding it.
   
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services