Clover icon

sunshower-base

  1. Project Clover database Fri Apr 6 2018 03:41:27 UTC
  2. Package io.sunshower.lang.primitives

File Integers.java

 

Coverage histogram

../../../../img/srcFileCovDistChart9.png
16% of files have more coverage

Code metrics

6
19
3
1
34
30
6
0.32
6.33
3
2

Classes

Class Line # Actions
Integers 3 19 6
0.8928571389.3%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    package io.sunshower.lang.primitives;
2   
 
3    public class Integers {
4   
 
5  0 toggle private Integers() {}
6   
 
7  1 toggle public static byte[] toByteArray(int[] integers) {
8  1 final int length = integers.length;
9  1 final byte[] bytes = new byte[length * 4];
10  11 for (int i = 0, k = 0; i < length; i++) {
11  10 int j = integers[i];
12  10 bytes[k] = (byte) (j >>> 24);
13  10 bytes[k + 1] = (byte) (j >>> 16);
14  10 bytes[k + 2] = (byte) (j >>> 8);
15  10 bytes[k + 3] = (byte) j;
16  10 k += 4;
17    }
18  1 return bytes;
19    }
20   
 
21  1 toggle public static int[] fromByteArray(byte[] b) {
22  1 final int len = b.length;
23  1 if (len % 4 != 0) {
24  0 throw new IllegalArgumentException("Byte array must be divisible by 4");
25    }
26  1 final int[] result = new int[len / 4];
27  11 for (int i = 0, j = 0; i < result.length; i++) {
28  10 int r = b[j] << 24 | (b[j + 1] & 0xFF) << 16 | (b[j + 2] & 0xFF) << 8 | (b[j + 3] & 0xFF);
29  10 result[i] = r;
30  10 j += 4;
31    }
32  1 return result;
33    }
34    }