Debian Codegraph @

src/org/tukaani/xz/common/ByteArrayView.java

raw symbols SCIP
1 // SPDX-License-Identifier: 0BSD
2 // SPDX-FileCopyrightText: The XZ for Java authors and contributors
3 // SPDX-FileContributor: Lasse Collin <[email protected]>
4
5 package org.tukaani.xz.common;
6
7 public final class ByteArrayView {
8 // See the version in the src9 directory.
9 public static final int ALIGN_SHORT = 0;
10 public static final int ALIGN_INT = 0;
11 public static final int ALIGN_LONG = 0;
12
13 public static short getShortBE(byte[] buf, int index) {
14 return (short)((buf[index] << 8)
15 | (buf[index + 1] & 0xFF));
16 }
17
18 public static short getShortLE(byte[] buf, int index) {
19 return (short)((buf[index] & 0xFF)
20 | (buf[index + 1] << 8));
21 }
22
23 public static int getIntBE(byte[] buf, int index) {
24 return (buf[index] << 24)
25 | ((buf[index + 1] & 0xFF) << 16)
26 | ((buf[index + 2] & 0xFF) << 8)
27 | (buf[index + 3] & 0xFF);
28 }
29
30 public static int getIntLE(byte[] buf, int index) {
31 return (buf[index] & 0xFF)
32 | ((buf[index + 1] & 0xFF) << 8)
33 | ((buf[index + 2] & 0xFF) << 16)
34 | (buf[index + 3] << 24);
35 }
36
37 public static long getLongBE(byte[] buf, int index) {
38 return ((long)buf[index] << 56)
39 | ((long)(buf[index + 1] & 0xFF) << 48)
40 | ((long)(buf[index + 2] & 0xFF) << 40)
41 | ((long)(buf[index + 3] & 0xFF) << 32)
42 | ((long)(buf[index + 4] & 0xFF) << 24)
43 | ((long)(buf[index + 5] & 0xFF) << 16)
44 | ((long)(buf[index + 6] & 0xFF) << 8)
45 | ((long)buf[index + 7] & 0xFF);
46 }
47
48 public static long getLongLE(byte[] buf, int index) {
49 return ((long)buf[index] & 0xFF)
50 | ((long)(buf[index + 1] & 0xFF) << 8)
51 | ((long)(buf[index + 2] & 0xFF) << 16)
52 | ((long)(buf[index + 3] & 0xFF) << 24)
53 | ((long)(buf[index + 4] & 0xFF) << 32)
54 | ((long)(buf[index + 5] & 0xFF) << 40)
55 | ((long)(buf[index + 6] & 0xFF) << 48)
56 | ((long)buf[index + 7] << 56);
57 }
58
59 public static void setShortBE(byte[] buf, int index, short value) {
60 buf[index] = (byte)(value >>> 8);
61 buf[index + 1] = (byte)(value);
62 }
63
64 public static void setShortLE(byte[] buf, int index, short value) {
65 buf[index] = (byte)(value);
66 buf[index + 1] = (byte)(value >>> 8);
67 }
68
69 public static void setIntBE(byte[] buf, int index, int value) {
70 buf[index] = (byte)(value >>> 24);
71 buf[index + 1] = (byte)(value >>> 16);
72 buf[index + 2] = (byte)(value >>> 8);
73 buf[index + 3] = (byte)(value);
74 }
75
76 public static void setIntLE(byte[] buf, int index, int value) {
77 buf[index] = (byte)(value);
78 buf[index + 1] = (byte)(value >>> 8);
79 buf[index + 2] = (byte)(value >>> 16);
80 buf[index + 3] = (byte)(value >>> 24);
81 }
82
83 public static void setLongBE(byte[] buf, int index, long value) {
84 buf[index] = (byte)(value >>> 56);
85 buf[index + 1] = (byte)(value >>> 48);
86 buf[index + 2] = (byte)(value >>> 40);
87 buf[index + 3] = (byte)(value >>> 32);
88 buf[index + 4] = (byte)(value >>> 24);
89 buf[index + 5] = (byte)(value >>> 16);
90 buf[index + 6] = (byte)(value >>> 8);
91 buf[index + 7] = (byte)(value);
92 }
93
94 public static void setLongLE(byte[] buf, int index, long value) {
95 buf[index] = (byte)(value);
96 buf[index + 1] = (byte)(value >>> 8);
97 buf[index + 2] = (byte)(value >>> 16);
98 buf[index + 3] = (byte)(value >>> 24);
99 buf[index + 4] = (byte)(value >>> 32);
100 buf[index + 5] = (byte)(value >>> 40);
101 buf[index + 6] = (byte)(value >>> 48);
102 buf[index + 7] = (byte)(value >>> 56);
103 }
104
105 private ByteArrayView() {}
106 }