1
1
/*
2
- * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
3
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2
+ * Adapted from: http://github.com/baomidou/dynamic-datasource/blob/bae2677b83abad549e3ddf41b286749515360e7b/dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/tx/LocalTxUtil.java
4
3
*
5
- * This code is free software; you can redistribute it and/or modify it
6
- * under the terms of the GNU General Public License version 2 only, as
7
- * published by the Free Software Foundation. Oracle designates this
8
- * particular file as subject to the "Classpath" exception as provided
9
- * by Oracle in the LICENSE file that accompanied this code.
4
+ * Copyright © 2018 organization baomidou
10
5
*
11
- * This code is distributed in the hope that it will be useful, but WITHOUT
12
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
- * version 2 for more details (a copy is included in the LICENSE file that
15
- * accompanied this code).
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
16
9
*
17
- * You should have received a copy of the GNU General Public License version
18
- * 2 along with this work; if not, write to the Free Software Foundation,
19
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
10
+ * http://www.apache.org/licenses/LICENSE-2.0
20
11
*
21
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
- * or visit www.oracle.com if you need additional information or have any
23
- * questions.
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
24
17
*/
25
18
26
19
package io .sentry .util ;
@@ -35,36 +28,41 @@ public final class UUIDGenerator {
35
28
36
29
@ SuppressWarnings ("NarrowingCompoundAssignment" )
37
30
public static long randomHalfLengthUUID () {
38
- Random random = SentryRandom .current ();
31
+ Random ng = SentryRandom .current ();
39
32
byte [] randomBytes = new byte [8 ];
40
- random .nextBytes (randomBytes );
41
- randomBytes [6 ] &= 0x0f ; /* clear version */
42
- randomBytes [6 ] |= 0x40 ; /* set to version 4 */
43
-
33
+ ng .nextBytes (randomBytes );
34
+ // clear version
35
+ randomBytes [6 ] &= 0x0f ;
36
+ // set to version 4
37
+ randomBytes [6 ] |= 0x40 ;
44
38
long msb = 0 ;
45
-
46
- for ( int i = 0 ; i < 8 ; i ++) msb = (msb << 8 ) | (randomBytes [i ] & 0xff );
47
-
39
+ for ( int i = 0 ; i < 8 ; i ++) {
40
+ msb = (msb << 8 ) | (randomBytes [i ] & 0xff );
41
+ }
48
42
return msb ;
49
43
}
50
44
51
45
@ SuppressWarnings ("NarrowingCompoundAssignment" )
52
46
public static UUID randomUUID () {
53
- Random random = SentryRandom .current ();
47
+ Random ng = SentryRandom .current ();
54
48
byte [] randomBytes = new byte [16 ];
55
- random .nextBytes (randomBytes );
56
- randomBytes [6 ] &= 0x0f ; /* clear version */
57
- randomBytes [6 ] |= 0x40 ; /* set to version 4 */
58
- randomBytes [8 ] &= 0x3f ; /* clear variant */
59
- randomBytes [8 ] |= (byte ) 0x80 ; /* set to IETF variant */
60
-
49
+ ng .nextBytes (randomBytes );
50
+ // clear version
51
+ randomBytes [6 ] &= 0x0f ;
52
+ // set to version 4
53
+ randomBytes [6 ] |= 0x40 ;
54
+ // clear variant
55
+ randomBytes [8 ] &= 0x3f ;
56
+ // set to IETF variant
57
+ randomBytes [8 ] |= 0x80 ;
61
58
long msb = 0 ;
62
59
long lsb = 0 ;
63
-
64
- for (int i = 0 ; i < 8 ; i ++) msb = (msb << 8 ) | (randomBytes [i ] & 0xff );
65
-
66
- for (int i = 8 ; i < 16 ; i ++) lsb = (lsb << 8 ) | (randomBytes [i ] & 0xff );
67
-
60
+ for (int i = 0 ; i < 8 ; i ++) {
61
+ msb = (msb << 8 ) | (randomBytes [i ] & 0xff );
62
+ }
63
+ for (int i = 8 ; i < 16 ; i ++) {
64
+ lsb = (lsb << 8 ) | (randomBytes [i ] & 0xff );
65
+ }
68
66
return new UUID (msb , lsb );
69
67
}
70
68
}
0 commit comments