Java ByteBuffer Set blockCopy(ByteBuffer source, int srcOffset, byte[] dest, int destOffset, int count)

Here you can find the source of blockCopy(ByteBuffer source, int srcOffset, byte[] dest, int destOffset, int count)

Description

block Copy

License

Open Source License

Declaration

public static boolean blockCopy(ByteBuffer source, int srcOffset, byte[] dest, int destOffset, int count) 

Method Source Code

//package com.java2s;
/* ************************************************************************
#
#  DivConq/*from   w  ww . j ava2  s .co  m*/
#
#  http://divconq.com/
#
#  Copyright:
#    Copyright 2014 eTimeline, LLC. All rights reserved.
#
#  License:
#    See the license.txt file in the project's top-level directory for details.
#
#  Authors:
#    * Andy White
#
************************************************************************ */

import java.nio.ByteBuffer;

public class Main {
    public static boolean blockCopy(byte[] source, int srcOffset, byte[] dest, int destOffset, int count) {
        if ((source == null) || (dest == null))
            return false;

        if ((srcOffset < 0) || (destOffset < 0) || (count <= 0))
            return false;

        if ((source.length - srcOffset) < count)
            return false;

        if ((dest.length - destOffset) < count)
            return false;

        System.arraycopy(source, srcOffset, dest, destOffset, count);

        return true;
    }

    public static boolean blockCopy(ByteBuffer source, int srcOffset, byte[] dest, int destOffset, int count) {
        if ((source == null) || (dest == null))
            return false;

        if ((srcOffset < 0) || (destOffset < 0) || (count <= 0))
            return false;

        if ((source.limit() - srcOffset) < count)
            return false;

        if ((dest.length - destOffset) < count)
            return false;

        source.position(srcOffset);
        source.get(dest, destOffset, count);

        return true;
    }

    public static boolean blockCopy(byte[] source, int srcOffset, ByteBuffer dest, int destOffset, int count) {
        if ((source == null) || (dest == null))
            return false;

        if ((srcOffset < 0) || (destOffset < 0) || (count <= 0))
            return false;

        if ((source.length - srcOffset) < count)
            return false;

        if ((dest.limit() - destOffset) < count)
            return false;

        dest.position(destOffset);
        dest.put(source, srcOffset, count);

        return true;
    }

    public static boolean blockCopy(ByteBuffer source, int srcOffset, ByteBuffer dest, int destOffset, int count) {
        if ((source == null) || (dest == null))
            return false;

        if ((srcOffset < 0) || (destOffset < 0) || (count <= 0))
            return false;

        if ((source.limit() - srcOffset) < count)
            return false;

        if ((dest.limit() - destOffset) < count)
            return false;

        int sl = source.limit();
        source.limit(srcOffset + count);
        dest.position(destOffset);
        dest.put(source);
        source.limit(sl);

        return true;
    }
}

Related

  1. arrayCopy(ByteBuffer buffer, int position, byte[] bytes, int offset, int length)
  2. base64FormatOfBinarySet(Collection bs)
  3. byteBuffersToString(ByteBuffer[] bufs, Charset cs)
  4. byteIndexOf(ByteBuffer buffer, byte[] temp, int offset)
  5. c_memset(ByteBuffer b, int c_, int size)
  6. charSequence2ByteBuffer(CharSequence cs, Charset charset)