Clover icon

sunshower-base

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

File Longs.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

6
23
2
1
44
41
5
0.22
11.5
2
2.5

Classes

Class Line # Actions
Longs 3 23 5
0.935483993.5%
 

Contributing tests

This file is covered by 1 test. .

Source view

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