Java ByteBuffer Allocate fromBytes(byte[] data, boolean[] preAllocatedValues)

Here you can find the source of fromBytes(byte[] data, boolean[] preAllocatedValues)

Description

from Bytes

License

Open Source License

Declaration

protected static void fromBytes(byte[] data, boolean[] preAllocatedValues) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

public class Main {
    protected static void fromBytes(byte[] data, int[] preAllocatedValues) {
        final ByteBuffer byteBuffer = ByteBuffer.wrap(data);
        for (int i = 0; i < preAllocatedValues.length; i++) {
            preAllocatedValues[i] = byteBuffer.getInt();
        }/* w  w  w .j  a v  a2 s  .c o  m*/
    }

    protected static void fromBytes(byte[] data, long[] preAllocatedValues) {
        final ByteBuffer byteBuffer = ByteBuffer.wrap(data);
        for (int i = 0; i < preAllocatedValues.length; i++) {
            preAllocatedValues[i] = byteBuffer.getLong();
        }
    }

    protected static void fromBytes(byte[] data, short[] preAllocatedValues) {
        final ByteBuffer byteBuffer = ByteBuffer.wrap(data);
        for (int i = 0; i < preAllocatedValues.length; i++) {
            preAllocatedValues[i] = byteBuffer.getShort();
        }
    }

    protected static void fromBytes(byte[] data, char[] preAllocatedValues) {
        final ByteBuffer byteBuffer = ByteBuffer.wrap(data);
        for (int i = 0; i < preAllocatedValues.length; i++) {
            preAllocatedValues[i] = byteBuffer.getChar();
        }
    }

    protected static void fromBytes(byte[] data, boolean[] preAllocatedValues) {
        final ByteBuffer byteBuffer = ByteBuffer.wrap(data);
        for (int i = 0; i < preAllocatedValues.length; i++) {
            preAllocatedValues[i] = byteBuffer.get() == 1;
        }
    }

    protected static void fromBytes(byte[] data, byte[] preAllocatedValues) {
        final ByteBuffer byteBuffer = ByteBuffer.wrap(data);
        for (int i = 0; i < preAllocatedValues.length; i++) {
            preAllocatedValues[i] = byteBuffer.get();
        }
    }

    protected static void fromBytes(byte[] data, double[] preAllocatedValues) {
        final ByteBuffer byteBuffer = ByteBuffer.wrap(data);
        for (int i = 0; i < preAllocatedValues.length; i++) {
            preAllocatedValues[i] = byteBuffer.getDouble();
        }

    }

    public static void fromBytes(byte[] data, float[] preAllocatedValues) {
        final ByteBuffer byteBuffer = ByteBuffer.wrap(data);
        for (int i = 0; i < preAllocatedValues.length; i++) {
            preAllocatedValues[i] = byteBuffer.getFloat();
        }
    }
}

Related

  1. allocateFloats(final int howmany, final int SIZE)
  2. allocateInt()
  3. allocateInts(final int[] intarray, final int SIZE)
  4. allocateNativeOrderDirectBuffer(int size)
  5. allocateTestBuffer(int capacity, boolean direct)