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

 ##########
 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;
+    }
+
+    byte[] data = new byte[counter];
+    for (Bytes b : listOfBytes) {
+      writeVint(data, offset, b.length());
+      offset++;
 
 Review comment:
   `writeVint` could return offset, then could write `offset = writeVint(data, 
offset, b.length())` instead of `offset++`
 
----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to