Java ByteBuffer Concatenate concat(ByteBuffer[] buffers, ByteBuffer buffer)

Here you can find the source of concat(ByteBuffer[] buffers, ByteBuffer buffer)

Description

concat

License

Open Source License

Declaration

public static ByteBuffer[] concat(ByteBuffer[] buffers, ByteBuffer buffer) 

Method Source Code

//package com.java2s;
/*/*from   w w w . j a  va  2  s  .  c om*/
Copyright (c) 2008-2011 Christoffer Lern?
    
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
    
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
    
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

import java.nio.ByteBuffer;

public class Main {
    public static ByteBuffer[] concat(ByteBuffer[] buffers, ByteBuffer buffer) {
        return concat(buffers, new ByteBuffer[] { buffer });
    }

    public static ByteBuffer[] concat(ByteBuffer buffer, ByteBuffer[] buffers2) {
        return concat(new ByteBuffer[] { buffer }, buffers2);
    }

    public static ByteBuffer[] concat(ByteBuffer[] buffers1, ByteBuffer[] buffers2) {
        if (buffers1 == null || buffers1.length == 0)
            return buffers2;
        if (buffers2 == null || buffers2.length == 0)
            return buffers1;
        ByteBuffer[] newBuffers = new ByteBuffer[buffers1.length + buffers2.length];
        System.arraycopy(buffers1, 0, newBuffers, 0, buffers1.length);
        System.arraycopy(buffers2, 0, newBuffers, buffers1.length, buffers2.length);
        return newBuffers;
    }
}

Related

  1. concat(byte[] pre, ByteBuffer bbuf)
  2. concat(ByteBuffer b1, ByteBuffer b2)
  3. concat(ByteBuffer outPart1, ByteBuffer outPart2)
  4. concat(ByteBuffer[] buf1, ByteBuffer[] buf2)
  5. concat(ByteBuffer[] buffers, int overAllCapacity)
  6. concat(List bbs)
  7. concatenateBytebuffers(ArrayList buffers)