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 ; }
Returns a single byte array containing all of the individual component arrays separated by the separator array .