]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db/src/org/simantics/db/service/Bytes.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.db / src / org / simantics / db / service / Bytes.java
1 package org.simantics.db.service;
2
3
4 final public class Bytes {
5
6         final public static void write(byte[] bytes, int index, byte value) {
7                 bytes[index] = value;
8         }
9
10         final public static void writeLE(byte[] bytes, int index, long value) {
11                 
12                 bytes[index++] = (byte) (value & 0xFF);
13                 bytes[index++] = (byte) ((value >>> 8) & 0xFF);
14                 bytes[index++] = (byte) ((value >>> 16) & 0xFF);
15                 bytes[index++] = (byte) ((value >>> 24) & 0xFF);
16                 bytes[index++] = (byte) ((value >>> 32) & 0xFF);
17                 bytes[index++] = (byte) ((value >>> 40) & 0xFF);
18                 bytes[index++] = (byte) ((value >>> 48) & 0xFF);
19                 bytes[index++] = (byte) ((value >>> 56) & 0xFF);
20                 
21         }
22
23         final public static void writeLE6(byte[] bytes, int index, long value) {
24                 
25                 bytes[index++] = (byte) (value & 0xFF);
26                 bytes[index++] = (byte) ((value >>> 8) & 0xFF);
27                 bytes[index++] = (byte) ((value >>> 16) & 0xFF);
28                 bytes[index++] = (byte) ((value >>> 24) & 0xFF);
29                 bytes[index++] = (byte) ((value >>> 32) & 0xFF);
30                 bytes[index++] = (byte) ((value >>> 40) & 0xFF);
31                 
32         }
33
34         final public static void writeLE7(byte[] bytes, int index, long value) {
35                 
36                 bytes[index++] = (byte) (value & 0xFF);
37                 bytes[index++] = (byte) ((value >>> 8) & 0xFF);
38                 bytes[index++] = (byte) ((value >>> 16) & 0xFF);
39                 bytes[index++] = (byte) ((value >>> 24) & 0xFF);
40                 bytes[index++] = (byte) ((value >>> 32) & 0xFF);
41                 bytes[index++] = (byte) ((value >>> 40) & 0xFF);
42                 bytes[index++] = (byte) ((value >>> 48) & 0xFF);
43                 
44         }
45         
46         final public static void writeLE8(byte[] bytes, int index, long value) {
47                 
48                 bytes[index++] = (byte) (value & 0xFF);
49                 bytes[index++] = (byte) ((value >>> 8) & 0xFF);
50                 bytes[index++] = (byte) ((value >>> 16) & 0xFF);
51                 bytes[index++] = (byte) ((value >>> 24) & 0xFF);
52                 bytes[index++] = (byte) ((value >>> 32) & 0xFF);
53                 bytes[index++] = (byte) ((value >>> 40) & 0xFF);
54                 bytes[index++] = (byte) ((value >>> 48) & 0xFF);
55                 bytes[index++] = (byte) ((value >>> 56) & 0xFF);
56                 
57         }
58
59         final public static void writeLE(byte[] bytes, int index, int value) {
60                 
61                 bytes[index++] = (byte) (value & 0xFF);
62                 bytes[index++] = (byte) ((value >>> 8) & 0xFF);
63                 bytes[index++] = (byte) ((value >>> 16) & 0xFF);
64                 bytes[index++] = (byte) ((value >>> 24) & 0xFF);
65                 
66         }
67
68         final public static void writeLE(byte[] bytes, int index, short value) {
69                 
70                 bytes[index++] = (byte) (value & 0xFF);
71                 bytes[index++] = (byte) ((value >>> 8) & 0xFF);
72                 
73         }
74         
75         final public static byte read(byte[] bytes, int byteIndex) {
76                 return bytes[byteIndex++];
77         }
78
79         final public static int readLE2(byte[] bytes, int byteIndex) {
80                 int result = (int) 
81                         (((int)(bytes[byteIndex++] & 0xff)) | 
82                         (((int)(bytes[byteIndex++] & 0xff))<<8)); 
83                 return result;
84         }
85
86         final public static int readLE4(byte[] bytes, int byteIndex) {
87                 int result = (int) 
88                         (((int)(bytes[byteIndex++] & 0xff)) | 
89                         (((int)(bytes[byteIndex++] & 0xff))<<8) | 
90                         (((int)(bytes[byteIndex++] & 0xff))<<16) | 
91                         (((int)(bytes[byteIndex++] & 0xff))<<24)); 
92                 return result;
93         }
94         
95         final public static long readLE7(byte[] bytes, int byteIndex) {
96                 long result = (long) 
97                         (((long)(bytes[byteIndex++] & 0xff)) | 
98                         (((long)(bytes[byteIndex++] & 0xff))<<8) | 
99                         (((long)(bytes[byteIndex++] & 0xff))<<16) | 
100                         (((long)(bytes[byteIndex++] & 0xff))<<24) | 
101                         (((long)(bytes[byteIndex++] & 0xff))<<32) | 
102                         (((long)(bytes[byteIndex++] & 0xff))<<40) | 
103                         (((long)(bytes[byteIndex++] & 0xff))<<48));
104                 return result;
105         }
106
107         final public static long readLE8(byte[] bytes, int byteIndex) {
108                 long result = (long) 
109                         (((long)(bytes[byteIndex++] & 0xff)) | 
110                         (((long)(bytes[byteIndex++] & 0xff))<<8) | 
111                         (((long)(bytes[byteIndex++] & 0xff))<<16) | 
112                         (((long)(bytes[byteIndex++] & 0xff))<<24) | 
113                         (((long)(bytes[byteIndex++] & 0xff))<<32) | 
114                         (((long)(bytes[byteIndex++] & 0xff))<<40) | 
115                         (((long)(bytes[byteIndex++] & 0xff))<<48) | 
116                         (((long)(bytes[byteIndex++] & 0xff))<<56));
117                 return result;
118         }
119                 
120 }