@Test public void testJoin() { byte[] comp1 = Bytes.toBytes("abc"); byte[] comp2 = Bytes.toBytes("def"); byte[] comp3 = Bytes.toBytes("ghi"); byte[] joined = ByteUtil.join(Constants.SEP_BYTES); assertNotNull(joined); assertEquals(0, joined.length); joined = ByteUtil.join(null, comp1, comp2, comp3); assertNotNull(joined); assertArrayEquals(Bytes.toBytes("abcdefghi"), joined); joined = ByteUtil.join(Constants.SEP_BYTES, comp1, comp2, comp3); assertNotNull(joined); assertArrayEquals( Bytes.toBytes("abc"+Constants.SEP+"def"+Constants.SEP+"ghi"), joined); }
public static byte[] join(byte[] separator, byte[]... components) { if (components == null || components.length == 0) { return Constants.EMPTY_BYTES; } int finalSize = 0; if (separator != null) { finalSize = separator.length * (components.length - 1); } for (byte[] comp : components) { finalSize += comp.length; } byte[] buf = new byte[finalSize]; int offset = 0; for (int i=0; i < components.length; i++) { System.arraycopy(components[i], 0, buf, offset, components[i].length); offset += components[i].length; if (i < (components.length-1) && separator != null && separator.length > 0) { System.arraycopy(separator, 0, buf, offset, separator.length); offset += separator.length; } } return buf; }
ByteUtil { public static byte[] join(byte[] separator, byte[]... components) { if (components == null || components.length == 0) { return Constants.EMPTY_BYTES; } int finalSize = 0; if (separator != null) { finalSize = separator.length * (components.length - 1); } for (byte[] comp : components) { finalSize += comp.length; } byte[] buf = new byte[finalSize]; int offset = 0; for (int i=0; i < components.length; i++) { System.arraycopy(components[i], 0, buf, offset, components[i].length); offset += components[i].length; if (i < (components.length-1) && separator != null && separator.length > 0) { System.arraycopy(separator, 0, buf, offset, separator.length); offset += separator.length; } } return buf; } }
ByteUtil { public static byte[] join(byte[] separator, byte[]... components) { if (components == null || components.length == 0) { return Constants.EMPTY_BYTES; } int finalSize = 0; if (separator != null) { finalSize = separator.length * (components.length - 1); } for (byte[] comp : components) { finalSize += comp.length; } byte[] buf = new byte[finalSize]; int offset = 0; for (int i=0; i < components.length; i++) { System.arraycopy(components[i], 0, buf, offset, components[i].length); offset += components[i].length; if (i < (components.length-1) && separator != null && separator.length > 0) { System.arraycopy(separator, 0, buf, offset, separator.length); offset += separator.length; } } return buf; }  }
ByteUtil { public static byte[] join(byte[] separator, byte[]... components) { if (components == null || components.length == 0) { return Constants.EMPTY_BYTES; } int finalSize = 0; if (separator != null) { finalSize = separator.length * (components.length - 1); } for (byte[] comp : components) { finalSize += comp.length; } byte[] buf = new byte[finalSize]; int offset = 0; for (int i=0; i < components.length; i++) { System.arraycopy(components[i], 0, buf, offset, components[i].length); offset += components[i].length; if (i < (components.length-1) && separator != null && separator.length > 0) { System.arraycopy(separator, 0, buf, offset, separator.length); offset += separator.length; } } return buf; }  static byte[][] split(byte[] source, byte[] separator); static byte[][] split(byte[] source, byte[] separator, int limit); static List<Range> splitRanges(byte[] source, byte[] separator); static List<Range> splitRanges(byte[] source, byte[] separator, int limit); static byte[] join(byte[] separator, byte[]... components); static int indexOf(byte[] array, byte[] target, int fromIndex); static byte[] safeCopy(byte[] source, int offset, int length); static long getValueAsLong(final byte[] key,
      final Map<byte[], byte[]> taskValues); static String getValueAsString(final byte[] key,
      final Map<byte[], byte[]> taskValues); static double getValueAsDouble(byte[] key,
      NavigableMap<byte[], byte[]> infoValues); static int getValueAsInt(byte[] key, Map<byte[], byte[]> infoValues); }
ByteUtil { public static byte[] join(byte[] separator, byte[]... components) { if (components == null || components.length == 0) { return Constants.EMPTY_BYTES; } int finalSize = 0; if (separator != null) { finalSize = separator.length * (components.length - 1); } for (byte[] comp : components) { finalSize += comp.length; } byte[] buf = new byte[finalSize]; int offset = 0; for (int i=0; i < components.length; i++) { System.arraycopy(components[i], 0, buf, offset, components[i].length); offset += components[i].length; if (i < (components.length-1) && separator != null && separator.length > 0) { System.arraycopy(separator, 0, buf, offset, separator.length); offset += separator.length; } } return buf; }  static byte[][] split(byte[] source, byte[] separator); static byte[][] split(byte[] source, byte[] separator, int limit); static List<Range> splitRanges(byte[] source, byte[] separator); static List<Range> splitRanges(byte[] source, byte[] separator, int limit); static byte[] join(byte[] separator, byte[]... components); static int indexOf(byte[] array, byte[] target, int fromIndex); static byte[] safeCopy(byte[] source, int offset, int length); static long getValueAsLong(final byte[] key,
      final Map<byte[], byte[]> taskValues); static String getValueAsString(final byte[] key,
      final Map<byte[], byte[]> taskValues); static double getValueAsDouble(byte[] key,
      NavigableMap<byte[], byte[]> infoValues); static int getValueAsInt(byte[] key, Map<byte[], byte[]> infoValues);  }