Java Integer Create toIntegerArray(byte[] input, int offset, int len)

Here you can find the source of toIntegerArray(byte[] input, int offset, int len)

Description

to Integer Array

License

Apache License

Declaration

public static int[] toIntegerArray(byte[] input, int offset, int len) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static int[] toIntegerArray(byte[] input, int offset, int len) {
        assert len % 4 == 0 : "Must be a multiple of 4 bytes";
        int[] result = new int[len / 4];
        toIntegerArray(input, offset, len, result, 0);
        return result;
    }/* w w  w . ja v a 2 s  . co m*/

    public static void toIntegerArray(byte[] input, int offset, int len, int[] output, int outputOffset) {
        assert len % 4 == 0 : "Must be a multiple of 4 bytes";
        int outputLen = len / 4;
        assert offset + outputLen < output.length : "Output buffer too short";
        for (int i = outputOffset; i < outputOffset + outputLen; i++) {
            output[i] = toInteger(input, offset);
            offset += 4;
        }
    }

    public static int toInteger(byte[] input) {
        return toInteger(input, 0);
    }

    private static int toInteger(byte[] input, int offset) {
        assert offset + 4 <= input.length : "Invalid length " + input.length;
        return ((input[offset++] & 0xff) << 24) | ((input[offset++] & 0xff) << 16) | ((input[offset++] & 0xff) << 8)
                | ((input[offset++] & 0xff));
    }
}

Related

  1. toInteger(String value, int defaultValue)
  2. toInteger(String value, Integer defValue)
  3. toInteger(String[] s)
  4. toInteger(String[] source)
  5. toInteger(StringBuilder value)
  6. toIntegerArray(double[] doubles)
  7. toIntegerArray(final int[] array)
  8. toIntegerArray(final int[] ints)
  9. toIntegerArray(String text, String delimiter)