Java Array Join join(byte[]... bs)

Here you can find the source of join(byte[]... bs)

Description

Join.

License

Open Source License

Parameter

Parameter Description
bs the bs

Return

the byte[]

Declaration

public static byte[] join(byte[]... bs) 

Method Source Code

//package com.java2s;
/**/*from   ww  w  .j av a 2 s  . co  m*/
 * This file is part of the Nilestore project.
 * 
 * Copyright (C) (2011) Nile University (NU)
 *
 * Nilestore is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

import java.util.List;

public class Main {
    /**
     * Join.
     * 
     * @param bs
     *            the bs
     * @return the byte[]
     */
    public static byte[] join(byte[]... bs) {
        int len = 0;
        for (byte[] b : bs) {
            len += b.length;
        }

        byte[] out = new byte[len];
        int offset = 0;
        for (byte[] b : bs) {
            System.arraycopy(b, 0, out, offset, b.length);
            offset += b.length;
        }
        return out;
    }

    /**
     * Join.
     * 
     * @param bs
     *            the bs
     * @return the byte[]
     */
    public static byte[] join(List<byte[]> bs) {
        int len = 0;
        for (byte[] b : bs) {
            len += b.length;
        }
        byte[] out = new byte[len];
        int offset = 0;
        for (byte[] b : bs) {
            System.arraycopy(b, 0, out, offset, b.length);
            offset += b.length;
        }
        return out;
    }
}

Related

  1. arrayJoin(int[] a, int[] b)
  2. arrayJoin(String[] arr, String joinStr)
  3. arrayJoin(String[] array, char with)
  4. arrayJoinToString(Object[] array, CharSequence delim)
  5. join(char sep, Object[] array)
  6. join(CharSequence separator, String[] strings)
  7. join(CharSequence[] strings, CharSequence separator)
  8. join(final Object[] array)