G-Earth 1.5.4 beta 22 - Initial release
Komplettes G-Earth Paket inkl. JRE, Extensions und Tools. Extensions: - G-BuildTools, G-Click Ultimate, G-Loader, G-Manipulate - G-Presets, G-Translator, G-Trigger, G-itemViewer - Market Utils, Packet Info Explorer, Plants - RandomRoomVisitor, RoomLogger, Sanbovir Photo Inspector - SpyFriends, WallAligner, XabboScripter, xabbo
This commit is contained in:
commit
368b92d87a
1
Cache/SULEK_API-FLASH-WIN63-202603091410-618570407
Normal file
1
Cache/SULEK_API-FLASH-WIN63-202603091410-618570407
Normal file
File diff suppressed because one or more lines are too long
1
Cache/cache.json
Normal file
1
Cache/cache.json
Normal file
@ -0,0 +1 @@
|
||||
{"notepad_text":"","last_client_mode":"FLASH","always_admin":false,"use_gpython":false,"language":"GERMAN","itemSource":"ONLY_INVENTORY","theme":"G-Earth Dark","develop_mode":false,"last_connection_settings":{"auto_detect":true,"port":30000,"host":"game-br.habbo.com"}}
|
||||
1
Extensions/G-BuildTools_2.0.1/command.txt
Normal file
1
Extensions/G-BuildTools_2.0.1/command.txt
Normal file
@ -0,0 +1 @@
|
||||
["java","-jar","GBuildTools.jar","-c","{cookie}","-p","{port}","-f","{filename}"]
|
||||
BIN
Extensions/G-BuildTools_2.0.1/extension/GBuildTools.jar
Normal file
BIN
Extensions/G-BuildTools_2.0.1/extension/GBuildTools.jar
Normal file
Binary file not shown.
1
Extensions/G-Click Ultimate_0.1.2/command.txt
Normal file
1
Extensions/G-Click Ultimate_0.1.2/command.txt
Normal file
@ -0,0 +1 @@
|
||||
["java","-jar","gclickultimate.jar","-c","{cookie}","-p","{port}","-f","{filename}"]
|
||||
BIN
Extensions/G-Click Ultimate_0.1.2/extension/gclickultimate.jar
Normal file
BIN
Extensions/G-Click Ultimate_0.1.2/extension/gclickultimate.jar
Normal file
Binary file not shown.
1
Extensions/G-Manipulate_0.2.1/command.txt
Normal file
1
Extensions/G-Manipulate_0.2.1/command.txt
Normal file
@ -0,0 +1 @@
|
||||
["java","-jar","gmanipulate.jar","-c","{cookie}","-p","{port}","-f","{filename}"]
|
||||
BIN
Extensions/G-Manipulate_0.2.1/extension/gmanipulate.jar
Normal file
BIN
Extensions/G-Manipulate_0.2.1/extension/gmanipulate.jar
Normal file
Binary file not shown.
@ -0,0 +1 @@
|
||||
["java","-jar","GPresets.jar","-c","{cookie}","-p","{port}","-f","{filename}"]
|
||||
@ -0,0 +1 @@
|
||||
{"noExportWired":true,"allowIncompleteBuilds":true,"language":"GERMAN","itemSource":"PREFER_BC"}
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,428 @@
|
||||
{
|
||||
"wired": {
|
||||
"effects": [
|
||||
{
|
||||
"wiredId": 4,
|
||||
"delay": 0,
|
||||
"options": [],
|
||||
"config": "",
|
||||
"items": [1],
|
||||
"stuff": 0
|
||||
},
|
||||
{
|
||||
"wiredId": 6,
|
||||
"delay": 0,
|
||||
"options": [
|
||||
1,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"config": "",
|
||||
"items": [14],
|
||||
"stuff": 0
|
||||
},
|
||||
{
|
||||
"wiredId": 7,
|
||||
"delay": 0,
|
||||
"options": [
|
||||
0,
|
||||
0,
|
||||
1
|
||||
],
|
||||
"config": "",
|
||||
"items": [1],
|
||||
"stuff": 0
|
||||
},
|
||||
{
|
||||
"wiredId": 13,
|
||||
"delay": 0,
|
||||
"options": [],
|
||||
"config": "",
|
||||
"items": [14],
|
||||
"stuff": 0
|
||||
},
|
||||
{
|
||||
"wiredId": 15,
|
||||
"delay": 0,
|
||||
"options": [],
|
||||
"config": "",
|
||||
"items": [10],
|
||||
"stuff": 0
|
||||
},
|
||||
{
|
||||
"wiredId": 16,
|
||||
"delay": 0,
|
||||
"options": [
|
||||
1,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"config": "",
|
||||
"items": [14],
|
||||
"stuff": 0
|
||||
},
|
||||
{
|
||||
"wiredId": 17,
|
||||
"delay": 0,
|
||||
"options": [
|
||||
0,
|
||||
0,
|
||||
1
|
||||
],
|
||||
"config": "",
|
||||
"items": [1],
|
||||
"stuff": 0
|
||||
}
|
||||
],
|
||||
"conditions": [
|
||||
{
|
||||
"wiredId": 2,
|
||||
"options": [
|
||||
1,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"config": "",
|
||||
"items": [14],
|
||||
"stuff": 0
|
||||
},
|
||||
{
|
||||
"wiredId": 3,
|
||||
"options": [
|
||||
0,
|
||||
0,
|
||||
1
|
||||
],
|
||||
"config": "",
|
||||
"items": [1],
|
||||
"stuff": 0
|
||||
},
|
||||
{
|
||||
"wiredId": 9,
|
||||
"options": [
|
||||
1,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"config": "",
|
||||
"items": [14],
|
||||
"stuff": 0
|
||||
},
|
||||
{
|
||||
"wiredId": 11,
|
||||
"options": [
|
||||
0,
|
||||
0,
|
||||
1
|
||||
],
|
||||
"config": "",
|
||||
"items": [1],
|
||||
"stuff": 0
|
||||
},
|
||||
{
|
||||
"wiredId": 18,
|
||||
"options": [],
|
||||
"config": "",
|
||||
"items": [1],
|
||||
"stuff": 0
|
||||
}
|
||||
],
|
||||
"triggers": [
|
||||
{
|
||||
"wiredId": 5,
|
||||
"options": [1],
|
||||
"config": "",
|
||||
"items": [],
|
||||
"stuff": 0
|
||||
},
|
||||
{
|
||||
"wiredId": 8,
|
||||
"options": [1],
|
||||
"config": "",
|
||||
"items": [],
|
||||
"stuff": 0
|
||||
},
|
||||
{
|
||||
"wiredId": 12,
|
||||
"options": [2],
|
||||
"config": "",
|
||||
"items": [],
|
||||
"stuff": 0
|
||||
},
|
||||
{
|
||||
"wiredId": 19,
|
||||
"options": [],
|
||||
"config": "",
|
||||
"items": [],
|
||||
"stuff": 0
|
||||
}
|
||||
]
|
||||
},
|
||||
"bindings": [
|
||||
{
|
||||
"wiredId": 2,
|
||||
"furniId": 14,
|
||||
"state": "2"
|
||||
},
|
||||
{
|
||||
"wiredId": 3,
|
||||
"furniId": 1,
|
||||
"location": {
|
||||
"x": 0,
|
||||
"y": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"wiredId": 6,
|
||||
"furniId": 14,
|
||||
"state": "0"
|
||||
},
|
||||
{
|
||||
"wiredId": 7,
|
||||
"furniId": 1,
|
||||
"location": {
|
||||
"x": 0,
|
||||
"y": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"wiredId": 9,
|
||||
"furniId": 14,
|
||||
"state": "2"
|
||||
},
|
||||
{
|
||||
"wiredId": 11,
|
||||
"furniId": 1,
|
||||
"location": {
|
||||
"x": 0,
|
||||
"y": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"wiredId": 16,
|
||||
"furniId": 14,
|
||||
"state": "0"
|
||||
},
|
||||
{
|
||||
"wiredId": 17,
|
||||
"furniId": 1,
|
||||
"location": {
|
||||
"x": 0,
|
||||
"y": 0
|
||||
}
|
||||
}
|
||||
],
|
||||
"furni": [
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_glowball[0]",
|
||||
"className": "wf_glowball",
|
||||
"location": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"id": 1,
|
||||
"state": "1"
|
||||
},
|
||||
{
|
||||
"rotation": 2,
|
||||
"name": "wf_cnd_not_match_snap[0]",
|
||||
"className": "wf_cnd_not_match_snap",
|
||||
"location": {
|
||||
"x": 2,
|
||||
"y": 0,
|
||||
"z": 1.3
|
||||
},
|
||||
"id": 2
|
||||
},
|
||||
{
|
||||
"rotation": 2,
|
||||
"name": "wf_cnd_not_match_snap[1]",
|
||||
"className": "wf_cnd_not_match_snap",
|
||||
"location": {
|
||||
"x": 2,
|
||||
"y": 0,
|
||||
"z": 0.65
|
||||
},
|
||||
"id": 3
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_act_chase[0]",
|
||||
"className": "wf_act_chase",
|
||||
"location": {
|
||||
"x": 2,
|
||||
"y": 0,
|
||||
"z": 1.95
|
||||
},
|
||||
"id": 4
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_trg_periodically[0]",
|
||||
"className": "wf_trg_periodically",
|
||||
"location": {
|
||||
"x": 2,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"id": 5
|
||||
},
|
||||
{
|
||||
"rotation": 2,
|
||||
"name": "wf_act_match_to_sshot[0]",
|
||||
"className": "wf_act_match_to_sshot",
|
||||
"location": {
|
||||
"x": 3,
|
||||
"y": 0,
|
||||
"z": 1.95
|
||||
},
|
||||
"id": 6
|
||||
},
|
||||
{
|
||||
"rotation": 2,
|
||||
"name": "wf_act_match_to_sshot[1]",
|
||||
"className": "wf_act_match_to_sshot",
|
||||
"location": {
|
||||
"x": 3,
|
||||
"y": 0,
|
||||
"z": 1.3
|
||||
},
|
||||
"id": 7
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_trg_periodically[1]",
|
||||
"className": "wf_trg_periodically",
|
||||
"location": {
|
||||
"x": 3,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"id": 8
|
||||
},
|
||||
{
|
||||
"rotation": 2,
|
||||
"name": "wf_cnd_match_snapshot[0]",
|
||||
"className": "wf_cnd_match_snapshot",
|
||||
"location": {
|
||||
"x": 3,
|
||||
"y": 0,
|
||||
"z": 0.65
|
||||
},
|
||||
"id": 9
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_ringplate[0]",
|
||||
"className": "wf_ringplate",
|
||||
"location": {
|
||||
"x": 3,
|
||||
"y": 3,
|
||||
"z": 0
|
||||
},
|
||||
"id": 10
|
||||
},
|
||||
{
|
||||
"rotation": 2,
|
||||
"name": "wf_cnd_not_match_snap[2]",
|
||||
"className": "wf_cnd_not_match_snap",
|
||||
"location": {
|
||||
"x": 4,
|
||||
"y": 0,
|
||||
"z": 0.65
|
||||
},
|
||||
"id": 11
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_trg_periodically[2]",
|
||||
"className": "wf_trg_periodically",
|
||||
"location": {
|
||||
"x": 4,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"id": 12
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_act_toggle_state[0]",
|
||||
"className": "wf_act_toggle_state",
|
||||
"location": {
|
||||
"x": 4,
|
||||
"y": 0,
|
||||
"z": 1.3
|
||||
},
|
||||
"id": 13
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_colortile[0]",
|
||||
"className": "wf_colortile",
|
||||
"location": {
|
||||
"x": 4,
|
||||
"y": 0,
|
||||
"z": 1.95
|
||||
},
|
||||
"id": 14,
|
||||
"state": "0"
|
||||
},
|
||||
{
|
||||
"rotation": 2,
|
||||
"name": "wf_act_teleport_to[0]",
|
||||
"className": "wf_act_teleport_to",
|
||||
"location": {
|
||||
"x": 5,
|
||||
"y": 0,
|
||||
"z": 2.6
|
||||
},
|
||||
"id": 15
|
||||
},
|
||||
{
|
||||
"rotation": 2,
|
||||
"name": "wf_act_match_to_sshot[2]",
|
||||
"className": "wf_act_match_to_sshot",
|
||||
"location": {
|
||||
"x": 5,
|
||||
"y": 0,
|
||||
"z": 1.95
|
||||
},
|
||||
"id": 16
|
||||
},
|
||||
{
|
||||
"rotation": 2,
|
||||
"name": "wf_act_match_to_sshot[3]",
|
||||
"className": "wf_act_match_to_sshot",
|
||||
"location": {
|
||||
"x": 5,
|
||||
"y": 0,
|
||||
"z": 1.3
|
||||
},
|
||||
"id": 17
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_cnd_stuff_is[0]",
|
||||
"className": "wf_cnd_stuff_is",
|
||||
"location": {
|
||||
"x": 5,
|
||||
"y": 0,
|
||||
"z": 0.65
|
||||
},
|
||||
"id": 18
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_trg_collision[0]",
|
||||
"className": "wf_trg_collision",
|
||||
"location": {
|
||||
"x": 5,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"id": 19
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,190 @@
|
||||
{
|
||||
"wired": {
|
||||
"effects": [
|
||||
{
|
||||
"wiredId": 4,
|
||||
"delay": 0,
|
||||
"options": [],
|
||||
"config": "",
|
||||
"items": [1],
|
||||
"stuff": 0
|
||||
},
|
||||
{
|
||||
"wiredId": 6,
|
||||
"delay": 0,
|
||||
"options": [],
|
||||
"config": "",
|
||||
"items": [5],
|
||||
"stuff": 0
|
||||
},
|
||||
{
|
||||
"wiredId": 9,
|
||||
"delay": 0,
|
||||
"options": [
|
||||
0,
|
||||
0,
|
||||
1
|
||||
],
|
||||
"config": "",
|
||||
"items": [1],
|
||||
"stuff": 0
|
||||
}
|
||||
],
|
||||
"conditions": [
|
||||
{
|
||||
"wiredId": 2,
|
||||
"options": [
|
||||
0,
|
||||
0,
|
||||
1
|
||||
],
|
||||
"config": "",
|
||||
"items": [1],
|
||||
"stuff": 0
|
||||
},
|
||||
{
|
||||
"wiredId": 8,
|
||||
"options": [],
|
||||
"config": "",
|
||||
"items": [1],
|
||||
"stuff": 0
|
||||
}
|
||||
],
|
||||
"triggers": [
|
||||
{
|
||||
"wiredId": 3,
|
||||
"options": [1],
|
||||
"config": "",
|
||||
"items": [],
|
||||
"stuff": 0
|
||||
},
|
||||
{
|
||||
"wiredId": 7,
|
||||
"options": [],
|
||||
"config": "",
|
||||
"items": [],
|
||||
"stuff": 0
|
||||
}
|
||||
]
|
||||
},
|
||||
"bindings": [
|
||||
{
|
||||
"wiredId": 2,
|
||||
"furniId": 1,
|
||||
"location": {
|
||||
"x": 0,
|
||||
"y": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"wiredId": 9,
|
||||
"furniId": 1,
|
||||
"location": {
|
||||
"x": 0,
|
||||
"y": 0
|
||||
}
|
||||
}
|
||||
],
|
||||
"furni": [
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_glowball[0]",
|
||||
"className": "wf_glowball",
|
||||
"location": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"id": 1,
|
||||
"state": "1"
|
||||
},
|
||||
{
|
||||
"rotation": 2,
|
||||
"name": "wf_cnd_not_match_snap[0]",
|
||||
"className": "wf_cnd_not_match_snap",
|
||||
"location": {
|
||||
"x": 2,
|
||||
"y": 0,
|
||||
"z": 0.65
|
||||
},
|
||||
"id": 2
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_trg_periodically[0]",
|
||||
"className": "wf_trg_periodically",
|
||||
"location": {
|
||||
"x": 2,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"id": 3
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_act_chase[0]",
|
||||
"className": "wf_act_chase",
|
||||
"location": {
|
||||
"x": 2,
|
||||
"y": 0,
|
||||
"z": 1.3
|
||||
},
|
||||
"id": 4
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_ringplate[0]",
|
||||
"className": "wf_ringplate",
|
||||
"location": {
|
||||
"x": 2,
|
||||
"y": 3,
|
||||
"z": 0
|
||||
},
|
||||
"id": 5
|
||||
},
|
||||
{
|
||||
"rotation": 2,
|
||||
"name": "wf_act_teleport_to[0]",
|
||||
"className": "wf_act_teleport_to",
|
||||
"location": {
|
||||
"x": 3,
|
||||
"y": 0,
|
||||
"z": 1.95
|
||||
},
|
||||
"id": 6
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_trg_collision[0]",
|
||||
"className": "wf_trg_collision",
|
||||
"location": {
|
||||
"x": 3,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"id": 7
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_cnd_stuff_is[0]",
|
||||
"className": "wf_cnd_stuff_is",
|
||||
"location": {
|
||||
"x": 3,
|
||||
"y": 0,
|
||||
"z": 0.65
|
||||
},
|
||||
"id": 8
|
||||
},
|
||||
{
|
||||
"rotation": 2,
|
||||
"name": "wf_act_match_to_sshot[0]",
|
||||
"className": "wf_act_match_to_sshot",
|
||||
"location": {
|
||||
"x": 3,
|
||||
"y": 0,
|
||||
"z": 1.3
|
||||
},
|
||||
"id": 9
|
||||
}
|
||||
]
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,302 @@
|
||||
{
|
||||
"wired": {
|
||||
"effects": [
|
||||
{
|
||||
"wiredId": 1,
|
||||
"delay": 0,
|
||||
"options": [],
|
||||
"config": "",
|
||||
"items": [4]
|
||||
},
|
||||
{
|
||||
"wiredId": 5,
|
||||
"delay": 0,
|
||||
"options": [],
|
||||
"config": "",
|
||||
"items": [8]
|
||||
},
|
||||
{
|
||||
"wiredId": 9,
|
||||
"delay": 0,
|
||||
"options": [
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"config": "",
|
||||
"items": [14]
|
||||
},
|
||||
{
|
||||
"wiredId": 11,
|
||||
"delay": 0,
|
||||
"options": [],
|
||||
"config": "",
|
||||
"items": [13]
|
||||
}
|
||||
],
|
||||
"addons": [],
|
||||
"conditions": [
|
||||
{
|
||||
"wiredId": 2,
|
||||
"options": [
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"config": "",
|
||||
"items": [
|
||||
8,
|
||||
13,
|
||||
14
|
||||
]
|
||||
},
|
||||
{
|
||||
"wiredId": 7,
|
||||
"options": [
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"config": "",
|
||||
"items": [
|
||||
13,
|
||||
14
|
||||
]
|
||||
},
|
||||
{
|
||||
"wiredId": 10,
|
||||
"options": [
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"config": "",
|
||||
"items": [14]
|
||||
}
|
||||
],
|
||||
"triggers": [
|
||||
{
|
||||
"wiredId": 3,
|
||||
"options": [1],
|
||||
"config": "",
|
||||
"items": [],
|
||||
"stuff": 0
|
||||
},
|
||||
{
|
||||
"wiredId": 6,
|
||||
"options": [1],
|
||||
"config": "",
|
||||
"items": [],
|
||||
"stuff": 0
|
||||
},
|
||||
{
|
||||
"wiredId": 12,
|
||||
"options": [1],
|
||||
"config": "",
|
||||
"items": [],
|
||||
"stuff": 0
|
||||
}
|
||||
]
|
||||
},
|
||||
"bindings": [
|
||||
{
|
||||
"wiredId": 2,
|
||||
"furniId": 13,
|
||||
"state": "9"
|
||||
},
|
||||
{
|
||||
"wiredId": 2,
|
||||
"furniId": 8,
|
||||
"state": "9"
|
||||
},
|
||||
{
|
||||
"wiredId": 2,
|
||||
"furniId": 14,
|
||||
"state": "1"
|
||||
},
|
||||
{
|
||||
"wiredId": 7,
|
||||
"furniId": 13,
|
||||
"state": "9"
|
||||
},
|
||||
{
|
||||
"wiredId": 7,
|
||||
"furniId": 14,
|
||||
"state": "1"
|
||||
},
|
||||
{
|
||||
"wiredId": 9,
|
||||
"furniId": 14,
|
||||
"state": "0"
|
||||
},
|
||||
{
|
||||
"wiredId": 10,
|
||||
"furniId": 14,
|
||||
"state": "1"
|
||||
}
|
||||
],
|
||||
"furni": [
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_act_toggle_state[0]",
|
||||
"className": "wf_act_toggle_state",
|
||||
"location": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 1.3
|
||||
},
|
||||
"id": 1
|
||||
},
|
||||
{
|
||||
"rotation": 2,
|
||||
"name": "wf_cnd_match_snapshot[0]",
|
||||
"className": "wf_cnd_match_snapshot",
|
||||
"location": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0.65
|
||||
},
|
||||
"id": 2
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_trg_periodically[0]",
|
||||
"className": "wf_trg_periodically",
|
||||
"location": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"id": 3
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "bc_alpha1_num*8[0]",
|
||||
"className": "bc_alpha1_num*8",
|
||||
"location": {
|
||||
"x": 0,
|
||||
"y": 3,
|
||||
"z": 0
|
||||
},
|
||||
"id": 4,
|
||||
"state": "0"
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_act_toggle_state[1]",
|
||||
"className": "wf_act_toggle_state",
|
||||
"location": {
|
||||
"x": 1,
|
||||
"y": 0,
|
||||
"z": 1.3
|
||||
},
|
||||
"id": 5
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_trg_periodically[1]",
|
||||
"className": "wf_trg_periodically",
|
||||
"location": {
|
||||
"x": 1,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"id": 6
|
||||
},
|
||||
{
|
||||
"rotation": 2,
|
||||
"name": "wf_cnd_match_snapshot[1]",
|
||||
"className": "wf_cnd_match_snapshot",
|
||||
"location": {
|
||||
"x": 1,
|
||||
"y": 0,
|
||||
"z": 0.65
|
||||
},
|
||||
"id": 7
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "bc_alpha1_num*8[1]",
|
||||
"className": "bc_alpha1_num*8",
|
||||
"location": {
|
||||
"x": 1,
|
||||
"y": 3,
|
||||
"z": 0
|
||||
},
|
||||
"id": 8,
|
||||
"state": "0"
|
||||
},
|
||||
{
|
||||
"rotation": 2,
|
||||
"name": "wf_act_match_to_sshot[0]",
|
||||
"className": "wf_act_match_to_sshot",
|
||||
"location": {
|
||||
"x": 2,
|
||||
"y": 0,
|
||||
"z": 1.9499999
|
||||
},
|
||||
"id": 9
|
||||
},
|
||||
{
|
||||
"rotation": 2,
|
||||
"name": "wf_cnd_match_snapshot[2]",
|
||||
"className": "wf_cnd_match_snapshot",
|
||||
"location": {
|
||||
"x": 2,
|
||||
"y": 0,
|
||||
"z": 0.65
|
||||
},
|
||||
"id": 10
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_act_toggle_state[2]",
|
||||
"className": "wf_act_toggle_state",
|
||||
"location": {
|
||||
"x": 2,
|
||||
"y": 0,
|
||||
"z": 1.3
|
||||
},
|
||||
"id": 11
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_trg_periodically[2]",
|
||||
"className": "wf_trg_periodically",
|
||||
"location": {
|
||||
"x": 2,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"id": 12
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "bc_alpha1_num*8[2]",
|
||||
"className": "bc_alpha1_num*8",
|
||||
"location": {
|
||||
"x": 2,
|
||||
"y": 3,
|
||||
"z": 0
|
||||
},
|
||||
"id": 13,
|
||||
"state": "0"
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wcandle[0]",
|
||||
"className": "wcandle",
|
||||
"location": {
|
||||
"x": 3,
|
||||
"y": 3,
|
||||
"z": 0
|
||||
},
|
||||
"id": 14,
|
||||
"state": "0"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,485 @@
|
||||
{
|
||||
"wired": {
|
||||
"effects": [
|
||||
{
|
||||
"wiredId": 2,
|
||||
"delay": 1,
|
||||
"options": [],
|
||||
"config": "",
|
||||
"items": [4]
|
||||
},
|
||||
{
|
||||
"wiredId": 7,
|
||||
"delay": 1,
|
||||
"options": [],
|
||||
"config": "",
|
||||
"items": [9]
|
||||
},
|
||||
{
|
||||
"wiredId": 8,
|
||||
"delay": 1,
|
||||
"options": [
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"config": "",
|
||||
"items": [16]
|
||||
},
|
||||
{
|
||||
"wiredId": 10,
|
||||
"delay": 1,
|
||||
"options": [],
|
||||
"config": "",
|
||||
"items": [16]
|
||||
},
|
||||
{
|
||||
"wiredId": 14,
|
||||
"delay": 1,
|
||||
"options": [],
|
||||
"config": "",
|
||||
"items": [21]
|
||||
},
|
||||
{
|
||||
"wiredId": 17,
|
||||
"delay": 0,
|
||||
"options": [
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"config": "",
|
||||
"items": [
|
||||
4,
|
||||
16,
|
||||
9,
|
||||
21
|
||||
]
|
||||
}
|
||||
],
|
||||
"addons": [],
|
||||
"conditions": [
|
||||
{
|
||||
"wiredId": 1,
|
||||
"options": [
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"config": "",
|
||||
"items": [
|
||||
16,
|
||||
9,
|
||||
21,
|
||||
18
|
||||
]
|
||||
},
|
||||
{
|
||||
"wiredId": 5,
|
||||
"options": [
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"config": "",
|
||||
"items": [
|
||||
16,
|
||||
21,
|
||||
18
|
||||
]
|
||||
},
|
||||
{
|
||||
"wiredId": 12,
|
||||
"options": [
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"config": "",
|
||||
"items": [
|
||||
21,
|
||||
18
|
||||
]
|
||||
},
|
||||
{
|
||||
"wiredId": 13,
|
||||
"options": [
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"config": "",
|
||||
"items": [18]
|
||||
},
|
||||
{
|
||||
"wiredId": 19,
|
||||
"options": [
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"config": "",
|
||||
"items": [18]
|
||||
}
|
||||
],
|
||||
"triggers": [
|
||||
{
|
||||
"wiredId": 3,
|
||||
"options": [2],
|
||||
"config": "",
|
||||
"items": [],
|
||||
"stuff": 0
|
||||
},
|
||||
{
|
||||
"wiredId": 6,
|
||||
"options": [2],
|
||||
"config": "",
|
||||
"items": [],
|
||||
"stuff": 0
|
||||
},
|
||||
{
|
||||
"wiredId": 11,
|
||||
"options": [2],
|
||||
"config": "",
|
||||
"items": [],
|
||||
"stuff": 0
|
||||
},
|
||||
{
|
||||
"wiredId": 15,
|
||||
"options": [2],
|
||||
"config": "",
|
||||
"items": [],
|
||||
"stuff": 0
|
||||
},
|
||||
{
|
||||
"wiredId": 20,
|
||||
"options": [1],
|
||||
"config": "",
|
||||
"items": [],
|
||||
"stuff": 0
|
||||
}
|
||||
]
|
||||
},
|
||||
"bindings": [
|
||||
{
|
||||
"wiredId": 1,
|
||||
"furniId": 9,
|
||||
"state": "9"
|
||||
},
|
||||
{
|
||||
"wiredId": 1,
|
||||
"furniId": 16,
|
||||
"state": "5"
|
||||
},
|
||||
{
|
||||
"wiredId": 1,
|
||||
"furniId": 21,
|
||||
"state": "9"
|
||||
},
|
||||
{
|
||||
"wiredId": 1,
|
||||
"furniId": 18,
|
||||
"state": "1"
|
||||
},
|
||||
{
|
||||
"wiredId": 5,
|
||||
"furniId": 16,
|
||||
"state": "5"
|
||||
},
|
||||
{
|
||||
"wiredId": 5,
|
||||
"furniId": 21,
|
||||
"state": "9"
|
||||
},
|
||||
{
|
||||
"wiredId": 5,
|
||||
"furniId": 18,
|
||||
"state": "1"
|
||||
},
|
||||
{
|
||||
"wiredId": 12,
|
||||
"furniId": 21,
|
||||
"state": "9"
|
||||
},
|
||||
{
|
||||
"wiredId": 12,
|
||||
"furniId": 18,
|
||||
"state": "1"
|
||||
},
|
||||
{
|
||||
"wiredId": 13,
|
||||
"furniId": 18,
|
||||
"state": "1"
|
||||
},
|
||||
{
|
||||
"wiredId": 17,
|
||||
"furniId": 4,
|
||||
"state": "0"
|
||||
},
|
||||
{
|
||||
"wiredId": 17,
|
||||
"furniId": 9,
|
||||
"state": "0"
|
||||
},
|
||||
{
|
||||
"wiredId": 17,
|
||||
"furniId": 16,
|
||||
"state": "0"
|
||||
},
|
||||
{
|
||||
"wiredId": 17,
|
||||
"furniId": 21,
|
||||
"state": "0"
|
||||
},
|
||||
{
|
||||
"wiredId": 19,
|
||||
"furniId": 18,
|
||||
"state": "0"
|
||||
}
|
||||
],
|
||||
"furni": [
|
||||
{
|
||||
"rotation": 2,
|
||||
"name": "wf_cnd_match_snapshot[0]",
|
||||
"className": "wf_cnd_match_snapshot",
|
||||
"location": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0.65
|
||||
},
|
||||
"id": 1
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_act_toggle_state[0]",
|
||||
"className": "wf_act_toggle_state",
|
||||
"location": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 1.3
|
||||
},
|
||||
"id": 2
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_trg_periodically[0]",
|
||||
"className": "wf_trg_periodically",
|
||||
"location": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"id": 3
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "bc_alpha1_num*11[0]",
|
||||
"className": "bc_alpha1_num*11",
|
||||
"location": {
|
||||
"x": 0,
|
||||
"y": 3,
|
||||
"z": 0
|
||||
},
|
||||
"id": 4,
|
||||
"state": "0"
|
||||
},
|
||||
{
|
||||
"rotation": 2,
|
||||
"name": "wf_cnd_match_snapshot[1]",
|
||||
"className": "wf_cnd_match_snapshot",
|
||||
"location": {
|
||||
"x": 1,
|
||||
"y": 0,
|
||||
"z": 0.65
|
||||
},
|
||||
"id": 5
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_trg_periodically[1]",
|
||||
"className": "wf_trg_periodically",
|
||||
"location": {
|
||||
"x": 1,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"id": 6
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_act_toggle_state[1]",
|
||||
"className": "wf_act_toggle_state",
|
||||
"location": {
|
||||
"x": 1,
|
||||
"y": 0,
|
||||
"z": 1.3
|
||||
},
|
||||
"id": 7
|
||||
},
|
||||
{
|
||||
"rotation": 2,
|
||||
"name": "wf_act_match_to_sshot[0]",
|
||||
"className": "wf_act_match_to_sshot",
|
||||
"location": {
|
||||
"x": 1,
|
||||
"y": 0,
|
||||
"z": 1.9499999
|
||||
},
|
||||
"id": 8
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "bc_alpha1_num*11[1]",
|
||||
"className": "bc_alpha1_num*11",
|
||||
"location": {
|
||||
"x": 1,
|
||||
"y": 3,
|
||||
"z": 0
|
||||
},
|
||||
"id": 9,
|
||||
"state": "0"
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_act_toggle_state[2]",
|
||||
"className": "wf_act_toggle_state",
|
||||
"location": {
|
||||
"x": 2,
|
||||
"y": 0,
|
||||
"z": 1.3
|
||||
},
|
||||
"id": 10
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_trg_periodically[2]",
|
||||
"className": "wf_trg_periodically",
|
||||
"location": {
|
||||
"x": 2,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"id": 11
|
||||
},
|
||||
{
|
||||
"rotation": 2,
|
||||
"name": "wf_cnd_match_snapshot[2]",
|
||||
"className": "wf_cnd_match_snapshot",
|
||||
"location": {
|
||||
"x": 2,
|
||||
"y": 0,
|
||||
"z": 0.65
|
||||
},
|
||||
"id": 12
|
||||
},
|
||||
{
|
||||
"rotation": 2,
|
||||
"name": "wf_cnd_match_snapshot[3]",
|
||||
"className": "wf_cnd_match_snapshot",
|
||||
"location": {
|
||||
"x": 3,
|
||||
"y": 0,
|
||||
"z": 0.65
|
||||
},
|
||||
"id": 13
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_act_toggle_state[3]",
|
||||
"className": "wf_act_toggle_state",
|
||||
"location": {
|
||||
"x": 3,
|
||||
"y": 0,
|
||||
"z": 1.3
|
||||
},
|
||||
"id": 14
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_trg_periodically[3]",
|
||||
"className": "wf_trg_periodically",
|
||||
"location": {
|
||||
"x": 3,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"id": 15
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "bc_alpha1_num*11[2]",
|
||||
"className": "bc_alpha1_num*11",
|
||||
"location": {
|
||||
"x": 3,
|
||||
"y": 3,
|
||||
"z": 0
|
||||
},
|
||||
"id": 16,
|
||||
"state": "0"
|
||||
},
|
||||
{
|
||||
"rotation": 2,
|
||||
"name": "wf_act_match_to_sshot[1]",
|
||||
"className": "wf_act_match_to_sshot",
|
||||
"location": {
|
||||
"x": 4,
|
||||
"y": 0,
|
||||
"z": 1.3
|
||||
},
|
||||
"id": 17
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_colortile[0]",
|
||||
"className": "wf_colortile",
|
||||
"location": {
|
||||
"x": 4,
|
||||
"y": 0,
|
||||
"z": 1.95
|
||||
},
|
||||
"id": 18,
|
||||
"state": "0"
|
||||
},
|
||||
{
|
||||
"rotation": 2,
|
||||
"name": "wf_cnd_match_snapshot[4]",
|
||||
"className": "wf_cnd_match_snapshot",
|
||||
"location": {
|
||||
"x": 4,
|
||||
"y": 0,
|
||||
"z": 0.65
|
||||
},
|
||||
"id": 19
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "wf_trg_periodically[4]",
|
||||
"className": "wf_trg_periodically",
|
||||
"location": {
|
||||
"x": 4,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"id": 20
|
||||
},
|
||||
{
|
||||
"rotation": 0,
|
||||
"name": "bc_alpha1_num*11[3]",
|
||||
"className": "bc_alpha1_num*11",
|
||||
"location": {
|
||||
"x": 4,
|
||||
"y": 3,
|
||||
"z": 0
|
||||
},
|
||||
"id": 21,
|
||||
"state": "0"
|
||||
}
|
||||
]
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
BIN
Extensions/G-Translator_1.0.2/cfr.jar
Normal file
BIN
Extensions/G-Translator_1.0.2/cfr.jar
Normal file
Binary file not shown.
1
Extensions/G-Translator_1.0.2/command.txt
Normal file
1
Extensions/G-Translator_1.0.2/command.txt
Normal file
@ -0,0 +1 @@
|
||||
["java","-jar","translator.jar","-c","{cookie}","-p","{port}","-f","{filename}"]
|
||||
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package at.favre.lib.bytes;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
final class Base64 {
|
||||
private static final byte[] MAP = new byte[]{65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47};
|
||||
private static final byte[] URL_MAP = new byte[]{65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 45, 95};
|
||||
|
||||
private Base64() {
|
||||
}
|
||||
|
||||
static byte[] decode(CharSequence in) {
|
||||
char c;
|
||||
int limit;
|
||||
for (limit = in.length(); limit > 0 && ((c = in.charAt(limit - 1)) == '=' || c == '\n' || c == '\r' || c == ' ' || c == '\t'); --limit) {
|
||||
}
|
||||
byte[] out = new byte[(int)((long)limit * 6L / 8L)];
|
||||
int outCount = 0;
|
||||
int inCount = 0;
|
||||
int word = 0;
|
||||
for (int pos = 0; pos < limit; ++pos) {
|
||||
int bits;
|
||||
char c2 = in.charAt(pos);
|
||||
if (c2 >= 'A' && c2 <= 'Z') {
|
||||
bits = c2 - 65;
|
||||
} else if (c2 >= 'a' && c2 <= 'z') {
|
||||
bits = c2 - 71;
|
||||
} else if (c2 >= '0' && c2 <= '9') {
|
||||
bits = c2 + 4;
|
||||
} else if (c2 == '+' || c2 == '-') {
|
||||
bits = 62;
|
||||
} else if (c2 == '/' || c2 == '_') {
|
||||
bits = 63;
|
||||
} else {
|
||||
if (c2 == '\n' || c2 == '\r' || c2 == ' ' || c2 == '\t') continue;
|
||||
throw new IllegalArgumentException("invalid character to decode: " + c2);
|
||||
}
|
||||
word = word << 6 | (byte)bits;
|
||||
if (++inCount % 4 != 0) continue;
|
||||
out[outCount++] = (byte)(word >> 16);
|
||||
out[outCount++] = (byte)(word >> 8);
|
||||
out[outCount++] = (byte)word;
|
||||
}
|
||||
int lastWordChars = inCount % 4;
|
||||
if (lastWordChars == 1) {
|
||||
return null;
|
||||
}
|
||||
if (lastWordChars == 2) {
|
||||
out[outCount++] = (byte)((word <<= 12) >> 16);
|
||||
} else if (lastWordChars == 3) {
|
||||
out[outCount++] = (byte)((word <<= 6) >> 16);
|
||||
out[outCount++] = (byte)(word >> 8);
|
||||
}
|
||||
if (outCount == out.length) {
|
||||
return out;
|
||||
}
|
||||
return Arrays.copyOfRange(out, 0, outCount);
|
||||
}
|
||||
|
||||
static byte[] encode(byte[] in) {
|
||||
return Base64.encode(in, false, true);
|
||||
}
|
||||
|
||||
static byte[] encode(byte[] in, boolean urlSafe, boolean usePadding) {
|
||||
return Base64.encode(in, urlSafe ? URL_MAP : MAP, usePadding);
|
||||
}
|
||||
|
||||
private static byte[] encode(byte[] in, byte[] map, boolean usePadding) {
|
||||
int length = Base64.outLength(in.length, usePadding);
|
||||
byte[] out = new byte[length];
|
||||
int index = 0;
|
||||
int end = in.length - in.length % 3;
|
||||
for (int i = 0; i < end; i += 3) {
|
||||
out[index++] = map[(in[i] & 0xFF) >> 2];
|
||||
out[index++] = map[(in[i] & 3) << 4 | (in[i + 1] & 0xFF) >> 4];
|
||||
out[index++] = map[(in[i + 1] & 0xF) << 2 | (in[i + 2] & 0xFF) >> 6];
|
||||
out[index++] = map[in[i + 2] & 0x3F];
|
||||
}
|
||||
switch (in.length % 3) {
|
||||
case 1: {
|
||||
out[index++] = map[(in[end] & 0xFF) >> 2];
|
||||
out[index++] = map[(in[end] & 3) << 4];
|
||||
if (!usePadding) break;
|
||||
out[index++] = 61;
|
||||
out[index] = 61;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
out[index++] = map[(in[end] & 0xFF) >> 2];
|
||||
out[index++] = map[(in[end] & 3) << 4 | (in[end + 1] & 0xFF) >> 4];
|
||||
out[index++] = map[(in[end + 1] & 0xF) << 2];
|
||||
if (!usePadding) break;
|
||||
out[index] = 61;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private static int outLength(int srclen, boolean doPadding) {
|
||||
int len;
|
||||
if (doPadding) {
|
||||
len = 4 * ((srclen + 2) / 3);
|
||||
} else {
|
||||
int n = srclen % 3;
|
||||
len = 4 * (srclen / 3) + (n == 0 ? 0 : n + 1);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package at.favre.lib.bytes;
|
||||
|
||||
import at.favre.lib.bytes.BinaryToTextEncoding;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
final class BaseEncoding
|
||||
implements BinaryToTextEncoding.EncoderDecoder {
|
||||
private static final char ASCII_MAX = '\u007f';
|
||||
static final Alphabet BASE32_RFC4848 = new Alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567".toCharArray());
|
||||
static final char BASE32_RFC4848_PADDING = '=';
|
||||
private final Alphabet alphabet;
|
||||
private final Character paddingChar;
|
||||
|
||||
public BaseEncoding(Alphabet alphabet, Character paddingChar) {
|
||||
this.alphabet = Objects.requireNonNull(alphabet);
|
||||
this.paddingChar = paddingChar;
|
||||
}
|
||||
|
||||
private int maxEncodedSize(int bytes) {
|
||||
return this.alphabet.charsPerChunk * BaseEncoding.divide(bytes, this.alphabet.bytesPerChunk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encode(byte[] array, ByteOrder byteOrder) {
|
||||
return this.encode(array, 0, array.length);
|
||||
}
|
||||
|
||||
private String encode(byte[] bytes, int off, int len) {
|
||||
StringBuilder result = new StringBuilder(this.maxEncodedSize(len));
|
||||
try {
|
||||
this.encodeTo(result, bytes, off, len);
|
||||
}
|
||||
catch (IOException impossible) {
|
||||
throw new AssertionError((Object)impossible);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private void encodeTo(Appendable target, byte[] bytes, int off, int len) throws IOException {
|
||||
Objects.requireNonNull(target);
|
||||
for (int i = 0; i < len; i += this.alphabet.bytesPerChunk) {
|
||||
this.encodeChunkTo(target, bytes, off + i, Math.min(this.alphabet.bytesPerChunk, len - i));
|
||||
}
|
||||
}
|
||||
|
||||
private void encodeChunkTo(Appendable target, byte[] bytes, int off, int len) throws IOException {
|
||||
int bitsProcessed;
|
||||
Objects.requireNonNull(target);
|
||||
long bitBuffer = 0L;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
bitBuffer |= (long)(bytes[off + i] & 0xFF);
|
||||
bitBuffer <<= 8;
|
||||
}
|
||||
int bitOffset = (len + 1) * 8 - this.alphabet.bitsPerChar;
|
||||
for (bitsProcessed = 0; bitsProcessed < len * 8; bitsProcessed += this.alphabet.bitsPerChar) {
|
||||
int charIndex = (int)(bitBuffer >>> bitOffset - bitsProcessed) & this.alphabet.mask;
|
||||
target.append(this.alphabet.encode(charIndex));
|
||||
}
|
||||
if (this.paddingChar != null) {
|
||||
while (bitsProcessed < this.alphabet.bytesPerChunk * 8) {
|
||||
target.append(this.paddingChar.charValue());
|
||||
bitsProcessed += this.alphabet.bitsPerChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int maxDecodedSize(int chars) {
|
||||
return (int)(((long)this.alphabet.bitsPerChar * (long)chars + 7L) / 8L);
|
||||
}
|
||||
|
||||
private String trimTrailingPadding(CharSequence chars) {
|
||||
int l;
|
||||
Objects.requireNonNull(chars);
|
||||
if (this.paddingChar == null) {
|
||||
return chars.toString();
|
||||
}
|
||||
for (l = chars.length() - 1; l >= 0 && chars.charAt(l) == this.paddingChar.charValue(); --l) {
|
||||
}
|
||||
return chars.subSequence(0, l + 1).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] decode(CharSequence encoded) {
|
||||
encoded = this.trimTrailingPadding(encoded);
|
||||
byte[] tmp = new byte[this.maxDecodedSize(encoded.length())];
|
||||
int len = this.decodeTo(tmp, encoded);
|
||||
return BaseEncoding.extract(tmp, len);
|
||||
}
|
||||
|
||||
private static byte[] extract(byte[] result, int length) {
|
||||
if (length == result.length) {
|
||||
return result;
|
||||
}
|
||||
byte[] trunc = new byte[length];
|
||||
System.arraycopy(result, 0, trunc, 0, length);
|
||||
return trunc;
|
||||
}
|
||||
|
||||
private int decodeTo(byte[] target, CharSequence chars) {
|
||||
Objects.requireNonNull(target);
|
||||
chars = this.trimTrailingPadding(chars);
|
||||
int bytesWritten = 0;
|
||||
for (int charIdx = 0; charIdx < chars.length(); charIdx += this.alphabet.charsPerChunk) {
|
||||
long chunk = 0L;
|
||||
int charsProcessed = 0;
|
||||
for (int i = 0; i < this.alphabet.charsPerChunk; ++i) {
|
||||
chunk <<= this.alphabet.bitsPerChar;
|
||||
if (charIdx + i >= chars.length()) continue;
|
||||
chunk |= (long)this.alphabet.decode(chars.charAt(charIdx + charsProcessed++));
|
||||
}
|
||||
int minOffset = this.alphabet.bytesPerChunk * 8 - charsProcessed * this.alphabet.bitsPerChar;
|
||||
for (int offset = (this.alphabet.bytesPerChunk - 1) * 8; offset >= minOffset; offset -= 8) {
|
||||
target[bytesWritten++] = (byte)(chunk >>> offset & 0xFFL);
|
||||
}
|
||||
}
|
||||
return bytesWritten;
|
||||
}
|
||||
|
||||
private static int divide(int p, int q) {
|
||||
int div = p / q;
|
||||
int rem = p - q * div;
|
||||
if (rem == 0) {
|
||||
return div;
|
||||
}
|
||||
int signum = 1 | (p ^ q) >> 31;
|
||||
return signum > 0 ? div + signum : div;
|
||||
}
|
||||
|
||||
private static int log2(int x) {
|
||||
return 31 - Integer.numberOfLeadingZeros(x);
|
||||
}
|
||||
|
||||
static final class Alphabet {
|
||||
private final char[] chars;
|
||||
final int mask;
|
||||
final int bitsPerChar;
|
||||
final int charsPerChunk;
|
||||
final int bytesPerChunk;
|
||||
private final byte[] decodabet;
|
||||
|
||||
Alphabet(char[] chars) {
|
||||
this.chars = Objects.requireNonNull(chars);
|
||||
this.bitsPerChar = BaseEncoding.log2(chars.length);
|
||||
int gcd = Math.min(8, Integer.lowestOneBit(this.bitsPerChar));
|
||||
this.charsPerChunk = 8 / gcd;
|
||||
this.bytesPerChunk = this.bitsPerChar / gcd;
|
||||
this.mask = chars.length - 1;
|
||||
byte[] decodabet = new byte[128];
|
||||
Arrays.fill(decodabet, (byte)-1);
|
||||
for (int i = 0; i < chars.length; ++i) {
|
||||
char c = chars[i];
|
||||
decodabet[c] = (byte)i;
|
||||
}
|
||||
this.decodabet = decodabet;
|
||||
}
|
||||
|
||||
char encode(int bits) {
|
||||
return this.chars[bits];
|
||||
}
|
||||
|
||||
int decode(char ch) {
|
||||
return this.decodabet[ch];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package at.favre.lib.bytes;
|
||||
|
||||
import at.favre.lib.bytes.Base64;
|
||||
import at.favre.lib.bytes.Bytes;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Objects;
|
||||
|
||||
public interface BinaryToTextEncoding {
|
||||
|
||||
public static class BaseRadixNumber
|
||||
implements EncoderDecoder {
|
||||
private final int radix;
|
||||
|
||||
BaseRadixNumber(int radix) {
|
||||
if (radix < 2 || radix > 36) {
|
||||
throw new IllegalArgumentException("supported radix is between 2 and 36");
|
||||
}
|
||||
this.radix = radix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encode(byte[] array, ByteOrder byteOrder) {
|
||||
return new BigInteger(1, byteOrder == ByteOrder.BIG_ENDIAN ? array : Bytes.from(array).reverse().array()).toString(this.radix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] decode(CharSequence encoded) {
|
||||
byte[] array = new BigInteger(encoded.toString(), this.radix).toByteArray();
|
||||
if (array[0] == 0) {
|
||||
byte[] tmp = new byte[array.length - 1];
|
||||
System.arraycopy(array, 1, tmp, 0, tmp.length);
|
||||
array = tmp;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Base64Encoding
|
||||
implements EncoderDecoder {
|
||||
private final boolean urlSafe;
|
||||
private final boolean padding;
|
||||
|
||||
Base64Encoding() {
|
||||
this(false, true);
|
||||
}
|
||||
|
||||
Base64Encoding(boolean urlSafe, boolean padding) {
|
||||
this.urlSafe = urlSafe;
|
||||
this.padding = padding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encode(byte[] array, ByteOrder byteOrder) {
|
||||
return new String(Base64.encode(byteOrder == ByteOrder.BIG_ENDIAN ? array : Bytes.from(array).reverse().array(), this.urlSafe, this.padding), StandardCharsets.US_ASCII);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] decode(CharSequence encoded) {
|
||||
return Base64.decode(encoded);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Hex
|
||||
implements EncoderDecoder {
|
||||
private static final char[] LOOKUP_TABLE_LOWER = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
private static final char[] LOOKUP_TABLE_UPPER = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
private final boolean upperCase;
|
||||
|
||||
public Hex() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
public Hex(boolean upperCase) {
|
||||
this.upperCase = upperCase;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encode(byte[] byteArray, ByteOrder byteOrder) {
|
||||
char[] buffer = new char[byteArray.length * 2];
|
||||
char[] lookup = this.upperCase ? LOOKUP_TABLE_UPPER : LOOKUP_TABLE_LOWER;
|
||||
for (int i = 0; i < byteArray.length; ++i) {
|
||||
int index = byteOrder == ByteOrder.BIG_ENDIAN ? i : byteArray.length - i - 1;
|
||||
buffer[i << 1] = lookup[byteArray[index] >> 4 & 0xF];
|
||||
buffer[(i << 1) + 1] = lookup[byteArray[index] & 0xF];
|
||||
}
|
||||
return new String(buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] decode(CharSequence hexString) {
|
||||
boolean isOddLength;
|
||||
int start = Objects.requireNonNull(hexString).length() > 2 && hexString.charAt(0) == '0' && hexString.charAt(1) == 'x' ? 2 : 0;
|
||||
int len = hexString.length();
|
||||
boolean bl = isOddLength = len % 2 != 0;
|
||||
if (isOddLength) {
|
||||
--start;
|
||||
}
|
||||
byte[] data = new byte[(len - start) / 2];
|
||||
for (int i = start; i < len; i += 2) {
|
||||
int first4Bits = i == start && isOddLength ? 0 : Character.digit(hexString.charAt(i), 16);
|
||||
int second4Bits = Character.digit(hexString.charAt(i + 1), 16);
|
||||
if (first4Bits == -1 || second4Bits == -1) {
|
||||
if (i == start && isOddLength) {
|
||||
throw new IllegalArgumentException("'" + hexString.charAt(i + 1) + "' at index " + (i + 1) + " is not hex formatted");
|
||||
}
|
||||
throw new IllegalArgumentException("'" + hexString.charAt(i) + hexString.charAt(i + 1) + "' at index " + i + " is not hex formatted");
|
||||
}
|
||||
data[(i - start) / 2] = (byte)((first4Bits << 4) + second4Bits);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
public static interface EncoderDecoder
|
||||
extends Encoder,
|
||||
Decoder {
|
||||
}
|
||||
|
||||
public static interface Decoder {
|
||||
public byte[] decode(CharSequence var1);
|
||||
}
|
||||
|
||||
public static interface Encoder {
|
||||
public String encode(byte[] var1, ByteOrder var2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,817 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package at.favre.lib.bytes;
|
||||
|
||||
import at.favre.lib.bytes.BaseEncoding;
|
||||
import at.favre.lib.bytes.BinaryToTextEncoding;
|
||||
import at.favre.lib.bytes.BytesFactory;
|
||||
import at.favre.lib.bytes.BytesTransformer;
|
||||
import at.favre.lib.bytes.BytesValidator;
|
||||
import at.favre.lib.bytes.BytesValidators;
|
||||
import at.favre.lib.bytes.MutableBytes;
|
||||
import at.favre.lib.bytes.ReadOnlyBytes;
|
||||
import at.favre.lib.bytes.Util;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInput;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.SecureRandom;
|
||||
import java.text.Normalizer;
|
||||
import java.util.Arrays;
|
||||
import java.util.BitSet;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Bytes
|
||||
implements Comparable<Bytes>,
|
||||
Serializable,
|
||||
Iterable<Byte> {
|
||||
private static final Bytes EMPTY = Bytes.wrap(new byte[0]);
|
||||
private final byte[] byteArray;
|
||||
private final ByteOrder byteOrder;
|
||||
private final BytesFactory factory;
|
||||
private transient int hashCodeCache;
|
||||
static final long serialVersionUID = 1L;
|
||||
|
||||
public static Bytes allocate(int length) {
|
||||
return Bytes.allocate(length, (byte)0);
|
||||
}
|
||||
|
||||
public static Bytes allocate(int length, byte defaultValue) {
|
||||
if (length == 0) {
|
||||
return Bytes.empty();
|
||||
}
|
||||
byte[] array = new byte[length];
|
||||
if (defaultValue != 0) {
|
||||
Arrays.fill(array, defaultValue);
|
||||
}
|
||||
return Bytes.wrap(array);
|
||||
}
|
||||
|
||||
public static Bytes empty() {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
public static Bytes wrap(Bytes bytes) {
|
||||
return Bytes.wrap(Objects.requireNonNull(bytes, "passed Byte instance must not be null").internalArray(), bytes.byteOrder);
|
||||
}
|
||||
|
||||
public static Bytes wrapNullSafe(byte[] array) {
|
||||
return array != null ? Bytes.wrap(array) : Bytes.empty();
|
||||
}
|
||||
|
||||
public static Bytes wrap(byte[] array) {
|
||||
return Bytes.wrap(array, ByteOrder.BIG_ENDIAN);
|
||||
}
|
||||
|
||||
public static Bytes wrap(byte[] array, ByteOrder byteOrder) {
|
||||
return new Bytes(Objects.requireNonNull(array, "passed array must not be null"), byteOrder);
|
||||
}
|
||||
|
||||
public static Bytes from(byte[] byteArrayToCopy) {
|
||||
return Bytes.wrap(Arrays.copyOf(Objects.requireNonNull(byteArrayToCopy, "must at least pass a single byte"), byteArrayToCopy.length));
|
||||
}
|
||||
|
||||
public static Bytes fromNullSafe(byte[] byteArrayToCopy) {
|
||||
return byteArrayToCopy != null ? Bytes.from(byteArrayToCopy) : Bytes.empty();
|
||||
}
|
||||
|
||||
public static Bytes from(byte[] array, int offset, int length) {
|
||||
Objects.requireNonNull(array, "passed array must not be null");
|
||||
byte[] part = new byte[length];
|
||||
System.arraycopy(array, offset, part, 0, length);
|
||||
return Bytes.wrap(part);
|
||||
}
|
||||
|
||||
public static Bytes from(byte[] ... moreArrays) {
|
||||
return Bytes.wrap(Util.Byte.concat(moreArrays));
|
||||
}
|
||||
|
||||
public static Bytes from(Bytes ... moreBytes) {
|
||||
Objects.requireNonNull(moreBytes, "bytes most not be null");
|
||||
byte[][] bytes = new byte[moreBytes.length][];
|
||||
for (int i = 0; i < moreBytes.length; ++i) {
|
||||
bytes[i] = moreBytes[i].array();
|
||||
}
|
||||
return Bytes.from(bytes);
|
||||
}
|
||||
|
||||
public static Bytes from(Collection<Byte> bytesCollection) {
|
||||
return Bytes.wrap(Util.Converter.toArray(bytesCollection));
|
||||
}
|
||||
|
||||
public static Bytes from(Byte[] boxedObjectArray) {
|
||||
return Bytes.wrap(Util.Converter.toPrimitiveArray(boxedObjectArray));
|
||||
}
|
||||
|
||||
public static Bytes from(byte singleByte) {
|
||||
return Bytes.wrap(new byte[]{singleByte});
|
||||
}
|
||||
|
||||
public static Bytes from(byte firstByte, byte ... moreBytes) {
|
||||
return Bytes.wrap(Util.Byte.concatVararg(firstByte, moreBytes));
|
||||
}
|
||||
|
||||
public static Bytes from(boolean booleanValue) {
|
||||
return Bytes.wrap(new byte[]{booleanValue ? (byte)1 : 0});
|
||||
}
|
||||
|
||||
public static Bytes from(char char2Byte) {
|
||||
return Bytes.wrap(ByteBuffer.allocate(2).putChar(char2Byte).array());
|
||||
}
|
||||
|
||||
public static Bytes from(short short2Byte) {
|
||||
return Bytes.wrap(ByteBuffer.allocate(2).putShort(short2Byte).array());
|
||||
}
|
||||
|
||||
public static Bytes from(int integer4byte) {
|
||||
return Bytes.wrap(ByteBuffer.allocate(4).putInt(integer4byte).array());
|
||||
}
|
||||
|
||||
public static Bytes from(int ... intArray) {
|
||||
return Bytes.wrap(Util.Converter.toByteArray(Objects.requireNonNull(intArray, "must provide at least a single int")));
|
||||
}
|
||||
|
||||
public static Bytes from(long long8byte) {
|
||||
return Bytes.wrap(ByteBuffer.allocate(8).putLong(long8byte).array());
|
||||
}
|
||||
|
||||
public static Bytes from(long ... longArray) {
|
||||
return Bytes.wrap(Util.Converter.toByteArray(Objects.requireNonNull(longArray, "must provide at least a single long")));
|
||||
}
|
||||
|
||||
public static Bytes from(float float4byte) {
|
||||
return Bytes.wrap(ByteBuffer.allocate(4).putFloat(float4byte).array());
|
||||
}
|
||||
|
||||
public static Bytes from(float ... floatArray) {
|
||||
return Bytes.wrap(Util.Converter.toByteArray(Objects.requireNonNull(floatArray, "must provide at least a single float")));
|
||||
}
|
||||
|
||||
public static Bytes from(double double8Byte) {
|
||||
return Bytes.wrap(ByteBuffer.allocate(8).putDouble(double8Byte).array());
|
||||
}
|
||||
|
||||
public static Bytes from(double ... doubleArray) {
|
||||
return Bytes.wrap(Util.Converter.toByteArray(Objects.requireNonNull(doubleArray, "must provide at least a single double")));
|
||||
}
|
||||
|
||||
public static Bytes from(ByteBuffer buffer) {
|
||||
return Bytes.wrap(Objects.requireNonNull(buffer, "provided byte buffer must not be null").array(), buffer.order());
|
||||
}
|
||||
|
||||
public static Bytes from(CharBuffer buffer) {
|
||||
return Bytes.from(Objects.requireNonNull(buffer, "provided char buffer must not be null").array());
|
||||
}
|
||||
|
||||
public static Bytes from(IntBuffer buffer) {
|
||||
return Bytes.from(Objects.requireNonNull(buffer, "provided int buffer must not be null").array());
|
||||
}
|
||||
|
||||
public static Bytes from(BitSet set) {
|
||||
return Bytes.wrap(set.toByteArray());
|
||||
}
|
||||
|
||||
public static Bytes from(BigInteger bigInteger) {
|
||||
return Bytes.wrap(bigInteger.toByteArray());
|
||||
}
|
||||
|
||||
public static Bytes from(InputStream stream) {
|
||||
return Bytes.wrap(Util.File.readFromStream(stream, -1));
|
||||
}
|
||||
|
||||
public static Bytes from(InputStream stream, int maxLength) {
|
||||
return Bytes.wrap(Util.File.readFromStream(stream, maxLength));
|
||||
}
|
||||
|
||||
public static Bytes from(DataInput dataInput, int length) {
|
||||
return Bytes.wrap(Util.File.readFromDataInput(dataInput, length));
|
||||
}
|
||||
|
||||
public static Bytes from(File file) {
|
||||
return Bytes.wrap(Util.File.readFromFile(file));
|
||||
}
|
||||
|
||||
public static Bytes from(File file, int offset, int length) {
|
||||
return Bytes.wrap(Util.File.readFromFile(file, offset, length));
|
||||
}
|
||||
|
||||
public static Bytes from(CharSequence utf8String) {
|
||||
return Bytes.from(utf8String, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static Bytes from(CharSequence utf8String, Normalizer.Form form) {
|
||||
return Bytes.from((CharSequence)Normalizer.normalize(utf8String, form), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static Bytes from(CharSequence string, Charset charset) {
|
||||
return Bytes.wrap(Objects.requireNonNull(string, "provided string must not be null").toString().getBytes(Objects.requireNonNull(charset, "provided charset must not be null")));
|
||||
}
|
||||
|
||||
public static Bytes from(char[] charArray) {
|
||||
return Bytes.from(charArray, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static Bytes from(char[] charArray, Charset charset) {
|
||||
return Bytes.from(charArray, charset, 0, charArray.length);
|
||||
}
|
||||
|
||||
public static Bytes from(char[] charArray, Charset charset, int offset, int length) {
|
||||
return Bytes.from(Util.Converter.charToByteArray(charArray, charset, offset, length));
|
||||
}
|
||||
|
||||
public static Bytes from(UUID uuid) {
|
||||
return Bytes.wrap(Util.Converter.toBytesFromUUID(Objects.requireNonNull(uuid)).array());
|
||||
}
|
||||
|
||||
public static Bytes parseBinary(CharSequence binaryString) {
|
||||
return Bytes.parseRadix(binaryString, 2);
|
||||
}
|
||||
|
||||
public static Bytes parseOctal(CharSequence octalString) {
|
||||
return Bytes.parseRadix(octalString, 8);
|
||||
}
|
||||
|
||||
public static Bytes parseDec(CharSequence decString) {
|
||||
return Bytes.parseRadix(decString, 10);
|
||||
}
|
||||
|
||||
public static Bytes parseRadix(CharSequence radixNumberString, int radix) {
|
||||
return Bytes.parse(radixNumberString, new BinaryToTextEncoding.BaseRadixNumber(radix));
|
||||
}
|
||||
|
||||
public static Bytes parseHex(CharSequence hexString) {
|
||||
return Bytes.parse(hexString, new BinaryToTextEncoding.Hex());
|
||||
}
|
||||
|
||||
public static Bytes parseBase32(CharSequence base32Rfc4648String) {
|
||||
return Bytes.parse(base32Rfc4648String, new BaseEncoding(BaseEncoding.BASE32_RFC4848, Character.valueOf('=')));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Bytes parseBase36(CharSequence base36String) {
|
||||
return Bytes.parse(base36String, new BinaryToTextEncoding.BaseRadixNumber(36));
|
||||
}
|
||||
|
||||
public static Bytes parseBase64(CharSequence base64String) {
|
||||
return Bytes.parse(base64String, new BinaryToTextEncoding.Base64Encoding());
|
||||
}
|
||||
|
||||
public static Bytes parse(CharSequence encoded, BinaryToTextEncoding.Decoder decoder) {
|
||||
return Bytes.wrap(Objects.requireNonNull(decoder, "passed decoder instance must no be null").decode(Objects.requireNonNull(encoded, "encoded data must not be null")));
|
||||
}
|
||||
|
||||
public static Bytes random(int length) {
|
||||
return Bytes.random(length, new SecureRandom());
|
||||
}
|
||||
|
||||
public static Bytes unsecureRandom(int length) {
|
||||
return Bytes.random(length, new Random());
|
||||
}
|
||||
|
||||
public static Bytes unsecureRandom(int length, long seed) {
|
||||
return Bytes.random(length, new Random(seed));
|
||||
}
|
||||
|
||||
public static Bytes random(int length, Random random) {
|
||||
byte[] array = new byte[length];
|
||||
random.nextBytes(array);
|
||||
return Bytes.wrap(array);
|
||||
}
|
||||
|
||||
Bytes(byte[] byteArray, ByteOrder byteOrder) {
|
||||
this(byteArray, byteOrder, new Factory());
|
||||
}
|
||||
|
||||
Bytes(byte[] byteArray, ByteOrder byteOrder, BytesFactory factory) {
|
||||
this.byteArray = byteArray;
|
||||
this.byteOrder = byteOrder;
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
public Bytes append(Bytes bytes) {
|
||||
return this.append(bytes.internalArray());
|
||||
}
|
||||
|
||||
public Bytes append(byte singleByte) {
|
||||
return this.append(Bytes.from(singleByte));
|
||||
}
|
||||
|
||||
public Bytes append(char char2Bytes) {
|
||||
return this.append(Bytes.from(char2Bytes));
|
||||
}
|
||||
|
||||
public Bytes append(short short2Bytes) {
|
||||
return this.append(Bytes.from(short2Bytes));
|
||||
}
|
||||
|
||||
public Bytes append(int integer4Bytes) {
|
||||
return this.append(Bytes.from(integer4Bytes));
|
||||
}
|
||||
|
||||
public Bytes append(long long8Bytes) {
|
||||
return this.append(Bytes.from(long8Bytes));
|
||||
}
|
||||
|
||||
public Bytes append(byte[] ... arrays) {
|
||||
return this.append(Bytes.from(arrays));
|
||||
}
|
||||
|
||||
public Bytes append(byte[] secondArray) {
|
||||
return this.transform(new BytesTransformer.ConcatTransformer(secondArray));
|
||||
}
|
||||
|
||||
public Bytes appendNullSafe(byte[] secondArrayNullable) {
|
||||
return secondArrayNullable == null ? this : this.append(secondArrayNullable);
|
||||
}
|
||||
|
||||
public Bytes append(CharSequence stringUtf8) {
|
||||
return this.append(stringUtf8, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public Bytes append(CharSequence string, Charset charset) {
|
||||
return this.transform(new BytesTransformer.ConcatTransformer(Objects.requireNonNull(string).toString().getBytes(Objects.requireNonNull(charset))));
|
||||
}
|
||||
|
||||
public Bytes xor(Bytes bytes) {
|
||||
return this.xor(bytes.internalArray());
|
||||
}
|
||||
|
||||
public Bytes xor(byte[] secondArray) {
|
||||
return this.transform(new BytesTransformer.BitWiseOperatorTransformer(secondArray, BytesTransformer.BitWiseOperatorTransformer.Mode.XOR));
|
||||
}
|
||||
|
||||
public Bytes and(Bytes bytes) {
|
||||
return this.and(bytes.internalArray());
|
||||
}
|
||||
|
||||
public Bytes and(byte[] secondArray) {
|
||||
return this.transform(new BytesTransformer.BitWiseOperatorTransformer(secondArray, BytesTransformer.BitWiseOperatorTransformer.Mode.AND));
|
||||
}
|
||||
|
||||
public Bytes or(Bytes bytes) {
|
||||
return this.or(bytes.internalArray());
|
||||
}
|
||||
|
||||
public Bytes or(byte[] secondArray) {
|
||||
return this.transform(new BytesTransformer.BitWiseOperatorTransformer(secondArray, BytesTransformer.BitWiseOperatorTransformer.Mode.OR));
|
||||
}
|
||||
|
||||
public Bytes not() {
|
||||
return this.transform(new BytesTransformer.NegateTransformer());
|
||||
}
|
||||
|
||||
public Bytes leftShift(int shiftCount) {
|
||||
return this.transform(new BytesTransformer.ShiftTransformer(shiftCount, BytesTransformer.ShiftTransformer.Type.LEFT_SHIFT, this.byteOrder));
|
||||
}
|
||||
|
||||
public Bytes rightShift(int shiftCount) {
|
||||
return this.transform(new BytesTransformer.ShiftTransformer(shiftCount, BytesTransformer.ShiftTransformer.Type.RIGHT_SHIFT, this.byteOrder));
|
||||
}
|
||||
|
||||
public Bytes switchBit(int bitPosition, boolean newBitValue) {
|
||||
return this.transform(new BytesTransformer.BitSwitchTransformer(bitPosition, newBitValue));
|
||||
}
|
||||
|
||||
public Bytes switchBit(int bitPosition) {
|
||||
return this.transform(new BytesTransformer.BitSwitchTransformer(bitPosition, null));
|
||||
}
|
||||
|
||||
public Bytes copy() {
|
||||
return this.transform(new BytesTransformer.CopyTransformer(0, this.length()));
|
||||
}
|
||||
|
||||
public Bytes copy(int offset, int length) {
|
||||
return this.transform(new BytesTransformer.CopyTransformer(offset, length));
|
||||
}
|
||||
|
||||
public Bytes reverse() {
|
||||
return this.transform(new BytesTransformer.ReverseTransformer());
|
||||
}
|
||||
|
||||
public Bytes resize(int newByteLength) {
|
||||
return this.resize(newByteLength, BytesTransformer.ResizeTransformer.Mode.RESIZE_KEEP_FROM_MAX_LENGTH);
|
||||
}
|
||||
|
||||
public Bytes resize(int newByteLength, BytesTransformer.ResizeTransformer.Mode mode) {
|
||||
return this.transform(new BytesTransformer.ResizeTransformer(newByteLength, mode));
|
||||
}
|
||||
|
||||
public Bytes hashMd5() {
|
||||
return this.hash("MD5");
|
||||
}
|
||||
|
||||
public Bytes hashSha1() {
|
||||
return this.hash("SHA-1");
|
||||
}
|
||||
|
||||
public Bytes hashSha256() {
|
||||
return this.hash("SHA-256");
|
||||
}
|
||||
|
||||
public Bytes hash(String algorithm) {
|
||||
return this.transform(new BytesTransformer.MessageDigestTransformer(algorithm));
|
||||
}
|
||||
|
||||
public Bytes transform(BytesTransformer transformer) {
|
||||
return this.factory.wrap(transformer.transform(this.internalArray(), this.isMutable()), this.byteOrder);
|
||||
}
|
||||
|
||||
public boolean validateNotOnlyZeros() {
|
||||
return this.validate(BytesValidators.notOnlyOf((byte)0));
|
||||
}
|
||||
|
||||
public boolean validate(BytesValidator ... bytesValidators) {
|
||||
return BytesValidators.and(Objects.requireNonNull(bytesValidators)).validate(this.internalArray());
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return this.internalArray().length;
|
||||
}
|
||||
|
||||
public int lengthBit() {
|
||||
return this.length() * 8;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.length() == 0;
|
||||
}
|
||||
|
||||
public ByteOrder byteOrder() {
|
||||
return this.byteOrder;
|
||||
}
|
||||
|
||||
public boolean isMutable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isReadOnly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean contains(byte target) {
|
||||
return this.indexOf(target) != -1;
|
||||
}
|
||||
|
||||
public int indexOf(byte target) {
|
||||
return this.indexOf(target, 0);
|
||||
}
|
||||
|
||||
public int indexOf(byte target, int fromIndex) {
|
||||
return this.indexOf(new byte[]{target}, fromIndex);
|
||||
}
|
||||
|
||||
public int indexOf(byte[] subArray) {
|
||||
return this.indexOf(subArray, 0);
|
||||
}
|
||||
|
||||
public int indexOf(byte[] subArray, int fromIndex) {
|
||||
return Util.Byte.indexOf(this.internalArray(), subArray, fromIndex, this.length());
|
||||
}
|
||||
|
||||
public boolean startsWith(byte[] subArray) {
|
||||
return Util.Byte.indexOf(this.internalArray(), subArray, 0, 1) == 0;
|
||||
}
|
||||
|
||||
public int lastIndexOf(byte target) {
|
||||
return Util.Byte.lastIndexOf(this.internalArray(), target, 0, this.length());
|
||||
}
|
||||
|
||||
public boolean endsWith(byte[] subArray) {
|
||||
int startIndex = this.length() - subArray.length;
|
||||
return startIndex >= 0 && Util.Byte.indexOf(this.internalArray(), subArray, startIndex, startIndex + 1) == startIndex;
|
||||
}
|
||||
|
||||
public boolean bitAt(int bitIndex) {
|
||||
Util.Validation.checkIndexBounds(this.lengthBit(), bitIndex, 1, "bit");
|
||||
if (this.byteOrder == ByteOrder.BIG_ENDIAN) {
|
||||
return (this.byteAt(this.length() - 1 - bitIndex / 8) >>> bitIndex % 8 & 1) != 0;
|
||||
}
|
||||
return (this.byteAt(bitIndex / 8) >>> bitIndex % 8 & 1) != 0;
|
||||
}
|
||||
|
||||
public byte byteAt(int index) {
|
||||
Util.Validation.checkIndexBounds(this.length(), index, 1, "byte");
|
||||
return this.internalArray()[index];
|
||||
}
|
||||
|
||||
public int unsignedByteAt(int index) {
|
||||
Util.Validation.checkIndexBounds(this.length(), index, 1, "unsigned byte");
|
||||
return 0xFF & this.internalArray()[index];
|
||||
}
|
||||
|
||||
public char charAt(int index) {
|
||||
Util.Validation.checkIndexBounds(this.length(), index, 2, "char");
|
||||
return ((ByteBuffer)this.internalBuffer().position(index)).getChar();
|
||||
}
|
||||
|
||||
public short shortAt(int index) {
|
||||
Util.Validation.checkIndexBounds(this.length(), index, 2, "short");
|
||||
return ((ByteBuffer)this.internalBuffer().position(index)).getShort();
|
||||
}
|
||||
|
||||
public int intAt(int index) {
|
||||
Util.Validation.checkIndexBounds(this.length(), index, 4, "int");
|
||||
return ((ByteBuffer)this.internalBuffer().position(index)).getInt();
|
||||
}
|
||||
|
||||
public long longAt(int index) {
|
||||
Util.Validation.checkIndexBounds(this.length(), index, 8, "long");
|
||||
return ((ByteBuffer)this.internalBuffer().position(index)).getLong();
|
||||
}
|
||||
|
||||
public int count(byte target) {
|
||||
return Util.Byte.countByte(this.internalArray(), target);
|
||||
}
|
||||
|
||||
public int count(byte[] pattern) {
|
||||
return Util.Byte.countByteArray(this.internalArray(), pattern);
|
||||
}
|
||||
|
||||
public double entropy() {
|
||||
return Util.Byte.entropy(this.internalArray());
|
||||
}
|
||||
|
||||
public Bytes duplicate() {
|
||||
return this.factory.wrap(this.internalArray(), this.byteOrder);
|
||||
}
|
||||
|
||||
public Bytes byteOrder(ByteOrder byteOrder) {
|
||||
if (byteOrder != this.byteOrder) {
|
||||
return Bytes.wrap(this.internalArray(), byteOrder);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ReadOnlyBytes readOnly() {
|
||||
if (this.isReadOnly()) {
|
||||
return (ReadOnlyBytes)this;
|
||||
}
|
||||
return new ReadOnlyBytes(this.internalArray(), this.byteOrder);
|
||||
}
|
||||
|
||||
public ByteBuffer buffer() {
|
||||
return ByteBuffer.wrap(this.array()).order(this.byteOrder);
|
||||
}
|
||||
|
||||
private ByteBuffer internalBuffer() {
|
||||
return ByteBuffer.wrap(this.internalArray()).order(this.byteOrder);
|
||||
}
|
||||
|
||||
public MutableBytes mutable() {
|
||||
if (this instanceof MutableBytes) {
|
||||
return (MutableBytes)this;
|
||||
}
|
||||
return new MutableBytes(this.array(), this.byteOrder);
|
||||
}
|
||||
|
||||
public InputStream inputStream() {
|
||||
return new ByteArrayInputStream(this.array());
|
||||
}
|
||||
|
||||
public byte[] array() {
|
||||
return this.internalArray();
|
||||
}
|
||||
|
||||
byte[] internalArray() {
|
||||
return this.byteArray;
|
||||
}
|
||||
|
||||
public String encodeBinary() {
|
||||
return this.encodeRadix(2);
|
||||
}
|
||||
|
||||
public String encodeOctal() {
|
||||
return this.encodeRadix(8);
|
||||
}
|
||||
|
||||
public String encodeDec() {
|
||||
return this.encodeRadix(10);
|
||||
}
|
||||
|
||||
public String encodeRadix(int radix) {
|
||||
return this.encode(new BinaryToTextEncoding.BaseRadixNumber(radix));
|
||||
}
|
||||
|
||||
public String encodeHex() {
|
||||
return this.encodeHex(false);
|
||||
}
|
||||
|
||||
public String encodeHex(boolean upperCase) {
|
||||
return this.encode(new BinaryToTextEncoding.Hex(upperCase));
|
||||
}
|
||||
|
||||
public String encodeBase32() {
|
||||
return this.encode(new BaseEncoding(BaseEncoding.BASE32_RFC4848, Character.valueOf('=')));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String encodeBase36() {
|
||||
return this.encodeRadix(36);
|
||||
}
|
||||
|
||||
public String encodeBase64() {
|
||||
return this.encodeBase64(false, true);
|
||||
}
|
||||
|
||||
public String encodeBase64Url() {
|
||||
return this.encodeBase64(true, true);
|
||||
}
|
||||
|
||||
public String encodeBase64(boolean urlSafe, boolean withPadding) {
|
||||
return this.encode(new BinaryToTextEncoding.Base64Encoding(urlSafe, withPadding));
|
||||
}
|
||||
|
||||
public String encodeUtf8() {
|
||||
return this.encodeCharset(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public String encodeCharset(Charset charset) {
|
||||
return new String(this.internalArray(), Objects.requireNonNull(charset, "given charset must not be null"));
|
||||
}
|
||||
|
||||
public byte[] encodeUtf8ToBytes() {
|
||||
return this.encodeCharsetToBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public byte[] encodeCharsetToBytes(Charset charset) {
|
||||
return this.encodeCharset(charset).getBytes(charset);
|
||||
}
|
||||
|
||||
public String encode(BinaryToTextEncoding.Encoder encoder) {
|
||||
return encoder.encode(this.internalArray(), this.byteOrder);
|
||||
}
|
||||
|
||||
public List<Byte> toList() {
|
||||
return Util.Converter.toList(this.internalArray());
|
||||
}
|
||||
|
||||
public Byte[] toBoxedArray() {
|
||||
return Util.Converter.toBoxedArray(this.internalArray());
|
||||
}
|
||||
|
||||
public BitSet toBitSet() {
|
||||
return BitSet.valueOf(this.internalArray());
|
||||
}
|
||||
|
||||
public BigInteger toBigInteger() {
|
||||
if (this.byteOrder == ByteOrder.LITTLE_ENDIAN) {
|
||||
return new BigInteger(new BytesTransformer.ReverseTransformer().transform(this.internalArray(), false));
|
||||
}
|
||||
return new BigInteger(this.internalArray());
|
||||
}
|
||||
|
||||
public UUID toUUID() {
|
||||
Util.Validation.checkExactLength(this.length(), 16, "UUID");
|
||||
ByteBuffer byteBuffer = this.buffer();
|
||||
return new UUID(byteBuffer.getLong(), byteBuffer.getLong());
|
||||
}
|
||||
|
||||
public byte toByte() {
|
||||
Util.Validation.checkExactLength(this.length(), 1, "byte");
|
||||
return this.internalArray()[0];
|
||||
}
|
||||
|
||||
public int toUnsignedByte() {
|
||||
Util.Validation.checkExactLength(this.length(), 1, "unsigned byte");
|
||||
return this.unsignedByteAt(0);
|
||||
}
|
||||
|
||||
public char toChar() {
|
||||
Util.Validation.checkExactLength(this.length(), 2, "char");
|
||||
return this.charAt(0);
|
||||
}
|
||||
|
||||
public short toShort() {
|
||||
Util.Validation.checkExactLength(this.length(), 2, "short");
|
||||
return this.shortAt(0);
|
||||
}
|
||||
|
||||
public int toInt() {
|
||||
Util.Validation.checkExactLength(this.length(), 4, "int");
|
||||
return this.intAt(0);
|
||||
}
|
||||
|
||||
public int[] toIntArray() {
|
||||
Util.Validation.checkModLength(this.length(), 4, "creating an int array");
|
||||
return Util.Converter.toIntArray(this.internalArray(), this.byteOrder);
|
||||
}
|
||||
|
||||
public long toLong() {
|
||||
Util.Validation.checkExactLength(this.length(), 8, "long");
|
||||
return this.longAt(0);
|
||||
}
|
||||
|
||||
public long[] toLongArray() {
|
||||
Util.Validation.checkModLength(this.length(), 8, "creating an long array");
|
||||
return Util.Converter.toLongArray(this.internalArray(), this.byteOrder);
|
||||
}
|
||||
|
||||
public float toFloat() {
|
||||
Util.Validation.checkExactLength(this.length(), 4, "float");
|
||||
return this.internalBuffer().getFloat();
|
||||
}
|
||||
|
||||
public float[] toFloatArray() {
|
||||
Util.Validation.checkModLength(this.length(), 4, "creating an float array");
|
||||
return Util.Converter.toFloatArray(this.internalArray(), this.byteOrder);
|
||||
}
|
||||
|
||||
public double toDouble() {
|
||||
Util.Validation.checkExactLength(this.length(), 8, "double");
|
||||
return this.internalBuffer().getDouble();
|
||||
}
|
||||
|
||||
public double[] toDoubleArray() {
|
||||
Util.Validation.checkModLength(this.length(), 8, "creating an double array");
|
||||
return Util.Converter.toDoubleArray(this.internalArray(), this.byteOrder);
|
||||
}
|
||||
|
||||
public char[] toCharArray() {
|
||||
return this.toCharArray(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public char[] toCharArray(Charset charset) {
|
||||
return Util.Converter.byteToCharArray(this.internalArray(), charset, this.byteOrder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Bytes o) {
|
||||
return this.internalBuffer().compareTo(o.internalBuffer());
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || this.getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Bytes bytes = (Bytes)o;
|
||||
if (!Arrays.equals(this.byteArray, bytes.byteArray)) {
|
||||
return false;
|
||||
}
|
||||
return Objects.equals(this.byteOrder, bytes.byteOrder);
|
||||
}
|
||||
|
||||
public boolean equals(byte[] anotherArray) {
|
||||
return anotherArray != null && Arrays.equals(this.internalArray(), anotherArray);
|
||||
}
|
||||
|
||||
public boolean equalsConstantTime(byte[] anotherArray) {
|
||||
return anotherArray != null && Util.Byte.constantTimeEquals(this.internalArray(), anotherArray);
|
||||
}
|
||||
|
||||
public boolean equals(Byte[] anotherArray) {
|
||||
return Util.Obj.equals(this.internalArray(), anotherArray);
|
||||
}
|
||||
|
||||
public boolean equals(ByteBuffer buffer) {
|
||||
return buffer != null && this.byteOrder == buffer.order() && this.internalBuffer().equals(buffer);
|
||||
}
|
||||
|
||||
public boolean equalsContent(Bytes other) {
|
||||
return other != null && Arrays.equals(this.internalArray(), other.internalArray());
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
if (this.hashCodeCache == 0) {
|
||||
this.hashCodeCache = Util.Obj.hashCode(this.internalArray(), this.byteOrder());
|
||||
}
|
||||
return this.hashCodeCache;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return Util.Obj.toString(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Byte> iterator() {
|
||||
return new Util.BytesIterator(this.internalArray());
|
||||
}
|
||||
|
||||
private static class Factory
|
||||
implements BytesFactory {
|
||||
private Factory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bytes wrap(byte[] array, ByteOrder byteOrder) {
|
||||
return new Bytes(array, byteOrder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package at.favre.lib.bytes;
|
||||
|
||||
import at.favre.lib.bytes.Bytes;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
public interface BytesFactory {
|
||||
public Bytes wrap(byte[] var1, ByteOrder var2);
|
||||
}
|
||||
|
||||
@ -0,0 +1,285 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package at.favre.lib.bytes;
|
||||
|
||||
import at.favre.lib.bytes.Bytes;
|
||||
import at.favre.lib.bytes.Util;
|
||||
import java.nio.ByteOrder;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Objects;
|
||||
|
||||
public interface BytesTransformer {
|
||||
public byte[] transform(byte[] var1, boolean var2);
|
||||
|
||||
public boolean supportInPlaceTransformation();
|
||||
|
||||
public static class MessageDigestTransformer
|
||||
implements BytesTransformer {
|
||||
static final String ALGORITHM_MD5 = "MD5";
|
||||
static final String ALGORITHM_SHA_1 = "SHA-1";
|
||||
static final String ALGORITHM_SHA_256 = "SHA-256";
|
||||
private final MessageDigest messageDigest;
|
||||
|
||||
MessageDigestTransformer(String digestName) {
|
||||
try {
|
||||
this.messageDigest = MessageDigest.getInstance(digestName);
|
||||
}
|
||||
catch (NoSuchAlgorithmException e) {
|
||||
throw new IllegalArgumentException("could not get message digest algorithm " + digestName, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(byte[] currentArray, boolean inPlace) {
|
||||
this.messageDigest.update(currentArray);
|
||||
return this.messageDigest.digest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportInPlaceTransformation() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static class BitSwitchTransformer
|
||||
implements BytesTransformer {
|
||||
private final int position;
|
||||
private final Boolean newBitValue;
|
||||
|
||||
BitSwitchTransformer(int position, Boolean newBitValue) {
|
||||
this.position = position;
|
||||
this.newBitValue = newBitValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(byte[] currentArray, boolean inPlace) {
|
||||
byte[] out;
|
||||
byte[] byArray = out = inPlace ? currentArray : Bytes.from(currentArray).array();
|
||||
if (this.position < 0 || this.position >= 8 * currentArray.length) {
|
||||
throw new IllegalArgumentException("bit index " + this.position * 8 + " out of bounds");
|
||||
}
|
||||
int bytePosition = currentArray.length - 1 - this.position / 8;
|
||||
if (this.newBitValue == null) {
|
||||
int n = bytePosition;
|
||||
out[n] = (byte)(out[n] ^ 1 << this.position % 8);
|
||||
} else if (this.newBitValue.booleanValue()) {
|
||||
int n = bytePosition;
|
||||
out[n] = (byte)(out[n] | 1 << this.position % 8);
|
||||
} else {
|
||||
int n = bytePosition;
|
||||
out[n] = (byte)(out[n] & ~(1 << this.position % 8));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportInPlaceTransformation() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ResizeTransformer
|
||||
implements BytesTransformer {
|
||||
private final int newSize;
|
||||
private final Mode mode;
|
||||
|
||||
ResizeTransformer(int newSize, Mode mode) {
|
||||
this.newSize = newSize;
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(byte[] currentArray, boolean inPlace) {
|
||||
if (currentArray.length == this.newSize) {
|
||||
return currentArray;
|
||||
}
|
||||
if (this.newSize < 0) {
|
||||
throw new IllegalArgumentException("cannot resize to smaller than 0");
|
||||
}
|
||||
if (this.newSize == 0) {
|
||||
return new byte[0];
|
||||
}
|
||||
byte[] resizedArray = new byte[this.newSize];
|
||||
if (this.mode == Mode.RESIZE_KEEP_FROM_MAX_LENGTH) {
|
||||
if (this.newSize > currentArray.length) {
|
||||
System.arraycopy(currentArray, 0, resizedArray, Math.max(0, Math.abs(this.newSize - currentArray.length)), Math.min(this.newSize, currentArray.length));
|
||||
} else {
|
||||
System.arraycopy(currentArray, Math.max(0, Math.abs(this.newSize - currentArray.length)), resizedArray, Math.min(0, Math.abs(this.newSize - currentArray.length)), Math.min(this.newSize, currentArray.length));
|
||||
}
|
||||
} else {
|
||||
System.arraycopy(currentArray, 0, resizedArray, 0, Math.min(currentArray.length, resizedArray.length));
|
||||
}
|
||||
return resizedArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportInPlaceTransformation() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static enum Mode {
|
||||
RESIZE_KEEP_FROM_ZERO_INDEX,
|
||||
RESIZE_KEEP_FROM_MAX_LENGTH;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CopyTransformer
|
||||
implements BytesTransformer {
|
||||
final int offset;
|
||||
final int length;
|
||||
|
||||
CopyTransformer(int offset, int length) {
|
||||
this.offset = offset;
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(byte[] currentArray, boolean inPlace) {
|
||||
byte[] copy = new byte[this.length];
|
||||
System.arraycopy(currentArray, this.offset, copy, 0, copy.length);
|
||||
return copy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportInPlaceTransformation() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ReverseTransformer
|
||||
implements BytesTransformer {
|
||||
@Override
|
||||
public byte[] transform(byte[] currentArray, boolean inPlace) {
|
||||
byte[] out = inPlace ? currentArray : Bytes.from(currentArray).array();
|
||||
Util.Byte.reverse(out, 0, out.length);
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportInPlaceTransformation() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ConcatTransformer
|
||||
implements BytesTransformer {
|
||||
private final byte[] secondArray;
|
||||
|
||||
ConcatTransformer(byte[] secondArrays) {
|
||||
this.secondArray = Objects.requireNonNull(secondArrays, "the second byte array must not be null");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(byte[] currentArray, boolean inPlace) {
|
||||
return Util.Byte.concat(currentArray, this.secondArray);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportInPlaceTransformation() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ShiftTransformer
|
||||
implements BytesTransformer {
|
||||
private final int shiftCount;
|
||||
private final Type type;
|
||||
private final ByteOrder byteOrder;
|
||||
|
||||
ShiftTransformer(int shiftCount, Type type, ByteOrder byteOrder) {
|
||||
this.shiftCount = shiftCount;
|
||||
this.type = Objects.requireNonNull(type, "passed shift type must not be null");
|
||||
this.byteOrder = Objects.requireNonNull(byteOrder, "passed byteOrder type must not be null");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(byte[] currentArray, boolean inPlace) {
|
||||
byte[] out = inPlace ? currentArray : Bytes.from(currentArray).array();
|
||||
switch (this.type) {
|
||||
case RIGHT_SHIFT: {
|
||||
return Util.Byte.shiftRight(out, this.shiftCount, this.byteOrder);
|
||||
}
|
||||
}
|
||||
return Util.Byte.shiftLeft(out, this.shiftCount, this.byteOrder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportInPlaceTransformation() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static enum Type {
|
||||
LEFT_SHIFT,
|
||||
RIGHT_SHIFT;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static final class NegateTransformer
|
||||
implements BytesTransformer {
|
||||
@Override
|
||||
public byte[] transform(byte[] currentArray, boolean inPlace) {
|
||||
byte[] out = inPlace ? currentArray : Bytes.from(currentArray).array();
|
||||
for (int i = 0; i < out.length; ++i) {
|
||||
out[i] = ~out[i];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportInPlaceTransformation() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class BitWiseOperatorTransformer
|
||||
implements BytesTransformer {
|
||||
private final byte[] secondArray;
|
||||
private final Mode mode;
|
||||
|
||||
BitWiseOperatorTransformer(byte[] secondArray, Mode mode) {
|
||||
this.secondArray = Objects.requireNonNull(secondArray, "the second byte array must not be null");
|
||||
this.mode = Objects.requireNonNull(mode, "passed bitwise mode must not be null");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(byte[] currentArray, boolean inPlace) {
|
||||
if (currentArray.length != this.secondArray.length) {
|
||||
throw new IllegalArgumentException("all byte array must be of same length doing bit wise operation");
|
||||
}
|
||||
byte[] out = inPlace ? currentArray : new byte[currentArray.length];
|
||||
block4: for (int i = 0; i < currentArray.length; ++i) {
|
||||
switch (this.mode) {
|
||||
case AND: {
|
||||
out[i] = (byte)(currentArray[i] & this.secondArray[i]);
|
||||
continue block4;
|
||||
}
|
||||
case XOR: {
|
||||
out[i] = (byte)(currentArray[i] ^ this.secondArray[i]);
|
||||
continue block4;
|
||||
}
|
||||
default: {
|
||||
out[i] = (byte)(currentArray[i] | this.secondArray[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportInPlaceTransformation() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static enum Mode {
|
||||
AND,
|
||||
OR,
|
||||
XOR;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,266 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package at.favre.lib.bytes;
|
||||
|
||||
import at.favre.lib.bytes.Bytes;
|
||||
import at.favre.lib.bytes.BytesTransformer;
|
||||
import at.favre.lib.bytes.Util;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.zip.CRC32;
|
||||
import java.util.zip.Checksum;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
public final class BytesTransformers {
|
||||
private BytesTransformers() {
|
||||
}
|
||||
|
||||
public static BytesTransformer shuffle() {
|
||||
return new ShuffleTransformer(new SecureRandom());
|
||||
}
|
||||
|
||||
public static BytesTransformer shuffle(Random random) {
|
||||
return new ShuffleTransformer(random);
|
||||
}
|
||||
|
||||
public static BytesTransformer sort() {
|
||||
return new SortTransformer();
|
||||
}
|
||||
|
||||
public static BytesTransformer sortUnsigned() {
|
||||
return new SortTransformer(new SortTransformer.UnsignedByteComparator());
|
||||
}
|
||||
|
||||
public static BytesTransformer sort(Comparator<Byte> comparator) {
|
||||
return new SortTransformer(comparator);
|
||||
}
|
||||
|
||||
public static BytesTransformer checksumAppendCrc32() {
|
||||
return new ChecksumTransformer(new CRC32(), ChecksumTransformer.Mode.APPEND, 4);
|
||||
}
|
||||
|
||||
public static BytesTransformer checksumCrc32() {
|
||||
return new ChecksumTransformer(new CRC32(), ChecksumTransformer.Mode.TRANSFORM, 4);
|
||||
}
|
||||
|
||||
public static BytesTransformer checksum(Checksum checksum, ChecksumTransformer.Mode mode, int checksumLengthByte) {
|
||||
return new ChecksumTransformer(checksum, mode, checksumLengthByte);
|
||||
}
|
||||
|
||||
public static BytesTransformer compressGzip() {
|
||||
return new GzipCompressor(true);
|
||||
}
|
||||
|
||||
public static BytesTransformer decompressGzip() {
|
||||
return new GzipCompressor(false);
|
||||
}
|
||||
|
||||
public static BytesTransformer hmacSha1(byte[] key) {
|
||||
return new HmacTransformer(key, "HmacSHA1");
|
||||
}
|
||||
|
||||
public static BytesTransformer hmacSha256(byte[] key) {
|
||||
return new HmacTransformer(key, "HmacSHA256");
|
||||
}
|
||||
|
||||
public static BytesTransformer hmac(byte[] key, String algorithmName) {
|
||||
return new HmacTransformer(key, algorithmName);
|
||||
}
|
||||
|
||||
public static final class HmacTransformer
|
||||
implements BytesTransformer {
|
||||
static final String HMAC_SHA1 = "HmacSHA1";
|
||||
static final String HMAC_SHA256 = "HmacSHA256";
|
||||
private final byte[] secretKey;
|
||||
private final String macAlgorithmName;
|
||||
|
||||
HmacTransformer(byte[] secretKey, String macAlgorithmName) {
|
||||
this.macAlgorithmName = macAlgorithmName;
|
||||
this.secretKey = secretKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(byte[] currentArray, boolean inPlace) {
|
||||
try {
|
||||
Mac mac = Mac.getInstance(this.macAlgorithmName);
|
||||
mac.init(new SecretKeySpec(this.secretKey, this.macAlgorithmName));
|
||||
return mac.doFinal(currentArray);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportInPlaceTransformation() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class GzipCompressor
|
||||
implements BytesTransformer {
|
||||
private final boolean compress;
|
||||
|
||||
GzipCompressor(boolean compress) {
|
||||
this.compress = compress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(byte[] currentArray, boolean inPlace) {
|
||||
return this.compress ? this.compress(currentArray) : this.decompress(currentArray);
|
||||
}
|
||||
|
||||
/*
|
||||
* Enabled aggressive block sorting
|
||||
* Enabled unnecessary exception pruning
|
||||
* Enabled aggressive exception aggregation
|
||||
*/
|
||||
private byte[] decompress(byte[] compressedContent) {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(Math.max(32, compressedContent.length / 2));
|
||||
try (GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(compressedContent));){
|
||||
int len;
|
||||
byte[] buffer = new byte[4096];
|
||||
while ((len = gzipInputStream.read(buffer)) > 0) {
|
||||
bos.write(buffer, 0, len);
|
||||
}
|
||||
byte[] byArray = bos.toByteArray();
|
||||
return byArray;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException("could not decompress gzip", e);
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] compress(byte[] content) {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(content.length);
|
||||
try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(bos);){
|
||||
gzipOutputStream.write(content);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException("could not compress gzip", e);
|
||||
}
|
||||
return bos.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportInPlaceTransformation() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ChecksumTransformer
|
||||
implements BytesTransformer {
|
||||
private final Checksum checksum;
|
||||
private final Mode mode;
|
||||
private final int checksumLengthByte;
|
||||
|
||||
ChecksumTransformer(Checksum checksum, Mode mode, int checksumLengthByte) {
|
||||
if (checksumLengthByte <= 0 || checksumLengthByte > 8) {
|
||||
throw new IllegalArgumentException("checksum length must be between 1 and 8 bytes");
|
||||
}
|
||||
Objects.requireNonNull(checksum, "checksum instance must not be null");
|
||||
this.checksum = checksum;
|
||||
this.mode = mode;
|
||||
this.checksumLengthByte = checksumLengthByte;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(byte[] currentArray, boolean inPlace) {
|
||||
this.checksum.update(currentArray, 0, currentArray.length);
|
||||
byte[] checksumBytes = Bytes.from(this.checksum.getValue()).resize(this.checksumLengthByte).array();
|
||||
if (this.mode == Mode.TRANSFORM) {
|
||||
return checksumBytes;
|
||||
}
|
||||
return Bytes.from(currentArray, checksumBytes).array();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportInPlaceTransformation() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static enum Mode {
|
||||
APPEND,
|
||||
TRANSFORM;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static final class SortTransformer
|
||||
implements BytesTransformer {
|
||||
private final Comparator comparator;
|
||||
|
||||
SortTransformer() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
SortTransformer(Comparator<Byte> comparator) {
|
||||
this.comparator = comparator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(byte[] currentArray, boolean inPlace) {
|
||||
if (this.comparator == null) {
|
||||
byte[] out = inPlace ? currentArray : Bytes.from(currentArray).array();
|
||||
Arrays.sort(out);
|
||||
return out;
|
||||
}
|
||||
Byte[] boxedArray = Bytes.wrap(currentArray).toBoxedArray();
|
||||
Arrays.sort(boxedArray, this.comparator);
|
||||
return Bytes.from(boxedArray).array();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportInPlaceTransformation() {
|
||||
return this.comparator == null;
|
||||
}
|
||||
|
||||
static final class UnsignedByteComparator
|
||||
implements Comparator<Byte> {
|
||||
UnsignedByteComparator() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(Byte o1, Byte o2) {
|
||||
int byteB;
|
||||
int byteA = o1 & 0xFF;
|
||||
if (byteA == (byteB = o2 & 0xFF)) {
|
||||
return 0;
|
||||
}
|
||||
return byteA < byteB ? -1 : 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ShuffleTransformer
|
||||
implements BytesTransformer {
|
||||
private final Random random;
|
||||
|
||||
ShuffleTransformer(Random random) {
|
||||
Objects.requireNonNull(random, "passed random must not be null");
|
||||
this.random = random;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(byte[] currentArray, boolean inPlace) {
|
||||
byte[] out = inPlace ? currentArray : Bytes.from(currentArray).array();
|
||||
Util.Byte.shuffle(out, this.random);
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportInPlaceTransformation() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package at.favre.lib.bytes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface BytesValidator {
|
||||
public boolean validate(byte[] var1);
|
||||
|
||||
public static final class Logical
|
||||
implements BytesValidator {
|
||||
private final List<BytesValidator> validatorList;
|
||||
private final Operator operator;
|
||||
|
||||
public Logical(List<BytesValidator> validatorList, Operator operator) {
|
||||
if (validatorList.isEmpty()) {
|
||||
throw new IllegalArgumentException("must contain at least 1 element");
|
||||
}
|
||||
if (operator == Operator.NOT && validatorList.size() != 1) {
|
||||
throw new IllegalArgumentException("not operator can only be applied to single element");
|
||||
}
|
||||
this.validatorList = validatorList;
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validate(byte[] byteArrayToValidate) {
|
||||
if (this.operator == Operator.NOT) {
|
||||
return !this.validatorList.get(0).validate(byteArrayToValidate);
|
||||
}
|
||||
boolean bool = this.operator != Operator.OR;
|
||||
block3: for (BytesValidator bytesValidator : this.validatorList) {
|
||||
switch (this.operator) {
|
||||
case AND: {
|
||||
bool &= bytesValidator.validate(byteArrayToValidate);
|
||||
continue block3;
|
||||
}
|
||||
}
|
||||
bool |= bytesValidator.validate(byteArrayToValidate);
|
||||
}
|
||||
return bool;
|
||||
}
|
||||
|
||||
static enum Operator {
|
||||
OR,
|
||||
AND,
|
||||
NOT;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static final class PrePostFix
|
||||
implements BytesValidator {
|
||||
private final byte[] pfix;
|
||||
private final boolean startsWith;
|
||||
|
||||
public PrePostFix(boolean startsWith, byte ... pfix) {
|
||||
this.pfix = pfix;
|
||||
this.startsWith = startsWith;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validate(byte[] byteArrayToValidate) {
|
||||
if (this.pfix.length > byteArrayToValidate.length) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < this.pfix.length; ++i) {
|
||||
if (this.startsWith && this.pfix[i] != byteArrayToValidate[i]) {
|
||||
return false;
|
||||
}
|
||||
if (this.startsWith || this.pfix[i] == byteArrayToValidate[byteArrayToValidate.length - this.pfix.length + i]) continue;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class IdenticalContent
|
||||
implements BytesValidator {
|
||||
private final byte refByte;
|
||||
private final Mode mode;
|
||||
|
||||
IdenticalContent(byte refByte, Mode mode) {
|
||||
this.refByte = refByte;
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validate(byte[] byteArrayToValidate) {
|
||||
for (byte b : byteArrayToValidate) {
|
||||
if (this.mode == Mode.NONE_OF && b == this.refByte) {
|
||||
return false;
|
||||
}
|
||||
if (this.mode == Mode.ONLY_OF && b != this.refByte) {
|
||||
return false;
|
||||
}
|
||||
if (this.mode != Mode.NOT_ONLY_OF || b == this.refByte) continue;
|
||||
return true;
|
||||
}
|
||||
return this.mode == Mode.NONE_OF || this.mode == Mode.ONLY_OF;
|
||||
}
|
||||
|
||||
static enum Mode {
|
||||
ONLY_OF,
|
||||
NONE_OF,
|
||||
NOT_ONLY_OF;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Length
|
||||
implements BytesValidator {
|
||||
private final int refLength;
|
||||
private final Mode mode;
|
||||
|
||||
public Length(int refLength, Mode mode) {
|
||||
this.refLength = refLength;
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validate(byte[] byteArrayToValidate) {
|
||||
switch (this.mode) {
|
||||
case GREATER_OR_EQ_THAN: {
|
||||
return byteArrayToValidate.length >= this.refLength;
|
||||
}
|
||||
case SMALLER_OR_EQ_THAN: {
|
||||
return byteArrayToValidate.length <= this.refLength;
|
||||
}
|
||||
}
|
||||
return byteArrayToValidate.length == this.refLength;
|
||||
}
|
||||
|
||||
static enum Mode {
|
||||
SMALLER_OR_EQ_THAN,
|
||||
GREATER_OR_EQ_THAN,
|
||||
EXACT;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package at.favre.lib.bytes;
|
||||
|
||||
import at.favre.lib.bytes.BytesValidator;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
public final class BytesValidators {
|
||||
private BytesValidators() {
|
||||
}
|
||||
|
||||
public static BytesValidator atLeast(int byteLength) {
|
||||
return new BytesValidator.Length(byteLength, BytesValidator.Length.Mode.GREATER_OR_EQ_THAN);
|
||||
}
|
||||
|
||||
public static BytesValidator atMost(int byteLength) {
|
||||
return new BytesValidator.Length(byteLength, BytesValidator.Length.Mode.SMALLER_OR_EQ_THAN);
|
||||
}
|
||||
|
||||
public static BytesValidator exactLength(int byteLength) {
|
||||
return new BytesValidator.Length(byteLength, BytesValidator.Length.Mode.EXACT);
|
||||
}
|
||||
|
||||
public static BytesValidator onlyOf(byte refByte) {
|
||||
return new BytesValidator.IdenticalContent(refByte, BytesValidator.IdenticalContent.Mode.ONLY_OF);
|
||||
}
|
||||
|
||||
public static BytesValidator notOnlyOf(byte refByte) {
|
||||
return new BytesValidator.IdenticalContent(refByte, BytesValidator.IdenticalContent.Mode.NOT_ONLY_OF);
|
||||
}
|
||||
|
||||
public static BytesValidator startsWith(byte ... startsWithBytes) {
|
||||
return new BytesValidator.PrePostFix(true, startsWithBytes);
|
||||
}
|
||||
|
||||
public static BytesValidator endsWith(byte ... endsWithBytes) {
|
||||
return new BytesValidator.PrePostFix(false, endsWithBytes);
|
||||
}
|
||||
|
||||
public static BytesValidator noneOf(byte refByte) {
|
||||
return new BytesValidator.IdenticalContent(refByte, BytesValidator.IdenticalContent.Mode.NONE_OF);
|
||||
}
|
||||
|
||||
public static BytesValidator or(BytesValidator ... validators) {
|
||||
return new BytesValidator.Logical(Arrays.asList(validators), BytesValidator.Logical.Operator.OR);
|
||||
}
|
||||
|
||||
public static BytesValidator and(BytesValidator ... validators) {
|
||||
return new BytesValidator.Logical(Arrays.asList(validators), BytesValidator.Logical.Operator.AND);
|
||||
}
|
||||
|
||||
public static BytesValidator not(BytesValidator validator) {
|
||||
return new BytesValidator.Logical(Collections.singletonList(validator), BytesValidator.Logical.Operator.NOT);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package at.favre.lib.bytes;
|
||||
|
||||
import at.favre.lib.bytes.Bytes;
|
||||
import at.favre.lib.bytes.BytesFactory;
|
||||
import at.favre.lib.bytes.Util;
|
||||
import java.nio.ByteOrder;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class MutableBytes
|
||||
extends Bytes
|
||||
implements AutoCloseable {
|
||||
MutableBytes(byte[] byteArray, ByteOrder byteOrder) {
|
||||
super(byteArray, byteOrder, new Factory());
|
||||
}
|
||||
|
||||
public static MutableBytes allocate(int length) {
|
||||
return MutableBytes.allocate(length, (byte)0);
|
||||
}
|
||||
|
||||
public static MutableBytes allocate(int length, byte defaultValue) {
|
||||
return Bytes.allocate(length, defaultValue).mutable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMutable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public MutableBytes overwrite(byte[] newArray) {
|
||||
return this.overwrite(newArray, 0);
|
||||
}
|
||||
|
||||
public MutableBytes overwrite(Bytes newBytes) {
|
||||
return this.overwrite(newBytes, 0);
|
||||
}
|
||||
|
||||
public MutableBytes overwrite(byte[] newArray, int offsetInternalArray) {
|
||||
Objects.requireNonNull(newArray, "must provide non-null array as source");
|
||||
System.arraycopy(newArray, 0, this.internalArray(), offsetInternalArray, newArray.length);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MutableBytes overwrite(Bytes newBytes, int offsetInternalArray) {
|
||||
return this.overwrite(Objects.requireNonNull(newBytes, "must provide non-null array as source").array(), offsetInternalArray);
|
||||
}
|
||||
|
||||
public MutableBytes setByteAt(int index, byte newByte) {
|
||||
this.internalArray()[index] = newByte;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MutableBytes wipe() {
|
||||
return this.fill((byte)0);
|
||||
}
|
||||
|
||||
public MutableBytes fill(byte fillByte) {
|
||||
Arrays.fill(this.internalArray(), fillByte);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MutableBytes secureWipe() {
|
||||
return this.secureWipe(new SecureRandom());
|
||||
}
|
||||
|
||||
public MutableBytes secureWipe(SecureRandom random) {
|
||||
Objects.requireNonNull(random, "random param must not be null");
|
||||
if (this.length() > 0) {
|
||||
random.nextBytes(this.internalArray());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Bytes immutable() {
|
||||
return Bytes.wrap(this.internalArray(), this.byteOrder());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Util.Obj.hashCode(this.internalArray(), this.byteOrder());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return super.equals(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
this.secureWipe();
|
||||
}
|
||||
|
||||
private static class Factory
|
||||
implements BytesFactory {
|
||||
private Factory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bytes wrap(byte[] array, ByteOrder byteOrder) {
|
||||
return new MutableBytes(array, byteOrder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package at.favre.lib.bytes;
|
||||
|
||||
import at.favre.lib.bytes.Bytes;
|
||||
import at.favre.lib.bytes.BytesFactory;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.ReadOnlyBufferException;
|
||||
|
||||
public final class ReadOnlyBytes
|
||||
extends Bytes {
|
||||
ReadOnlyBytes(byte[] byteArray, ByteOrder byteOrder) {
|
||||
super(byteArray, byteOrder, new Factory());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadOnly() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] array() {
|
||||
throw new ReadOnlyBufferException();
|
||||
}
|
||||
|
||||
private static class Factory
|
||||
implements BytesFactory {
|
||||
private Factory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bytes wrap(byte[] array, ByteOrder byteOrder) {
|
||||
return new ReadOnlyBytes(array, byteOrder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,557 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package at.favre.lib.bytes;
|
||||
|
||||
import at.favre.lib.bytes.Bytes;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInput;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.DoubleBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.LongBuffer;
|
||||
import java.nio.charset.CharacterCodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
final class Util {
|
||||
private Util() {
|
||||
}
|
||||
|
||||
static final class BytesIterator
|
||||
implements Iterator<java.lang.Byte> {
|
||||
private final byte[] array;
|
||||
private int cursor = 0;
|
||||
|
||||
BytesIterator(byte[] array) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return this.cursor != this.array.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.lang.Byte next() {
|
||||
try {
|
||||
int i = this.cursor;
|
||||
java.lang.Byte next = this.array[i];
|
||||
this.cursor = i + 1;
|
||||
return next;
|
||||
}
|
||||
catch (IndexOutOfBoundsException e) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException("The Bytes iterator does not support removing");
|
||||
}
|
||||
}
|
||||
|
||||
static final class File {
|
||||
private static final int BUF_SIZE = 4096;
|
||||
|
||||
private File() {
|
||||
}
|
||||
|
||||
static byte[] readFromStream(InputStream inputStream, int maxLengthToRead) {
|
||||
boolean readWholeStream = maxLengthToRead == -1;
|
||||
try {
|
||||
int r;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(readWholeStream ? 32 : maxLengthToRead);
|
||||
byte[] buf = new byte[]{};
|
||||
for (int remaining = maxLengthToRead; readWholeStream || remaining > 0; remaining -= r) {
|
||||
int bufSize = Math.min(4096, readWholeStream ? 4096 : remaining);
|
||||
if (buf.length != bufSize) {
|
||||
buf = new byte[bufSize];
|
||||
}
|
||||
if ((r = inputStream.read(buf)) == -1) break;
|
||||
out.write(buf, 0, r);
|
||||
}
|
||||
return out.toByteArray();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException("could not read from input stream", e);
|
||||
}
|
||||
}
|
||||
|
||||
static byte[] readFromDataInput(DataInput dataInput, int length) {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(length);
|
||||
try {
|
||||
int remaining = length;
|
||||
for (int i = 0; i < length; ++i) {
|
||||
byte[] buf = new byte[Math.min(remaining, 4096)];
|
||||
dataInput.readFully(buf);
|
||||
out.write(buf);
|
||||
remaining -= buf.length;
|
||||
}
|
||||
return out.toByteArray();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException("could not read from data input", e);
|
||||
}
|
||||
}
|
||||
|
||||
static byte[] readFromFile(java.io.File file) {
|
||||
Validation.checkFileExists(file);
|
||||
try {
|
||||
return Files.readAllBytes(file.toPath());
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalStateException("could not read from file", e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Enabled aggressive block sorting
|
||||
* Enabled unnecessary exception pruning
|
||||
* Enabled aggressive exception aggregation
|
||||
*/
|
||||
static byte[] readFromFile(java.io.File file, int offset, int length) {
|
||||
Validation.checkFileExists(file);
|
||||
try (RandomAccessFile raf = new RandomAccessFile(file, "r");){
|
||||
raf.seek(offset);
|
||||
byte[] byArray = File.readFromDataInput(raf, length);
|
||||
return byArray;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException("could not read from random access file", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static final class Validation {
|
||||
private Validation() {
|
||||
}
|
||||
|
||||
static void checkIndexBounds(int length, int index, int primitiveLength, String type) {
|
||||
if (index < 0 || index + primitiveLength > length) {
|
||||
throw new IndexOutOfBoundsException("cannot get " + type + " from index out of bounds: " + index);
|
||||
}
|
||||
}
|
||||
|
||||
static void checkExactLength(int length, int expectedLength, String type) {
|
||||
if (length != expectedLength) {
|
||||
throw new IllegalArgumentException("cannot convert to " + type + " if length != " + expectedLength + " bytes (was " + length + ")");
|
||||
}
|
||||
}
|
||||
|
||||
static void checkModLength(int length, int modFactor, String errorSubject) {
|
||||
if (length % modFactor != 0) {
|
||||
throw new IllegalArgumentException("Illegal length for " + errorSubject + ". Byte array length must be multiple of " + modFactor + ", length was " + length);
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkFileExists(java.io.File file) {
|
||||
if (file == null || !file.exists() || !file.isFile()) {
|
||||
throw new IllegalArgumentException("file must not be null, has to exist and must be a file (not a directory) " + file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static final class Obj {
|
||||
private Obj() {
|
||||
}
|
||||
|
||||
static boolean equals(byte[] obj, java.lang.Byte[] anotherArray) {
|
||||
if (anotherArray == null) {
|
||||
return false;
|
||||
}
|
||||
if (obj.length != anotherArray.length) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < obj.length; ++i) {
|
||||
if (anotherArray[i] != null && obj[i] == anotherArray[i]) continue;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static int hashCode(byte[] byteArray, ByteOrder byteOrder) {
|
||||
int result = Arrays.hashCode(byteArray);
|
||||
result = 31 * result + (byteOrder != null ? byteOrder.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
static String toString(Bytes bytes) {
|
||||
String preview = bytes.isEmpty() ? "" : (bytes.length() > 8 ? "(0x" + bytes.copy(0, 4).encodeHex() + "..." + bytes.copy(bytes.length() - 4, 4).encodeHex() + ")" : "(0x" + bytes.encodeHex() + ")");
|
||||
return bytes.length() + " " + (bytes.length() == 1 ? "byte" : "bytes") + " " + preview;
|
||||
}
|
||||
}
|
||||
|
||||
static final class Converter {
|
||||
private Converter() {
|
||||
}
|
||||
|
||||
static byte[] toArray(Collection<java.lang.Byte> collection) {
|
||||
int len = collection.size();
|
||||
byte[] array = new byte[len];
|
||||
int i = 0;
|
||||
for (java.lang.Byte b : collection) {
|
||||
array[i] = b;
|
||||
++i;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
static java.lang.Byte[] toBoxedArray(byte[] array) {
|
||||
java.lang.Byte[] objectArray = new java.lang.Byte[array.length];
|
||||
for (int i = 0; i < array.length; ++i) {
|
||||
objectArray[i] = array[i];
|
||||
}
|
||||
return objectArray;
|
||||
}
|
||||
|
||||
static List<java.lang.Byte> toList(byte[] array) {
|
||||
ArrayList<java.lang.Byte> list = new ArrayList<java.lang.Byte>(array.length);
|
||||
for (byte b : array) {
|
||||
list.add(b);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
static byte[] toPrimitiveArray(java.lang.Byte[] objectArray) {
|
||||
byte[] primitivesArray = new byte[objectArray.length];
|
||||
for (int i = 0; i < objectArray.length; ++i) {
|
||||
primitivesArray[i] = objectArray[i];
|
||||
}
|
||||
return primitivesArray;
|
||||
}
|
||||
|
||||
static byte[] toByteArray(int[] intArray) {
|
||||
byte[] primitivesArray = new byte[intArray.length * 4];
|
||||
ByteBuffer buffer = ByteBuffer.allocate(4);
|
||||
for (int i = 0; i < intArray.length; ++i) {
|
||||
buffer.clear();
|
||||
byte[] intBytes = buffer.putInt(intArray[i]).array();
|
||||
System.arraycopy(intBytes, 0, primitivesArray, i * 4, intBytes.length);
|
||||
}
|
||||
return primitivesArray;
|
||||
}
|
||||
|
||||
static byte[] toByteArray(float[] floatArray) {
|
||||
byte[] primitivesArray = new byte[floatArray.length * 4];
|
||||
ByteBuffer buffer = ByteBuffer.allocate(4);
|
||||
for (int i = 0; i < floatArray.length; ++i) {
|
||||
buffer.clear();
|
||||
byte[] floatBytes = buffer.putFloat(floatArray[i]).array();
|
||||
System.arraycopy(floatBytes, 0, primitivesArray, i * 4, floatBytes.length);
|
||||
}
|
||||
return primitivesArray;
|
||||
}
|
||||
|
||||
static byte[] toByteArray(long[] longArray) {
|
||||
byte[] primitivesArray = new byte[longArray.length * 8];
|
||||
ByteBuffer buffer = ByteBuffer.allocate(8);
|
||||
for (int i = 0; i < longArray.length; ++i) {
|
||||
buffer.clear();
|
||||
byte[] longBytes = buffer.putLong(longArray[i]).array();
|
||||
System.arraycopy(longBytes, 0, primitivesArray, i * 8, longBytes.length);
|
||||
}
|
||||
return primitivesArray;
|
||||
}
|
||||
|
||||
static byte[] toByteArray(double[] doubleArray) {
|
||||
byte[] primitivesArray = new byte[doubleArray.length * 8];
|
||||
ByteBuffer buffer = ByteBuffer.allocate(8);
|
||||
for (int i = 0; i < doubleArray.length; ++i) {
|
||||
buffer.clear();
|
||||
byte[] doubleBytes = buffer.putDouble(doubleArray[i]).array();
|
||||
System.arraycopy(doubleBytes, 0, primitivesArray, i * 8, doubleBytes.length);
|
||||
}
|
||||
return primitivesArray;
|
||||
}
|
||||
|
||||
static byte[] charToByteArray(char[] charArray, Charset charset, int offset, int length) {
|
||||
ByteBuffer bb;
|
||||
if (offset < 0 || offset > charArray.length) {
|
||||
throw new IllegalArgumentException("offset must be gt 0 and smaller than array length");
|
||||
}
|
||||
if (length < 0 || length > charArray.length) {
|
||||
throw new IllegalArgumentException("length must be at least 1 and less than array length");
|
||||
}
|
||||
if (offset + length > charArray.length) {
|
||||
throw new IllegalArgumentException("length + offset must be smaller than array length");
|
||||
}
|
||||
if (length == 0) {
|
||||
return new byte[0];
|
||||
}
|
||||
CharBuffer charBuffer = CharBuffer.wrap(charArray);
|
||||
if (offset != 0 || length != charBuffer.remaining()) {
|
||||
charBuffer = charBuffer.subSequence(offset, offset + length);
|
||||
}
|
||||
if ((bb = charset.encode(charBuffer)).capacity() != bb.limit()) {
|
||||
byte[] bytes = new byte[bb.remaining()];
|
||||
bb.get(bytes);
|
||||
return bytes;
|
||||
}
|
||||
return bb.array();
|
||||
}
|
||||
|
||||
static char[] byteToCharArray(byte[] bytes, Charset charset, ByteOrder byteOrder) {
|
||||
Objects.requireNonNull(bytes, "bytes must not be null");
|
||||
Objects.requireNonNull(charset, "charset must not be null");
|
||||
try {
|
||||
CharBuffer charBuffer = charset.newDecoder().decode(ByteBuffer.wrap(bytes).order(byteOrder));
|
||||
if (charBuffer.capacity() != charBuffer.limit()) {
|
||||
char[] compacted = new char[charBuffer.remaining()];
|
||||
charBuffer.get(compacted);
|
||||
return compacted;
|
||||
}
|
||||
return charBuffer.array();
|
||||
}
|
||||
catch (CharacterCodingException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
static int[] toIntArray(byte[] bytes, ByteOrder byteOrder) {
|
||||
IntBuffer buffer = ByteBuffer.wrap(bytes).order(byteOrder).asIntBuffer();
|
||||
int[] array = new int[buffer.remaining()];
|
||||
buffer.get(array);
|
||||
return array;
|
||||
}
|
||||
|
||||
static long[] toLongArray(byte[] bytes, ByteOrder byteOrder) {
|
||||
LongBuffer buffer = ByteBuffer.wrap(bytes).order(byteOrder).asLongBuffer();
|
||||
long[] array = new long[buffer.remaining()];
|
||||
buffer.get(array);
|
||||
return array;
|
||||
}
|
||||
|
||||
static float[] toFloatArray(byte[] bytes, ByteOrder byteOrder) {
|
||||
FloatBuffer buffer = ByteBuffer.wrap(bytes).order(byteOrder).asFloatBuffer();
|
||||
float[] array = new float[buffer.remaining()];
|
||||
buffer.get(array);
|
||||
return array;
|
||||
}
|
||||
|
||||
static double[] toDoubleArray(byte[] bytes, ByteOrder byteOrder) {
|
||||
DoubleBuffer buffer = ByteBuffer.wrap(bytes).order(byteOrder).asDoubleBuffer();
|
||||
double[] array = new double[buffer.remaining()];
|
||||
buffer.get(array);
|
||||
return array;
|
||||
}
|
||||
|
||||
static ByteBuffer toBytesFromUUID(UUID uuid) {
|
||||
ByteBuffer bb = ByteBuffer.allocate(16);
|
||||
bb.putLong(uuid.getMostSignificantBits());
|
||||
bb.putLong(uuid.getLeastSignificantBits());
|
||||
return bb;
|
||||
}
|
||||
}
|
||||
|
||||
static final class Byte {
|
||||
private Byte() {
|
||||
}
|
||||
|
||||
static byte[] concat(byte[] ... arrays) {
|
||||
int length = 0;
|
||||
for (byte[] array : arrays) {
|
||||
length += array.length;
|
||||
}
|
||||
byte[] result = new byte[length];
|
||||
int pos = 0;
|
||||
for (byte[] array : arrays) {
|
||||
System.arraycopy(array, 0, result, pos, array.length);
|
||||
pos += array.length;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static byte[] concatVararg(byte firstByte, byte[] moreBytes) {
|
||||
if (moreBytes == null) {
|
||||
return new byte[]{firstByte};
|
||||
}
|
||||
return Byte.concat({firstByte}, moreBytes);
|
||||
}
|
||||
|
||||
static int indexOf(byte[] array, byte[] target, int start, int end) {
|
||||
Objects.requireNonNull(array, "array must not be null");
|
||||
Objects.requireNonNull(target, "target must not be null");
|
||||
if (target.length == 0 || start < 0) {
|
||||
return -1;
|
||||
}
|
||||
block0: for (int i = start; i < Math.min(end, array.length - target.length + 1); ++i) {
|
||||
for (int j = 0; j < target.length; ++j) {
|
||||
if (array[i + j] != target[j]) continue block0;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int lastIndexOf(byte[] array, byte target, int start, int end) {
|
||||
for (int i = end - 1; i >= start; --i) {
|
||||
if (array[i] != target) continue;
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int countByte(byte[] array, byte target) {
|
||||
int count = 0;
|
||||
for (byte b : array) {
|
||||
if (b != target) continue;
|
||||
++count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static int countByteArray(byte[] array, byte[] pattern) {
|
||||
Objects.requireNonNull(pattern, "pattern must not be null");
|
||||
if (pattern.length == 0 || array.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
int count = 0;
|
||||
block0: for (int i = 0; i < array.length - pattern.length + 1; ++i) {
|
||||
for (int j = 0; j < pattern.length; ++j) {
|
||||
if (array[i + j] != pattern[j]) continue block0;
|
||||
}
|
||||
++count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static void shuffle(byte[] array, Random random) {
|
||||
for (int i = array.length - 1; i > 0; --i) {
|
||||
int index = random.nextInt(i + 1);
|
||||
byte a = array[index];
|
||||
array[index] = array[i];
|
||||
array[i] = a;
|
||||
}
|
||||
}
|
||||
|
||||
static void reverse(byte[] array, int fromIndex, int toIndex) {
|
||||
Objects.requireNonNull(array);
|
||||
int i = fromIndex;
|
||||
for (int j = toIndex - 1; i < j; ++i, --j) {
|
||||
byte tmp = array[i];
|
||||
array[i] = array[j];
|
||||
array[j] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
static byte[] shiftLeft(byte[] byteArray, int shiftBitCount, ByteOrder byteOrder) {
|
||||
int shiftMod = shiftBitCount % 8;
|
||||
byte carryMask = (byte)((1 << shiftMod) - 1);
|
||||
int offsetBytes = shiftBitCount / 8;
|
||||
if (byteOrder == ByteOrder.BIG_ENDIAN) {
|
||||
for (int i = 0; i < byteArray.length; ++i) {
|
||||
int sourceIndex = i + offsetBytes;
|
||||
if (sourceIndex >= byteArray.length) {
|
||||
byteArray[i] = 0;
|
||||
continue;
|
||||
}
|
||||
byte src = byteArray[sourceIndex];
|
||||
byte dst = (byte)(src << shiftMod);
|
||||
if (sourceIndex + 1 < byteArray.length) {
|
||||
dst = (byte)(dst | byteArray[sourceIndex + 1] >>> 8 - shiftMod & carryMask);
|
||||
}
|
||||
byteArray[i] = dst;
|
||||
}
|
||||
} else {
|
||||
for (int i = byteArray.length - 1; i >= 0; --i) {
|
||||
int sourceIndex = i - offsetBytes;
|
||||
if (sourceIndex < 0) {
|
||||
byteArray[i] = 0;
|
||||
continue;
|
||||
}
|
||||
byte src = byteArray[sourceIndex];
|
||||
byte dst = (byte)(src << shiftMod);
|
||||
if (sourceIndex - 1 >= 0) {
|
||||
dst = (byte)(dst | byteArray[sourceIndex - 1] >>> 8 - shiftMod & carryMask);
|
||||
}
|
||||
byteArray[i] = dst;
|
||||
}
|
||||
}
|
||||
return byteArray;
|
||||
}
|
||||
|
||||
static byte[] shiftRight(byte[] byteArray, int shiftBitCount, ByteOrder byteOrder) {
|
||||
int shiftMod = shiftBitCount % 8;
|
||||
byte carryMask = (byte)(255 << 8 - shiftMod);
|
||||
int offsetBytes = shiftBitCount / 8;
|
||||
if (byteOrder == ByteOrder.BIG_ENDIAN) {
|
||||
for (int i = byteArray.length - 1; i >= 0; --i) {
|
||||
int sourceIndex = i - offsetBytes;
|
||||
if (sourceIndex < 0) {
|
||||
byteArray[i] = 0;
|
||||
continue;
|
||||
}
|
||||
byte src = byteArray[sourceIndex];
|
||||
byte dst = (byte)((0xFF & src) >>> shiftMod);
|
||||
if (sourceIndex - 1 >= 0) {
|
||||
dst = (byte)(dst | byteArray[sourceIndex - 1] << 8 - shiftMod & carryMask);
|
||||
}
|
||||
byteArray[i] = dst;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < byteArray.length; ++i) {
|
||||
int sourceIndex = i + offsetBytes;
|
||||
if (sourceIndex >= byteArray.length) {
|
||||
byteArray[i] = 0;
|
||||
continue;
|
||||
}
|
||||
byte src = byteArray[sourceIndex];
|
||||
byte dst = (byte)((0xFF & src) >>> shiftMod);
|
||||
if (sourceIndex + 1 < byteArray.length) {
|
||||
dst = (byte)(dst | byteArray[sourceIndex + 1] << 8 - shiftMod & carryMask);
|
||||
}
|
||||
byteArray[i] = dst;
|
||||
}
|
||||
}
|
||||
return byteArray;
|
||||
}
|
||||
|
||||
static boolean constantTimeEquals(byte[] array, byte[] anotherArray) {
|
||||
if (anotherArray == null || array.length != anotherArray.length) {
|
||||
return false;
|
||||
}
|
||||
int result = 0;
|
||||
for (int i = 0; i < array.length; ++i) {
|
||||
result |= array[i] ^ anotherArray[i];
|
||||
}
|
||||
return result == 0;
|
||||
}
|
||||
|
||||
static double entropy(byte[] array) {
|
||||
int[] buffer = new int[256];
|
||||
Arrays.fill(buffer, -1);
|
||||
for (byte element : array) {
|
||||
int unsigned = 0xFF & element;
|
||||
if (buffer[unsigned] == -1) {
|
||||
buffer[unsigned] = 0;
|
||||
}
|
||||
int n = unsigned;
|
||||
buffer[n] = buffer[n] + 1;
|
||||
}
|
||||
double entropy = 0.0;
|
||||
for (int count : buffer) {
|
||||
if (count == -1) continue;
|
||||
double prob = (double)count / (double)array.length;
|
||||
entropy -= prob * (Math.log(prob) / Math.log(2.0));
|
||||
}
|
||||
return entropy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt;
|
||||
|
||||
import com.barchart.udt.OptionUDT;
|
||||
import com.barchart.udt.SocketUDT;
|
||||
import com.barchart.udt.net.NetSocketUDT;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class AppClient {
|
||||
static boolean finished = false;
|
||||
|
||||
public static void main(String[] args) {
|
||||
int port = 9000;
|
||||
int size = 10000;
|
||||
byte[] data = new byte[10000];
|
||||
Future<Boolean> monResult = null;
|
||||
if (args.length != 2) {
|
||||
System.out.println("usage: appclient server_host server_port");
|
||||
return;
|
||||
}
|
||||
String host = args[0];
|
||||
port = Integer.parseInt(args[1]);
|
||||
try {
|
||||
final NetSocketUDT socket = new NetSocketUDT();
|
||||
if (System.getProperty("os.name").contains("win")) {
|
||||
socket.socketUDT().setOption(OptionUDT.UDT_MSS, 1052);
|
||||
}
|
||||
socket.connect(new InetSocketAddress(host, port));
|
||||
OutputStream os = socket.getOutputStream();
|
||||
monResult = Executors.newSingleThreadExecutor().submit(new Callable<Boolean>(){
|
||||
|
||||
@Override
|
||||
public Boolean call() {
|
||||
return AppClient.monitor(socket.socketUDT());
|
||||
}
|
||||
});
|
||||
for (int i = 0; i < 1000000; ++i) {
|
||||
os.write(data);
|
||||
}
|
||||
finished = true;
|
||||
if (monResult != null) {
|
||||
monResult.get();
|
||||
}
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean monitor(SocketUDT socket) {
|
||||
System.out.println("SendRate(Mb/s)\tRTT(ms)\tCWnd\tPktSndPeriod(us)\tRecvACK\tRecvNAK");
|
||||
try {
|
||||
while (!finished) {
|
||||
Thread.sleep(1000L);
|
||||
socket.updateMonitor(false);
|
||||
System.out.printf("%.2f\t\t%.2f\t%d\t%.2f\t\t\t%d\t%d\n", socket.monitor().mbpsSendRate, socket.monitor().msRTT, socket.monitor().pktCongestionWindow, socket.monitor().usPktSndPeriod, socket.monitor().pktRecvACK, socket.monitor().pktRecvNAK);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt;
|
||||
|
||||
import com.barchart.udt.net.NetServerSocketUDT;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Executors;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class AppServer {
|
||||
static Logger log = LoggerFactory.getLogger(AppServer.class);
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
int port = 9000;
|
||||
if (args.length > 1) {
|
||||
System.out.println("usage: appserver [server_port]");
|
||||
return;
|
||||
}
|
||||
if (args.length == 1) {
|
||||
port = Integer.parseInt(args[0]);
|
||||
}
|
||||
NetServerSocketUDT acceptorSocket = new NetServerSocketUDT();
|
||||
acceptorSocket.bind(new InetSocketAddress("0.0.0.0", port), 256);
|
||||
System.out.printf("server is ready at port: %d\n", port);
|
||||
while (true) {
|
||||
final Socket clientSocket = acceptorSocket.accept();
|
||||
Executors.newSingleThreadExecutor().submit(new Callable<Boolean>(){
|
||||
|
||||
@Override
|
||||
public Boolean call() {
|
||||
return AppServer.clientTask(clientSocket);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean clientTask(Socket clientSocket) {
|
||||
byte[] data = new byte[10000];
|
||||
try {
|
||||
InputStream is = clientSocket.getInputStream();
|
||||
block2: while (true) {
|
||||
int remain = data.length;
|
||||
while (true) {
|
||||
if (remain <= 0) continue block2;
|
||||
int ret = is.read(data, data.length - remain, remain);
|
||||
remain -= ret;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt;
|
||||
|
||||
public class BundleUDT {
|
||||
}
|
||||
|
||||
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt;
|
||||
|
||||
import com.barchart.udt.MonitorUDT;
|
||||
import com.barchart.udt.SocketUDT;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CCC {
|
||||
private static boolean initOk = SocketUDT.INIT_OK;
|
||||
private long nativeHandle;
|
||||
private int msINT;
|
||||
private int pktINT;
|
||||
private int usRTO;
|
||||
private final Logger log = LoggerFactory.getLogger(CCC.class);
|
||||
|
||||
private native void initNative();
|
||||
|
||||
protected native void setACKTimer(int var1);
|
||||
|
||||
protected native void setACKInterval(int var1);
|
||||
|
||||
protected native void setRTO(int var1);
|
||||
|
||||
protected native void setPacketSndPeriod(double var1);
|
||||
|
||||
protected native void setCWndSize(double var1);
|
||||
|
||||
protected native MonitorUDT getPerfInfo();
|
||||
|
||||
public CCC() {
|
||||
this.initNative();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
this.log.info("CCC::init");
|
||||
}
|
||||
|
||||
public void close() {
|
||||
this.log.info("CCC::close");
|
||||
}
|
||||
|
||||
public void onACK(int ack) {
|
||||
}
|
||||
|
||||
public void onLoss(int[] lossList) {
|
||||
}
|
||||
|
||||
public void onTimeout() {
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt;
|
||||
|
||||
import com.barchart.udt.ExceptionUDT;
|
||||
import com.barchart.udt.SocketUDT;
|
||||
import com.barchart.udt.TypeUDT;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class EpollUDT {
|
||||
protected static final Logger log = LoggerFactory.getLogger(EpollUDT.class);
|
||||
protected final int id = SocketUDT.epollCreate0();
|
||||
protected volatile boolean isActive = true;
|
||||
private final SocketUDT socketUDT = new SocketUDT(TypeUDT.DATAGRAM);
|
||||
|
||||
public EpollUDT() throws ExceptionUDT {
|
||||
SocketUDT.epollAdd0(this.id, this.socketUDT.id(), Opt.BOTH.code);
|
||||
log.debug("ep {} create", (Object)this.id());
|
||||
}
|
||||
|
||||
public void destroy() throws ExceptionUDT {
|
||||
SocketUDT.epollRemove0(this.id(), this.socketUDT.id());
|
||||
this.socketUDT.close();
|
||||
this.isActive = false;
|
||||
SocketUDT.epollRelease0(this.id());
|
||||
log.debug("ep {} delete", (Object)this.id());
|
||||
}
|
||||
|
||||
public int id() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return this.isActive;
|
||||
}
|
||||
|
||||
protected void finalize() {
|
||||
try {
|
||||
this.destroy();
|
||||
super.finalize();
|
||||
}
|
||||
catch (Throwable e) {
|
||||
log.error("failed to destroy id=" + this.id(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(SocketUDT socket, Opt option) throws ExceptionUDT {
|
||||
log.debug("ep {} add {} {}", new Object[]{this.id(), socket, option});
|
||||
SocketUDT.epollAdd0(this.id(), socket.id(), option.code);
|
||||
}
|
||||
|
||||
public void remove(SocketUDT socket) throws ExceptionUDT {
|
||||
log.debug("ep {} rem {}", (Object)this.id(), (Object)socket);
|
||||
SocketUDT.epollRemove0(this.id(), socket.id());
|
||||
}
|
||||
|
||||
public void update(SocketUDT socket, Opt option) throws ExceptionUDT {
|
||||
log.debug("ep {} mod {} {}", new Object[]{this.id(), socket, option});
|
||||
assert (option.isValidInterestRequest());
|
||||
SocketUDT.epollUpdate0(this.id(), socket.id(), option.code);
|
||||
}
|
||||
|
||||
public Opt verify(SocketUDT socket) throws ExceptionUDT {
|
||||
int code = SocketUDT.epollVerify0(this.id(), socket.id());
|
||||
return Opt.from(code);
|
||||
}
|
||||
|
||||
public static enum Opt {
|
||||
NONE(0),
|
||||
READ(1),
|
||||
WRITE(4),
|
||||
ERROR(8),
|
||||
BOTH(Opt.WRITE.code | Opt.READ.code),
|
||||
ERROR_READ(Opt.ERROR.code | Opt.READ.code),
|
||||
ERROR_WRITE(Opt.ERROR.code | Opt.WRITE.code),
|
||||
ALL(Opt.ERROR.code | Opt.WRITE.code | Opt.READ.code),
|
||||
UNKNOWN(-1);
|
||||
|
||||
private static final Opt[] ENUM_VALS;
|
||||
public final int code;
|
||||
|
||||
public static Opt from(int code) {
|
||||
for (Opt known : ENUM_VALS) {
|
||||
if (known.code != code) continue;
|
||||
return known;
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
private Opt(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public boolean hasError() {
|
||||
return (this.code & Opt.ERROR.code) != 0;
|
||||
}
|
||||
|
||||
public boolean hasRead() {
|
||||
return (this.code & Opt.READ.code) != 0;
|
||||
}
|
||||
|
||||
public boolean hasWrite() {
|
||||
return (this.code & Opt.WRITE.code) != 0;
|
||||
}
|
||||
|
||||
public boolean isValidInterestRequest() {
|
||||
switch (this) {
|
||||
case NONE:
|
||||
case READ:
|
||||
case WRITE:
|
||||
case ERROR:
|
||||
case BOTH:
|
||||
case ERROR_WRITE:
|
||||
case ERROR_READ:
|
||||
case ALL: {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static {
|
||||
ENUM_VALS = Opt.values();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt;
|
||||
|
||||
public enum ErrorUDT {
|
||||
SUCCESS(0, "success operation"),
|
||||
ECONNSETUP(1000, "connection setup failure"),
|
||||
NOSERVER(1001, "server does not exist"),
|
||||
ECONNREJ(1002, "connection request was rejected by server"),
|
||||
ESOCKFAIL(1003, "could not create/configure UDP socket"),
|
||||
ESECFAIL(1004, "connection request was aborted due to security reasons"),
|
||||
ECONNFAIL(2000, "connection failure"),
|
||||
ECONNLOST(2001, "connection was broken"),
|
||||
ENOCONN(2002, "connection does not exist"),
|
||||
ERESOURCE(3000, "system resource failure"),
|
||||
ETHREAD(3001, "could not create new thread"),
|
||||
ENOBUF(3002, "no memory space"),
|
||||
EFILE(4000, "file access error"),
|
||||
EINVRDOFF(4001, "invalid read offset"),
|
||||
ERDPERM(4002, "no read permission"),
|
||||
EINVWROFF(4003, "invalid write offset"),
|
||||
EWRPERM(4004, "no write permission"),
|
||||
EINVOP(5000, "operation not supported"),
|
||||
EBOUNDSOCK(5001, "cannot execute the operation on a bound socket"),
|
||||
ECONNSOCK(5002, "cannot execute the operation on a connected socket"),
|
||||
EINVPARAM(5003, "bad parameters"),
|
||||
EINVSOCK(5004, "invalid UDT socket"),
|
||||
EUNBOUNDSOCK(5005, "cannot listen on unbound socket"),
|
||||
ENOLISTEN(5006, "(accept) socket is not in listening state"),
|
||||
ERDVNOSERV(5007, "rendezvous connection process does not allow listen and accept call"),
|
||||
ERDVUNBOUND(5008, "rendezvous connection setup is enabled but bind has not been called before connect"),
|
||||
ESTREAMILL(5009, "operation not supported in SOCK_STREAM mode"),
|
||||
EDGRAMILL(5010, "operation not supported in SOCK_DGRAM mode"),
|
||||
EDUPLISTEN(5011, "another socket is already listening on the same UDP port"),
|
||||
ELARGEMSG(5012, "message is too large to be hold in the sending buffer"),
|
||||
EINVPOLLID(5013, "epoll ID is invalid"),
|
||||
EASYNCFAIL(6000, "non-blocking call failure"),
|
||||
EASYNCSND(6001, "no buffer available for sending"),
|
||||
EASYNCRCV(6002, "no data available for read"),
|
||||
ETIMEOUT(6003, "timeout before operation completes"),
|
||||
EPEERERR(7000, "error has happened at the peer side"),
|
||||
WRAPPER_UNKNOWN(-1, "unknown error code"),
|
||||
WRAPPER_UNIMPLEMENTED(-2, "this feature is not yet implemented"),
|
||||
WRAPPER_MESSAGE(-3, "wrapper generated error"),
|
||||
USER_DEFINED_MESSAGE(-4, "user defined message");
|
||||
|
||||
private final int code;
|
||||
private final String description;
|
||||
static final ErrorUDT[] ENUM_VALS;
|
||||
|
||||
public int getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
private ErrorUDT(int code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public static ErrorUDT errorFrom(int code) {
|
||||
for (ErrorUDT known : ENUM_VALS) {
|
||||
if (known.code != code) continue;
|
||||
return known;
|
||||
}
|
||||
return WRAPPER_UNKNOWN;
|
||||
}
|
||||
|
||||
public static String descriptionFrom(int socketID, int errorCode, String errorComment) {
|
||||
ErrorUDT error = ErrorUDT.errorFrom(errorCode);
|
||||
return String.format("UDT Error : %d : %s : %s [id: 0x%08x]", errorCode, error.description, errorComment, socketID);
|
||||
}
|
||||
|
||||
static {
|
||||
ENUM_VALS = ErrorUDT.values();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt;
|
||||
|
||||
import com.barchart.udt.ErrorUDT;
|
||||
import com.barchart.udt.anno.Native;
|
||||
import java.net.SocketException;
|
||||
|
||||
public class ExceptionUDT
|
||||
extends SocketException {
|
||||
@Native
|
||||
private final ErrorUDT errorUDT;
|
||||
@Native
|
||||
private final int socketID;
|
||||
|
||||
public ErrorUDT getError() {
|
||||
return this.errorUDT;
|
||||
}
|
||||
|
||||
public int getSocketID() {
|
||||
return this.socketID;
|
||||
}
|
||||
|
||||
@Native
|
||||
protected ExceptionUDT(int socketID, int errorCode, String comment) {
|
||||
super(ErrorUDT.descriptionFrom(socketID, errorCode, comment));
|
||||
this.errorUDT = ErrorUDT.errorFrom(errorCode);
|
||||
this.socketID = socketID;
|
||||
}
|
||||
|
||||
@Native
|
||||
protected ExceptionUDT(int socketID, ErrorUDT error, String comment) {
|
||||
super(ErrorUDT.descriptionFrom(socketID, error.getCode(), comment));
|
||||
this.errorUDT = error;
|
||||
this.socketID = socketID;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt;
|
||||
|
||||
import com.barchart.udt.CCC;
|
||||
|
||||
public interface FactoryInterfaceUDT {
|
||||
public CCC create();
|
||||
|
||||
public FactoryInterfaceUDT cloneFactory();
|
||||
}
|
||||
|
||||
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt;
|
||||
|
||||
import com.barchart.udt.CCC;
|
||||
import com.barchart.udt.FactoryInterfaceUDT;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class FactoryUDT<C>
|
||||
implements FactoryInterfaceUDT {
|
||||
C classType;
|
||||
final Class<C> clazz;
|
||||
Logger log = LoggerFactory.getLogger(FactoryUDT.class);
|
||||
boolean doInit = false;
|
||||
boolean doClose = false;
|
||||
boolean doOnACK = false;
|
||||
boolean doOnLoss = false;
|
||||
boolean doOnTimeout = false;
|
||||
|
||||
public FactoryUDT(Class<C> clazz) {
|
||||
this.clazz = clazz;
|
||||
if (!CCC.class.isAssignableFrom(clazz)) {
|
||||
throw new IllegalArgumentException("Generic argument 'C' must be 'CCC' class or extension");
|
||||
}
|
||||
try {
|
||||
if (clazz.getMethod("init", new Class[0]).getDeclaringClass() != CCC.class) {
|
||||
this.doInit = true;
|
||||
}
|
||||
if (clazz.getMethod("close", new Class[0]).getDeclaringClass() != CCC.class) {
|
||||
this.doClose = true;
|
||||
}
|
||||
if (clazz.getMethod("onACK", Integer.TYPE).getDeclaringClass() != CCC.class) {
|
||||
this.doOnACK = true;
|
||||
}
|
||||
if (clazz.getMethod("onLoss", int[].class).getDeclaringClass() != CCC.class) {
|
||||
this.doOnLoss = true;
|
||||
}
|
||||
if (clazz.getMethod("onTimeout", new Class[0]).getDeclaringClass() != CCC.class) {
|
||||
this.doOnTimeout = true;
|
||||
}
|
||||
}
|
||||
catch (SecurityException e) {
|
||||
this.log.error("Error setting up class factory", e);
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
this.log.error("Expected CCC method doesn't exsit", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CCC create() {
|
||||
try {
|
||||
C cccObj = this.clazz.newInstance();
|
||||
return (CCC)cccObj;
|
||||
}
|
||||
catch (InstantiationException e) {
|
||||
this.log.error("Failed to instansiate CCC class", e);
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
this.log.error("Failed to instansiate CCC class", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FactoryInterfaceUDT cloneFactory() {
|
||||
return new FactoryUDT<C>(this.clazz);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt;
|
||||
|
||||
public class LingerUDT
|
||||
extends Number
|
||||
implements Comparable<LingerUDT> {
|
||||
public static final LingerUDT LINGER_ZERO = new LingerUDT(0);
|
||||
final int timeout;
|
||||
private static final long serialVersionUID = 3414455799823407217L;
|
||||
|
||||
public LingerUDT(int lingerSeconds) throws IllegalArgumentException {
|
||||
if (65535 < lingerSeconds) {
|
||||
throw new IllegalArgumentException("lingerSeconds is out of range: 0 <= linger <= 65535");
|
||||
}
|
||||
this.timeout = lingerSeconds > 0 ? lingerSeconds : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double doubleValue() {
|
||||
return this.timeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float floatValue() {
|
||||
return this.timeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int intValue() {
|
||||
return this.timeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long longValue() {
|
||||
return this.timeout;
|
||||
}
|
||||
|
||||
boolean isLingerOn() {
|
||||
return this.timeout > 0;
|
||||
}
|
||||
|
||||
int timeout() {
|
||||
return this.timeout;
|
||||
}
|
||||
|
||||
public boolean equals(Object otherLinger) {
|
||||
if (otherLinger instanceof LingerUDT) {
|
||||
LingerUDT other = (LingerUDT)otherLinger;
|
||||
return other.timeout == this.timeout;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.timeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(LingerUDT other) {
|
||||
return other.timeout - this.timeout;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.valueOf(this.timeout);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,212 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt;
|
||||
|
||||
import com.barchart.udt.SocketUDT;
|
||||
import java.lang.reflect.Field;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class MonitorUDT {
|
||||
private static final Logger log = LoggerFactory.getLogger(MonitorUDT.class);
|
||||
protected final SocketUDT socketUDT;
|
||||
protected volatile long msTimeStamp;
|
||||
protected volatile long pktSentTotal;
|
||||
protected volatile long pktRecvTotal;
|
||||
protected volatile int pktSndLossTotal;
|
||||
protected volatile int pktRcvLossTotal;
|
||||
protected volatile int pktRetransTotal;
|
||||
protected volatile int pktSentACKTotal;
|
||||
protected volatile int pktRecvACKTotal;
|
||||
protected volatile int pktSentNAKTotal;
|
||||
protected volatile int pktRecvNAKTotal;
|
||||
protected volatile long usSndDurationTotal;
|
||||
protected volatile long pktSent;
|
||||
protected volatile long pktRecv;
|
||||
protected volatile int pktSndLoss;
|
||||
protected volatile int pktRcvLoss;
|
||||
protected volatile int pktRetrans;
|
||||
protected volatile int pktSentACK;
|
||||
protected volatile int pktRecvACK;
|
||||
protected volatile int pktSentNAK;
|
||||
protected volatile int pktRecvNAK;
|
||||
protected volatile double mbpsSendRate;
|
||||
protected volatile double mbpsRecvRate;
|
||||
protected volatile long usSndDuration;
|
||||
protected volatile double usPktSndPeriod;
|
||||
protected volatile int pktFlowWindow;
|
||||
protected volatile int pktCongestionWindow;
|
||||
protected volatile int pktFlightSize;
|
||||
protected volatile double msRTT;
|
||||
protected volatile double mbpsBandwidth;
|
||||
protected volatile int byteAvailSndBuf;
|
||||
protected volatile int byteAvailRcvBuf;
|
||||
|
||||
protected MonitorUDT(SocketUDT socketUDT) {
|
||||
this.socketUDT = socketUDT;
|
||||
}
|
||||
|
||||
public long millisSinceStart() {
|
||||
return this.msTimeStamp;
|
||||
}
|
||||
|
||||
public long globalSentTotal() {
|
||||
return this.pktSentTotal;
|
||||
}
|
||||
|
||||
public long globalReceivedTotal() {
|
||||
return this.pktRecvTotal;
|
||||
}
|
||||
|
||||
public int globalSenderLost() {
|
||||
return this.pktSndLossTotal;
|
||||
}
|
||||
|
||||
public int globalReceiverLost() {
|
||||
return this.pktRcvLossTotal;
|
||||
}
|
||||
|
||||
public int globalRetransmittedTotal() {
|
||||
return this.pktRetransTotal;
|
||||
}
|
||||
|
||||
public int globalSentAckTotal() {
|
||||
return this.pktSentACKTotal;
|
||||
}
|
||||
|
||||
public int globalReceivedAckTotal() {
|
||||
return this.pktRecvACKTotal;
|
||||
}
|
||||
|
||||
public int globalSentNakTotal() {
|
||||
return this.pktSentNAKTotal;
|
||||
}
|
||||
|
||||
public int globalReceivedNakTotal() {
|
||||
return this.pktRecvNAKTotal;
|
||||
}
|
||||
|
||||
public long globalMicrosSendDurationTotal() {
|
||||
return this.usSndDurationTotal;
|
||||
}
|
||||
|
||||
public long localPacketsSent() {
|
||||
return this.pktSent;
|
||||
}
|
||||
|
||||
public long localPacketsReceived() {
|
||||
return this.pktRecv;
|
||||
}
|
||||
|
||||
public int localSenderLost() {
|
||||
return this.pktSndLoss;
|
||||
}
|
||||
|
||||
public int localReceiverLost() {
|
||||
return this.pktRcvLoss;
|
||||
}
|
||||
|
||||
public int localRetransmitted() {
|
||||
return this.pktRetrans;
|
||||
}
|
||||
|
||||
public int localSentAck() {
|
||||
return this.pktSentACK;
|
||||
}
|
||||
|
||||
public int localReceivedAck() {
|
||||
return this.pktRecvACK;
|
||||
}
|
||||
|
||||
public int localSentNak() {
|
||||
return this.pktSentNAK;
|
||||
}
|
||||
|
||||
public int localReceivedNak() {
|
||||
return this.pktRecvNAK;
|
||||
}
|
||||
|
||||
public double mbpsSendRate() {
|
||||
return this.mbpsSendRate;
|
||||
}
|
||||
|
||||
public double mbpsReceiveRate() {
|
||||
return this.mbpsRecvRate;
|
||||
}
|
||||
|
||||
public long microsSendTime() {
|
||||
return this.usSndDuration;
|
||||
}
|
||||
|
||||
public double currentSendPeriod() {
|
||||
return this.usPktSndPeriod;
|
||||
}
|
||||
|
||||
public int currentFlowWindow() {
|
||||
return this.pktFlowWindow;
|
||||
}
|
||||
|
||||
public int currentCongestionWindow() {
|
||||
return this.pktCongestionWindow;
|
||||
}
|
||||
|
||||
public int currentFlightSize() {
|
||||
return this.pktFlightSize;
|
||||
}
|
||||
|
||||
public double currentMillisRTT() {
|
||||
return this.msRTT;
|
||||
}
|
||||
|
||||
public double currentMbpsBandwidth() {
|
||||
return this.mbpsBandwidth;
|
||||
}
|
||||
|
||||
public int currentAvailableInSender() {
|
||||
return this.byteAvailSndBuf;
|
||||
}
|
||||
|
||||
public int currentAvailableInReceiver() {
|
||||
return this.byteAvailRcvBuf;
|
||||
}
|
||||
|
||||
public void appendSnapshot(StringBuilder text) {
|
||||
Field[] fieldArray;
|
||||
text.append("\n\t");
|
||||
text.append(String.format("[id: 0x%08x]", this.socketUDT.id()));
|
||||
for (Field field : fieldArray = MonitorUDT.class.getDeclaredFields()) {
|
||||
if (!this.isNumeric(field)) continue;
|
||||
try {
|
||||
field.setAccessible(true);
|
||||
String fieldName = field.getName();
|
||||
String fieldValue = field.get(this).toString();
|
||||
text.append("\n\t");
|
||||
text.append(fieldName);
|
||||
text.append(" = ");
|
||||
text.append(fieldValue);
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("unexpected", e);
|
||||
}
|
||||
}
|
||||
double localSendLoss = 100.0 * (double)this.pktSndLoss / (double)this.pktSent;
|
||||
text.append("\n\t% localSendLoss = ");
|
||||
text.append(localSendLoss);
|
||||
double localReceiveLoss = 100.0 * (double)this.pktRcvLoss / (double)this.pktRecv;
|
||||
text.append("\n\t% localReceiveLoss = ");
|
||||
text.append(localReceiveLoss);
|
||||
}
|
||||
|
||||
protected boolean isNumeric(Field field) {
|
||||
Class<?> fieledType = field.getType();
|
||||
return fieledType == Integer.TYPE || fieledType == Long.TYPE || fieledType == Double.TYPE;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder text = new StringBuilder(1024);
|
||||
this.appendSnapshot(text);
|
||||
return text.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,208 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt;
|
||||
|
||||
import com.barchart.udt.FactoryUDT;
|
||||
import com.barchart.udt.LingerUDT;
|
||||
import com.barchart.udt.SocketUDT;
|
||||
import com.barchart.udt.util.HelpUDT;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class OptionUDT<T> {
|
||||
public static final OptionUDT<Integer> UDT_MSS;
|
||||
public static final OptionUDT<Integer> Maximum_Transfer_Unit;
|
||||
public static final OptionUDT<Boolean> UDT_SNDSYN;
|
||||
public static final OptionUDT<Boolean> Is_Send_Synchronous;
|
||||
public static final OptionUDT<Boolean> UDT_RCVSYN;
|
||||
public static final OptionUDT<Boolean> Is_Receive_Synchronous;
|
||||
public static final OptionUDT<FactoryUDT> UDT_CC;
|
||||
public static final OptionUDT<FactoryUDT> Custom_Congestion_Control;
|
||||
public static final OptionUDT<Integer> UDT_FC;
|
||||
public static final OptionUDT<Integer> Flight_Window_Size;
|
||||
public static final OptionUDT<Integer> UDT_SNDBUF;
|
||||
public static final OptionUDT<Integer> Protocol_Send_Buffer_Size;
|
||||
public static final OptionUDT<Integer> UDT_RCVBUF;
|
||||
public static final OptionUDT<Integer> Protocol_Receive_Buffer_Size;
|
||||
public static final OptionUDT<LingerUDT> UDT_LINGER;
|
||||
public static final OptionUDT<LingerUDT> Time_To_Linger_On_Close;
|
||||
public static final OptionUDT<Integer> UDP_SNDBUF;
|
||||
public static final OptionUDT<Integer> System_Send_Buffer_Size;
|
||||
public static final OptionUDT<Integer> UDP_RCVBUF;
|
||||
public static final OptionUDT<Integer> System_Receive_Buffer_Size;
|
||||
public static final OptionUDT<Boolean> UDT_RENDEZVOUS;
|
||||
public static final OptionUDT<Boolean> Is_Randezvous_Connect_Enabled;
|
||||
public static final OptionUDT<Integer> UDT_SNDTIMEO;
|
||||
public static final OptionUDT<Integer> Send_Timeout;
|
||||
public static final OptionUDT<Integer> UDT_RCVTIMEO;
|
||||
public static final OptionUDT<Integer> Receive_Timeout;
|
||||
public static final OptionUDT<Boolean> UDT_REUSEADDR;
|
||||
public static final OptionUDT<Boolean> Is_Address_Reuse_Enabled;
|
||||
public static final OptionUDT<Long> UDT_MAXBW;
|
||||
public static final OptionUDT<Long> Maximum_Bandwidth;
|
||||
public static final OptionUDT<Integer> UDT_STATE;
|
||||
public static final OptionUDT<Integer> Status_Code;
|
||||
public static final OptionUDT<Integer> UDT_EVENT;
|
||||
public static final OptionUDT<Integer> Epoll_Event_Mask;
|
||||
public static final OptionUDT<Integer> UDT_SNDDATA;
|
||||
public static final OptionUDT<Integer> Send_Buffer_Consumed;
|
||||
public static final OptionUDT<Integer> UDT_RCVDATA;
|
||||
public static final OptionUDT<Integer> Receive_Buffer_Available;
|
||||
protected static final Logger log;
|
||||
protected static final List<OptionUDT<?>> values;
|
||||
private final int code;
|
||||
private final Class<?> type;
|
||||
private final Format format;
|
||||
private String name;
|
||||
|
||||
protected OptionUDT(int code, Class<T> klaz, Format format) {
|
||||
this.code = code;
|
||||
this.type = klaz;
|
||||
this.format = format;
|
||||
values.add(this);
|
||||
}
|
||||
|
||||
protected static <T> OptionUDT<T> NEW(int code, Class<T> klaz, Format format) {
|
||||
return new OptionUDT<T>(code, klaz, format);
|
||||
}
|
||||
|
||||
public static void appendSnapshot(SocketUDT socketUDT, StringBuilder text) {
|
||||
text.append("\n\t");
|
||||
text.append(String.format("[id: 0x%08x]", socketUDT.id()));
|
||||
for (OptionUDT<?> option : values) {
|
||||
int optionCode = 0;
|
||||
String optionName = null;
|
||||
String optionValue = null;
|
||||
try {
|
||||
optionCode = option.code;
|
||||
optionName = option.name();
|
||||
optionValue = option.format.convert(socketUDT.getOption(option));
|
||||
if (optionName.startsWith("UD")) continue;
|
||||
text.append("\n\t");
|
||||
text.append(optionCode);
|
||||
text.append(") ");
|
||||
text.append(optionName);
|
||||
text.append(" = ");
|
||||
text.append(optionValue);
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("unexpected; " + optionName, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int code() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public Class<?> type() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public Format format() {
|
||||
return this.format;
|
||||
}
|
||||
|
||||
public String name() {
|
||||
if (this.name == null) {
|
||||
this.name = HelpUDT.constantFieldName(this.getClass(), this);
|
||||
}
|
||||
return this.name;
|
||||
}
|
||||
|
||||
static {
|
||||
log = LoggerFactory.getLogger(OptionUDT.class);
|
||||
values = new CopyOnWriteArrayList();
|
||||
UDT_MSS = OptionUDT.NEW(0, Integer.class, Format.DECIMAL);
|
||||
Maximum_Transfer_Unit = OptionUDT.NEW(0, Integer.class, Format.DECIMAL);
|
||||
UDT_SNDSYN = OptionUDT.NEW(1, Boolean.class, Format.BOOLEAN);
|
||||
Is_Send_Synchronous = OptionUDT.NEW(1, Boolean.class, Format.BOOLEAN);
|
||||
UDT_RCVSYN = OptionUDT.NEW(2, Boolean.class, Format.BOOLEAN);
|
||||
Is_Receive_Synchronous = OptionUDT.NEW(2, Boolean.class, Format.BOOLEAN);
|
||||
UDT_CC = OptionUDT.NEW(3, FactoryUDT.class, Format.DEFAULT);
|
||||
Custom_Congestion_Control = OptionUDT.NEW(3, FactoryUDT.class, Format.DEFAULT);
|
||||
UDT_FC = OptionUDT.NEW(4, Integer.class, Format.BINARY);
|
||||
Flight_Window_Size = OptionUDT.NEW(4, Integer.class, Format.BINARY);
|
||||
UDT_SNDBUF = OptionUDT.NEW(5, Integer.class, Format.DECIMAL);
|
||||
Protocol_Send_Buffer_Size = OptionUDT.NEW(5, Integer.class, Format.DECIMAL);
|
||||
UDT_RCVBUF = OptionUDT.NEW(6, Integer.class, Format.DECIMAL);
|
||||
Protocol_Receive_Buffer_Size = OptionUDT.NEW(6, Integer.class, Format.DECIMAL);
|
||||
UDT_LINGER = OptionUDT.NEW(7, LingerUDT.class, Format.DECIMAL);
|
||||
Time_To_Linger_On_Close = OptionUDT.NEW(7, LingerUDT.class, Format.DECIMAL);
|
||||
UDP_SNDBUF = OptionUDT.NEW(8, Integer.class, Format.DECIMAL);
|
||||
System_Send_Buffer_Size = OptionUDT.NEW(8, Integer.class, Format.DECIMAL);
|
||||
UDP_RCVBUF = OptionUDT.NEW(9, Integer.class, Format.DECIMAL);
|
||||
System_Receive_Buffer_Size = OptionUDT.NEW(9, Integer.class, Format.DECIMAL);
|
||||
UDT_RENDEZVOUS = OptionUDT.NEW(12, Boolean.class, Format.BOOLEAN);
|
||||
Is_Randezvous_Connect_Enabled = OptionUDT.NEW(12, Boolean.class, Format.BOOLEAN);
|
||||
UDT_SNDTIMEO = OptionUDT.NEW(13, Integer.class, Format.DECIMAL);
|
||||
Send_Timeout = OptionUDT.NEW(13, Integer.class, Format.DECIMAL);
|
||||
UDT_RCVTIMEO = OptionUDT.NEW(14, Integer.class, Format.DECIMAL);
|
||||
Receive_Timeout = OptionUDT.NEW(14, Integer.class, Format.DECIMAL);
|
||||
UDT_REUSEADDR = OptionUDT.NEW(15, Boolean.class, Format.BOOLEAN);
|
||||
Is_Address_Reuse_Enabled = OptionUDT.NEW(15, Boolean.class, Format.BOOLEAN);
|
||||
UDT_MAXBW = OptionUDT.NEW(16, Long.class, Format.DECIMAL);
|
||||
Maximum_Bandwidth = OptionUDT.NEW(16, Long.class, Format.DECIMAL);
|
||||
UDT_STATE = OptionUDT.NEW(17, Integer.class, Format.DECIMAL);
|
||||
Status_Code = OptionUDT.NEW(17, Integer.class, Format.DECIMAL);
|
||||
UDT_EVENT = OptionUDT.NEW(18, Integer.class, Format.DECIMAL);
|
||||
Epoll_Event_Mask = OptionUDT.NEW(18, Integer.class, Format.DECIMAL);
|
||||
UDT_SNDDATA = OptionUDT.NEW(19, Integer.class, Format.DECIMAL);
|
||||
Send_Buffer_Consumed = OptionUDT.NEW(19, Integer.class, Format.DECIMAL);
|
||||
UDT_RCVDATA = OptionUDT.NEW(20, Integer.class, Format.DECIMAL);
|
||||
Receive_Buffer_Available = OptionUDT.NEW(20, Integer.class, Format.DECIMAL);
|
||||
}
|
||||
|
||||
public static enum Format {
|
||||
DECIMAL{
|
||||
|
||||
@Override
|
||||
public String convert(Object value) {
|
||||
if (value instanceof Number) {
|
||||
long number = ((Number)value).longValue();
|
||||
return String.format("%,d", number);
|
||||
}
|
||||
return "invalid format";
|
||||
}
|
||||
}
|
||||
,
|
||||
BINARY{
|
||||
|
||||
@Override
|
||||
public String convert(Object value) {
|
||||
if (value instanceof Number) {
|
||||
long number = ((Number)value).longValue();
|
||||
return String.format("%,d (%,d K)", number, number / 1024L);
|
||||
}
|
||||
return "invalid format";
|
||||
}
|
||||
}
|
||||
,
|
||||
BOOLEAN{
|
||||
|
||||
@Override
|
||||
public String convert(Object value) {
|
||||
if (value instanceof Boolean) {
|
||||
boolean bool = (Boolean)value;
|
||||
return String.format("%b", bool);
|
||||
}
|
||||
return "invalid format";
|
||||
}
|
||||
}
|
||||
,
|
||||
DEFAULT{
|
||||
|
||||
@Override
|
||||
public String convert(Object value) {
|
||||
return "" + value;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public abstract String convert(Object var1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt;
|
||||
|
||||
import com.barchart.udt.lib.LibraryLoaderUDT;
|
||||
|
||||
public final class ResourceUDT {
|
||||
public static final String PACKAGE_NAME = ResourceUDT.class.getPackage().getName();
|
||||
public static final String PROPERTY_LIBRARY_EXTRACT_LOCATION = PACKAGE_NAME + ".library.extract.location";
|
||||
public static final String PROPERTY_LOADER_CLASS_NAME = PACKAGE_NAME + ".loader.class.name";
|
||||
public static final String DEFAULT_LIBRARY_EXTRACT_LOCATION = "./lib/bin";
|
||||
public static final String DEFAULT_LIBRARY_LOADER_CLASS = LibraryLoaderUDT.class.getName();
|
||||
|
||||
private ResourceUDT() {
|
||||
}
|
||||
|
||||
public static String getLibraryExtractLocation() {
|
||||
return System.getProperty(PROPERTY_LIBRARY_EXTRACT_LOCATION, DEFAULT_LIBRARY_EXTRACT_LOCATION);
|
||||
}
|
||||
|
||||
public static void setLibraryExtractLocation(String location) {
|
||||
System.setProperty(PROPERTY_LIBRARY_EXTRACT_LOCATION, location);
|
||||
}
|
||||
|
||||
public static String getLibraryLoaderClassName() {
|
||||
return System.getProperty(PROPERTY_LOADER_CLASS_NAME, DEFAULT_LIBRARY_LOADER_CLASS);
|
||||
}
|
||||
|
||||
public static void setLibraryLoaderClassName(String className) {
|
||||
System.setProperty(PROPERTY_LOADER_CLASS_NAME, className);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,729 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt;
|
||||
|
||||
import com.barchart.udt.ErrorUDT;
|
||||
import com.barchart.udt.ExceptionUDT;
|
||||
import com.barchart.udt.LingerUDT;
|
||||
import com.barchart.udt.MonitorUDT;
|
||||
import com.barchart.udt.OptionUDT;
|
||||
import com.barchart.udt.ResourceUDT;
|
||||
import com.barchart.udt.StatusUDT;
|
||||
import com.barchart.udt.TypeUDT;
|
||||
import com.barchart.udt.anno.Native;
|
||||
import com.barchart.udt.lib.LibraryLoader;
|
||||
import com.barchart.udt.util.HelpUDT;
|
||||
import java.io.File;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.Set;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SocketUDT {
|
||||
public static final int DEFAULT_ACCEPT_QUEUE_SIZE = 256;
|
||||
public static final int DEFAULT_FILE_BLOCK_SIZE = 0x100000;
|
||||
public static final int DEFAULT_MAX_SELECTOR_SIZE = 1024;
|
||||
public static final int DEFAULT_MIN_SELECTOR_TIMEOUT = 10;
|
||||
public static final int INFINITE_TTL = -1;
|
||||
@Native
|
||||
public static boolean INIT_OK = false;
|
||||
protected static final Logger log = LoggerFactory.getLogger(SocketUDT.class);
|
||||
@Native
|
||||
public static final int SIGNATURE_JNI = 20130512;
|
||||
public static final int TIMEOUT_INFINITE = -1;
|
||||
public static long TIMEOUT_NONE = 0L;
|
||||
@Native
|
||||
public static final int UDT_EXCEPT_INDEX = 2;
|
||||
@Native
|
||||
public static final int UDT_READ_INDEX = 0;
|
||||
@Native
|
||||
public static final int UDT_SIZE_COUNT = 3;
|
||||
@Native
|
||||
public static final int UDT_WRITE_INDEX = 1;
|
||||
private volatile int listenQueueSize;
|
||||
@Native
|
||||
private volatile InetSocketAddress localSocketAddress;
|
||||
private volatile boolean messageIsOrdered;
|
||||
private volatile int messageTimeTolive;
|
||||
@Native
|
||||
private final MonitorUDT monitor;
|
||||
@Native
|
||||
private volatile InetSocketAddress remoteSocketAddress;
|
||||
@Native
|
||||
private final int socketAddressFamily;
|
||||
@Native
|
||||
private final int socketID;
|
||||
@Native
|
||||
private final TypeUDT type;
|
||||
|
||||
public static void cleanup() throws ExceptionUDT {
|
||||
SocketUDT.stopClass0();
|
||||
}
|
||||
|
||||
protected static native void epollAdd0(int var0, int var1, int var2) throws ExceptionUDT;
|
||||
|
||||
protected static native int epollCreate0() throws ExceptionUDT;
|
||||
|
||||
protected static native void epollRelease0(int var0) throws ExceptionUDT;
|
||||
|
||||
protected static native void epollRemove0(int var0, int var1) throws ExceptionUDT;
|
||||
|
||||
protected static native void epollUpdate0(int var0, int var1, int var2) throws ExceptionUDT;
|
||||
|
||||
protected static native int epollVerify0(int var0, int var1) throws ExceptionUDT;
|
||||
|
||||
protected static native int epollWait0(int var0, IntBuffer var1, IntBuffer var2, IntBuffer var3, long var4) throws ExceptionUDT;
|
||||
|
||||
protected static native int getSignatureJNI0();
|
||||
|
||||
protected static native void initClass0() throws ExceptionUDT;
|
||||
|
||||
protected static native int receive0(int var0, int var1, byte[] var2) throws ExceptionUDT;
|
||||
|
||||
protected static native int receive1(int var0, int var1, byte[] var2, int var3, int var4) throws ExceptionUDT;
|
||||
|
||||
protected static native int receive2(int var0, int var1, ByteBuffer var2, int var3, int var4) throws ExceptionUDT;
|
||||
|
||||
protected static native long receiveFile0(int var0, String var1, long var2, long var4, int var6) throws ExceptionUDT;
|
||||
|
||||
public static int selectEpoll(int epollId, IntBuffer readBuffer, IntBuffer writeBuffer, IntBuffer sizeBuffer, long millisTimeout) throws ExceptionUDT {
|
||||
assert (readBuffer != null && readBuffer.isDirect());
|
||||
assert (writeBuffer != null && writeBuffer.isDirect());
|
||||
assert (sizeBuffer != null && sizeBuffer.isDirect());
|
||||
return SocketUDT.epollWait0(epollId, readBuffer, writeBuffer, sizeBuffer, millisTimeout);
|
||||
}
|
||||
|
||||
protected static native int send0(int var0, int var1, int var2, boolean var3, byte[] var4) throws ExceptionUDT;
|
||||
|
||||
protected static native int send1(int var0, int var1, int var2, boolean var3, byte[] var4, int var5, int var6) throws ExceptionUDT;
|
||||
|
||||
protected static native int send2(int var0, int var1, int var2, boolean var3, ByteBuffer var4, int var5, int var6) throws ExceptionUDT;
|
||||
|
||||
protected static native long sendFile0(int var0, String var1, long var2, long var4, int var6) throws ExceptionUDT;
|
||||
|
||||
protected static native void stopClass0() throws ExceptionUDT;
|
||||
|
||||
protected static native void testCrashJVM0();
|
||||
|
||||
protected static native void testDirectByteBufferAccess0(ByteBuffer var0);
|
||||
|
||||
protected static native void testDirectIntBufferAccess0(IntBuffer var0);
|
||||
|
||||
protected static native void testDirectIntBufferLoad0(IntBuffer var0);
|
||||
|
||||
protected static native void testEmptyCall0();
|
||||
|
||||
protected static native void testFillArray0(byte[] var0);
|
||||
|
||||
protected static native void testFillBuffer0(ByteBuffer var0);
|
||||
|
||||
protected static native void testGetSetArray0(int[] var0, boolean var1);
|
||||
|
||||
protected static native void testInvalidClose0(int var0) throws ExceptionUDT;
|
||||
|
||||
protected static native void testIterateArray0(Object[] var0);
|
||||
|
||||
protected static native void testIterateSet0(Set<Object> var0);
|
||||
|
||||
protected static native int[] testMakeArray0(int var0);
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public SocketUDT(TypeUDT type) throws ExceptionUDT {
|
||||
Class<SocketUDT> clazz = SocketUDT.class;
|
||||
synchronized (SocketUDT.class) {
|
||||
this.type = type;
|
||||
this.monitor = new MonitorUDT(this);
|
||||
this.socketID = this.initInstance0(type.code);
|
||||
this.socketAddressFamily = 2;
|
||||
this.setDefaultMessageSendMode();
|
||||
// ** MonitorExit[var2_2] (shouldn't be in output)
|
||||
log.debug("init : {}", (Object)this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
protected SocketUDT(TypeUDT type, int socketID) throws ExceptionUDT {
|
||||
Class<SocketUDT> clazz = SocketUDT.class;
|
||||
synchronized (SocketUDT.class) {
|
||||
this.type = type;
|
||||
this.monitor = new MonitorUDT(this);
|
||||
this.socketID = this.initInstance1(socketID);
|
||||
this.socketAddressFamily = 2;
|
||||
this.setDefaultMessageSendMode();
|
||||
// ** MonitorExit[var3_3] (shouldn't be in output)
|
||||
log.debug("init : {}", (Object)this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public SocketUDT accept() throws ExceptionUDT {
|
||||
return this.accept0();
|
||||
}
|
||||
|
||||
protected native SocketUDT accept0() throws ExceptionUDT;
|
||||
|
||||
public void bind(InetSocketAddress localSocketAddress) throws ExceptionUDT, IllegalArgumentException {
|
||||
HelpUDT.checkSocketAddress(localSocketAddress);
|
||||
this.bind0(localSocketAddress);
|
||||
}
|
||||
|
||||
protected native void bind0(InetSocketAddress var1) throws ExceptionUDT;
|
||||
|
||||
public void clearError() {
|
||||
this.clearError0();
|
||||
}
|
||||
|
||||
protected native void clearError0();
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
public void close() throws ExceptionUDT {
|
||||
Class<SocketUDT> clazz = SocketUDT.class;
|
||||
synchronized (SocketUDT.class) {
|
||||
switch (this.status()) {
|
||||
case INIT:
|
||||
case OPENED:
|
||||
case LISTENING:
|
||||
case CONNECTING:
|
||||
case CONNECTED:
|
||||
case BROKEN: {
|
||||
this.close0();
|
||||
log.debug("done : {}", (Object)this);
|
||||
break;
|
||||
}
|
||||
case CLOSING:
|
||||
case CLOSED:
|
||||
case NONEXIST: {
|
||||
log.debug("dead : {}", (Object)this);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
log.error("Invalid socket/status {}/{}", (Object)this, (Object)this.status());
|
||||
}
|
||||
}
|
||||
// ** MonitorExit[var1_1] (shouldn't be in output)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
protected native void close0() throws ExceptionUDT;
|
||||
|
||||
public void connect(InetSocketAddress remoteSocketAddress) throws ExceptionUDT {
|
||||
HelpUDT.checkSocketAddress(remoteSocketAddress);
|
||||
this.connect0(remoteSocketAddress);
|
||||
}
|
||||
|
||||
protected native void connect0(InetSocketAddress var1) throws ExceptionUDT;
|
||||
|
||||
public boolean equals(Object otherSocketUDT) {
|
||||
if (otherSocketUDT instanceof SocketUDT) {
|
||||
SocketUDT other = (SocketUDT)otherSocketUDT;
|
||||
return other.socketID == this.socketID;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void finalize() {
|
||||
try {
|
||||
this.close();
|
||||
super.finalize();
|
||||
}
|
||||
catch (Throwable e) {
|
||||
log.error("failed to close id=" + this.socketID, e);
|
||||
}
|
||||
}
|
||||
|
||||
public ErrorUDT getError() {
|
||||
int code = this.getErrorCode();
|
||||
return ErrorUDT.errorFrom(code);
|
||||
}
|
||||
|
||||
public int getErrorCode() {
|
||||
return this.getErrorCode0();
|
||||
}
|
||||
|
||||
protected native int getErrorCode0();
|
||||
|
||||
public String getErrorMessage() {
|
||||
return this.getErrorMessage0();
|
||||
}
|
||||
|
||||
protected native String getErrorMessage0();
|
||||
|
||||
public int getListenQueueSize() {
|
||||
return this.listenQueueSize;
|
||||
}
|
||||
|
||||
public InetAddress getLocalInetAddress() {
|
||||
try {
|
||||
InetSocketAddress local = this.getLocalSocketAddress();
|
||||
if (local == null) {
|
||||
return null;
|
||||
}
|
||||
return local.getAddress();
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.debug("failed to get local address", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public int getLocalInetPort() {
|
||||
try {
|
||||
InetSocketAddress local = this.getLocalSocketAddress();
|
||||
if (local == null) {
|
||||
return 0;
|
||||
}
|
||||
return local.getPort();
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.debug("failed to get local port", e);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public InetSocketAddress getLocalSocketAddress() throws ExceptionUDT {
|
||||
if (this.hasLoadedLocalSocketAddress()) {
|
||||
return this.localSocketAddress;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean getMessageIsOdered() {
|
||||
return this.messageIsOrdered;
|
||||
}
|
||||
|
||||
public int getMessageTimeTolLive() {
|
||||
return this.messageTimeTolive;
|
||||
}
|
||||
|
||||
public <T> T getOption(OptionUDT<T> option) throws ExceptionUDT {
|
||||
if (option == null) {
|
||||
throw new IllegalArgumentException("option == null");
|
||||
}
|
||||
return (T)this.getOption0(option.code(), option.type());
|
||||
}
|
||||
|
||||
protected native Object getOption0(int var1, Class<?> var2) throws ExceptionUDT;
|
||||
|
||||
public int getReceiveBufferSize() throws ExceptionUDT {
|
||||
int protocolSize = this.getOption(OptionUDT.Protocol_Receive_Buffer_Size);
|
||||
int kernelSize = this.getOption(OptionUDT.System_Receive_Buffer_Size);
|
||||
return Math.min(protocolSize, kernelSize);
|
||||
}
|
||||
|
||||
public InetAddress getRemoteInetAddress() {
|
||||
try {
|
||||
InetSocketAddress remote = this.getRemoteSocketAddress();
|
||||
if (remote == null) {
|
||||
return null;
|
||||
}
|
||||
return remote.getAddress();
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.debug("failed to get remote address", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public int getRemoteInetPort() {
|
||||
try {
|
||||
InetSocketAddress remote = this.getRemoteSocketAddress();
|
||||
if (remote == null) {
|
||||
return 0;
|
||||
}
|
||||
return remote.getPort();
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.debug("failed to get remote port", e);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public InetSocketAddress getRemoteSocketAddress() throws ExceptionUDT {
|
||||
if (this.hasLoadedRemoteSocketAddress()) {
|
||||
return this.remoteSocketAddress;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean getReuseAddress() throws ExceptionUDT {
|
||||
return this.getOption(OptionUDT.Is_Address_Reuse_Enabled);
|
||||
}
|
||||
|
||||
public int getSendBufferSize() throws ExceptionUDT {
|
||||
int protocolSize = this.getOption(OptionUDT.Protocol_Send_Buffer_Size);
|
||||
int kernelSize = this.getOption(OptionUDT.System_Send_Buffer_Size);
|
||||
return Math.min(protocolSize, kernelSize);
|
||||
}
|
||||
|
||||
public int getSoLinger() throws ExceptionUDT {
|
||||
return this.getOption(OptionUDT.Time_To_Linger_On_Close).intValue();
|
||||
}
|
||||
|
||||
public int getSoTimeout() throws ExceptionUDT {
|
||||
int millisTimeout;
|
||||
int receiveTimeout;
|
||||
int sendTimeout = this.getOption(OptionUDT.Send_Timeout);
|
||||
if (sendTimeout != (receiveTimeout = this.getOption(OptionUDT.Receive_Timeout).intValue())) {
|
||||
log.error("sendTimeout != receiveTimeout");
|
||||
millisTimeout = Math.max(sendTimeout, receiveTimeout);
|
||||
} else if (sendTimeout < 0) {
|
||||
millisTimeout = 0;
|
||||
} else if (sendTimeout > 0) {
|
||||
millisTimeout = sendTimeout;
|
||||
} else {
|
||||
log.error("UDT reported unexpected zero timeout");
|
||||
millisTimeout = -1;
|
||||
}
|
||||
return millisTimeout;
|
||||
}
|
||||
|
||||
protected native int getStatus0();
|
||||
|
||||
public int hashCode() {
|
||||
return this.socketID;
|
||||
}
|
||||
|
||||
protected native boolean hasLoadedLocalSocketAddress();
|
||||
|
||||
protected native boolean hasLoadedRemoteSocketAddress();
|
||||
|
||||
public int id() {
|
||||
return this.socketID;
|
||||
}
|
||||
|
||||
protected native int initInstance0(int var1) throws ExceptionUDT;
|
||||
|
||||
protected native int initInstance1(int var1) throws ExceptionUDT;
|
||||
|
||||
public boolean isBlocking() {
|
||||
try {
|
||||
if (this.isOpen()) {
|
||||
boolean isReceiveBlocking = this.getOption(OptionUDT.Is_Receive_Synchronous);
|
||||
boolean isSendBlocking = this.getOption(OptionUDT.Is_Send_Synchronous);
|
||||
return isReceiveBlocking && isSendBlocking;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("failed to get option", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isBound() {
|
||||
switch (this.status()) {
|
||||
case OPENED:
|
||||
case LISTENING:
|
||||
case CONNECTING:
|
||||
case CONNECTED: {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isClosed() {
|
||||
return !this.isOpen();
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
switch (this.status()) {
|
||||
case CONNECTED: {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isNonBlocking() {
|
||||
try {
|
||||
if (this.isOpen()) {
|
||||
boolean isReceiveBlocking = this.getOption(OptionUDT.Is_Receive_Synchronous);
|
||||
boolean isSendBlocking = this.getOption(OptionUDT.Is_Send_Synchronous);
|
||||
return !isReceiveBlocking && !isSendBlocking;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("failed to get option", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
switch (this.status()) {
|
||||
case INIT:
|
||||
case OPENED:
|
||||
case LISTENING:
|
||||
case CONNECTING:
|
||||
case CONNECTED: {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isRendezvous() {
|
||||
try {
|
||||
if (this.isOpen()) {
|
||||
return this.getOption(OptionUDT.Is_Randezvous_Connect_Enabled);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("failed to get option", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void listen(int queueSize) throws ExceptionUDT {
|
||||
if (queueSize <= 0) {
|
||||
throw new IllegalArgumentException("queueSize <= 0");
|
||||
}
|
||||
this.listenQueueSize = queueSize;
|
||||
this.listen0(queueSize);
|
||||
}
|
||||
|
||||
protected native void listen0(int var1) throws ExceptionUDT;
|
||||
|
||||
public MonitorUDT monitor() {
|
||||
return this.monitor;
|
||||
}
|
||||
|
||||
public int receive(byte[] array) throws ExceptionUDT {
|
||||
HelpUDT.checkArray(array);
|
||||
return SocketUDT.receive0(this.socketID, this.type.code, array);
|
||||
}
|
||||
|
||||
public int receive(byte[] array, int position, int limit) throws ExceptionUDT {
|
||||
HelpUDT.checkArray(array);
|
||||
return SocketUDT.receive1(this.socketID, this.type.code, array, position, limit);
|
||||
}
|
||||
|
||||
public int receive(ByteBuffer buffer) throws ExceptionUDT {
|
||||
HelpUDT.checkBuffer(buffer);
|
||||
int position = buffer.position();
|
||||
int limit = buffer.limit();
|
||||
int remaining = buffer.remaining();
|
||||
int sizeReceived = SocketUDT.receive2(this.socketID, this.type.code, buffer, position, limit);
|
||||
if (sizeReceived <= 0) {
|
||||
return sizeReceived;
|
||||
}
|
||||
if (sizeReceived <= remaining) {
|
||||
buffer.position(position + sizeReceived);
|
||||
return sizeReceived;
|
||||
}
|
||||
log.error("sizeReceived > remaining");
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long receiveFile(File file, long offset, long length) throws ExceptionUDT {
|
||||
if (this.type == TypeUDT.DATAGRAM) {
|
||||
throw new IllegalStateException("invalid socket type : " + (Object)((Object)this.type));
|
||||
}
|
||||
if (!(file != null && file.exists() && file.isFile() && file.canWrite())) {
|
||||
throw new IllegalArgumentException("invalid file : " + file);
|
||||
}
|
||||
if (offset < 0L || offset > file.length()) {
|
||||
throw new IllegalArgumentException("invalid offset : " + offset);
|
||||
}
|
||||
if (length < 0L || offset + length > file.length()) {
|
||||
throw new IllegalArgumentException("invalid length : " + length);
|
||||
}
|
||||
String path = file.getAbsolutePath();
|
||||
int block = length > 0x100000L ? 0x100000 : (int)length;
|
||||
return SocketUDT.receiveFile0(this.id(), path, offset, length, block);
|
||||
}
|
||||
|
||||
public int send(byte[] array) throws ExceptionUDT {
|
||||
HelpUDT.checkArray(array);
|
||||
return SocketUDT.send0(this.socketID, this.type.code, this.messageTimeTolive, this.messageIsOrdered, array);
|
||||
}
|
||||
|
||||
public int send(byte[] array, int position, int limit) throws ExceptionUDT {
|
||||
HelpUDT.checkArray(array);
|
||||
return SocketUDT.send1(this.socketID, this.type.code, this.messageTimeTolive, this.messageIsOrdered, array, position, limit);
|
||||
}
|
||||
|
||||
public int send(ByteBuffer buffer) throws ExceptionUDT {
|
||||
HelpUDT.checkBuffer(buffer);
|
||||
int position = buffer.position();
|
||||
int limit = buffer.limit();
|
||||
int remaining = buffer.remaining();
|
||||
int sizeSent = SocketUDT.send2(this.socketID, this.type.code, this.messageTimeTolive, this.messageIsOrdered, buffer, position, limit);
|
||||
if (sizeSent <= 0) {
|
||||
return sizeSent;
|
||||
}
|
||||
if (sizeSent <= remaining) {
|
||||
buffer.position(position + sizeSent);
|
||||
return sizeSent;
|
||||
}
|
||||
log.error("sizeSent > remaining");
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long sendFile(File file, long offset, long length) throws ExceptionUDT {
|
||||
if (this.type == TypeUDT.DATAGRAM) {
|
||||
throw new IllegalStateException("invalid socket type : " + (Object)((Object)this.type));
|
||||
}
|
||||
if (!(file != null && file.exists() && file.isFile() && file.canRead())) {
|
||||
throw new IllegalArgumentException("invalid file : " + file);
|
||||
}
|
||||
if (offset < 0L || offset > file.length()) {
|
||||
throw new IllegalArgumentException("invalid offset : " + offset);
|
||||
}
|
||||
if (length < 0L || offset + length > file.length()) {
|
||||
throw new IllegalArgumentException("invalid length : " + length);
|
||||
}
|
||||
String path = file.getAbsolutePath();
|
||||
int block = length > 0x100000L ? 0x100000 : (int)length;
|
||||
return SocketUDT.sendFile0(this.id(), path, offset, length, block);
|
||||
}
|
||||
|
||||
public void setBlocking(boolean block) throws ExceptionUDT {
|
||||
if (block) {
|
||||
this.setOption(OptionUDT.Is_Receive_Synchronous, Boolean.TRUE);
|
||||
this.setOption(OptionUDT.Is_Send_Synchronous, Boolean.TRUE);
|
||||
} else {
|
||||
this.setOption(OptionUDT.Is_Receive_Synchronous, Boolean.FALSE);
|
||||
this.setOption(OptionUDT.Is_Send_Synchronous, Boolean.FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
public void setDefaultMessageSendMode() {
|
||||
this.setMessageIsOdered(true);
|
||||
this.setMessageTimeTolLive(-1);
|
||||
}
|
||||
|
||||
public void setMessageIsOdered(boolean isOrdered) {
|
||||
this.messageIsOrdered = isOrdered;
|
||||
}
|
||||
|
||||
public void setMessageTimeTolLive(int timeToLive) {
|
||||
this.messageTimeTolive = timeToLive;
|
||||
}
|
||||
|
||||
public <T> void setOption(OptionUDT<T> option, T value) throws ExceptionUDT {
|
||||
if (option == null || value == null) {
|
||||
throw new IllegalArgumentException("option == null || value == null");
|
||||
}
|
||||
this.setOption0(option.code(), option.type(), value);
|
||||
}
|
||||
|
||||
protected native void setOption0(int var1, Class<?> var2, Object var3) throws ExceptionUDT;
|
||||
|
||||
public void setReceiveBufferSize(int size) throws ExceptionUDT {
|
||||
this.setOption(OptionUDT.Protocol_Receive_Buffer_Size, size);
|
||||
this.setOption(OptionUDT.System_Receive_Buffer_Size, size);
|
||||
}
|
||||
|
||||
public void setRendezvous(boolean isOn) throws ExceptionUDT {
|
||||
this.setOption(OptionUDT.Is_Randezvous_Connect_Enabled, isOn);
|
||||
}
|
||||
|
||||
public void setReuseAddress(boolean on) throws ExceptionUDT {
|
||||
this.setOption(OptionUDT.Is_Address_Reuse_Enabled, on);
|
||||
}
|
||||
|
||||
public void setSendBufferSize(int size) throws ExceptionUDT {
|
||||
this.setOption(OptionUDT.Protocol_Send_Buffer_Size, size);
|
||||
this.setOption(OptionUDT.System_Send_Buffer_Size, size);
|
||||
}
|
||||
|
||||
public void setSoLinger(boolean on, int linger) throws ExceptionUDT {
|
||||
if (on) {
|
||||
if (linger <= 0) {
|
||||
throw new IllegalArgumentException("linger <= 0");
|
||||
}
|
||||
this.setOption(OptionUDT.Time_To_Linger_On_Close, new LingerUDT(linger));
|
||||
} else {
|
||||
this.setOption(OptionUDT.Time_To_Linger_On_Close, LingerUDT.LINGER_ZERO);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSoTimeout(int millisTimeout) throws ExceptionUDT {
|
||||
if (millisTimeout < 0) {
|
||||
throw new IllegalArgumentException("timeout < 0");
|
||||
}
|
||||
if (millisTimeout == 0) {
|
||||
millisTimeout = -1;
|
||||
}
|
||||
this.setOption(OptionUDT.Send_Timeout, millisTimeout);
|
||||
this.setOption(OptionUDT.Receive_Timeout, millisTimeout);
|
||||
}
|
||||
|
||||
public StatusUDT status() {
|
||||
return StatusUDT.from(this.getStatus0());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("[id: 0x%08x] %s %s bind=%s:%s peer=%s:%s", new Object[]{this.socketID, this.type, this.status(), this.getLocalInetAddress(), this.getLocalInetPort(), this.getRemoteInetAddress(), this.getRemoteInetPort()});
|
||||
}
|
||||
|
||||
public String toStringMonitor() {
|
||||
try {
|
||||
this.updateMonitor(false);
|
||||
}
|
||||
catch (Exception e) {
|
||||
return "failed to update monitor : " + e.getMessage();
|
||||
}
|
||||
StringBuilder text = new StringBuilder(1024);
|
||||
this.monitor.appendSnapshot(text);
|
||||
return text.toString();
|
||||
}
|
||||
|
||||
public String toStringOptions() {
|
||||
StringBuilder text = new StringBuilder(1024);
|
||||
OptionUDT.appendSnapshot(this, text);
|
||||
return text.toString();
|
||||
}
|
||||
|
||||
public TypeUDT type() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void updateMonitor(boolean makeClear) throws ExceptionUDT {
|
||||
this.updateMonitor0(makeClear);
|
||||
}
|
||||
|
||||
protected native void updateMonitor0(boolean var1) throws ExceptionUDT;
|
||||
|
||||
static {
|
||||
try {
|
||||
String location = ResourceUDT.getLibraryExtractLocation();
|
||||
log.info("library location : {}", (Object)location);
|
||||
String loaderName = ResourceUDT.getLibraryLoaderClassName();
|
||||
log.info("loader provider : {}", (Object)loaderName);
|
||||
Class<?> loaderClass = Class.forName(loaderName);
|
||||
LibraryLoader loaderInstance = (LibraryLoader)loaderClass.newInstance();
|
||||
loaderInstance.load(location);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
log.error("Failed to LOAD native library", e);
|
||||
throw new RuntimeException("load", e);
|
||||
}
|
||||
try {
|
||||
SocketUDT.initClass0();
|
||||
}
|
||||
catch (Throwable e) {
|
||||
log.error("Failed to INIT native library", e);
|
||||
throw new RuntimeException("init", e);
|
||||
}
|
||||
if (20130512 != SocketUDT.getSignatureJNI0()) {
|
||||
log.error("Java/Native SIGNATURE inconsistent");
|
||||
throw new RuntimeException("signature");
|
||||
}
|
||||
INIT_OK = true;
|
||||
log.debug("native library load & init OK");
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public enum StatusUDT {
|
||||
INIT(1),
|
||||
OPENED(2),
|
||||
LISTENING(3),
|
||||
CONNECTING(4),
|
||||
CONNECTED(5),
|
||||
BROKEN(6),
|
||||
CLOSING(7),
|
||||
CLOSED(8),
|
||||
NONEXIST(9),
|
||||
UNKNOWN(100);
|
||||
|
||||
protected static final Logger log;
|
||||
private final int code;
|
||||
|
||||
private StatusUDT(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public static final StatusUDT from(int code) {
|
||||
switch (code) {
|
||||
case 1: {
|
||||
return INIT;
|
||||
}
|
||||
case 2: {
|
||||
return OPENED;
|
||||
}
|
||||
case 3: {
|
||||
return LISTENING;
|
||||
}
|
||||
case 4: {
|
||||
return CONNECTING;
|
||||
}
|
||||
case 5: {
|
||||
return CONNECTED;
|
||||
}
|
||||
case 6: {
|
||||
return BROKEN;
|
||||
}
|
||||
case 7: {
|
||||
return CLOSING;
|
||||
}
|
||||
case 8: {
|
||||
return CLOSED;
|
||||
}
|
||||
case 9: {
|
||||
return NONEXIST;
|
||||
}
|
||||
}
|
||||
log.error("unexpected code={}", (Object)code);
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
static {
|
||||
log = LoggerFactory.getLogger(StatusUDT.class);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt;
|
||||
|
||||
public enum TypeUDT {
|
||||
STREAM(1),
|
||||
DATAGRAM(2);
|
||||
|
||||
protected final int code;
|
||||
|
||||
public int code() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
private TypeUDT(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.anno;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Documented
|
||||
@Target(value={ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR})
|
||||
@Retention(value=RetentionPolicy.RUNTIME)
|
||||
public @interface Native {
|
||||
}
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.anno;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Documented
|
||||
@Target(value={ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR})
|
||||
@Retention(value=RetentionPolicy.RUNTIME)
|
||||
public @interface ThreadSafe {
|
||||
public String value();
|
||||
}
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.ccc;
|
||||
|
||||
import com.barchart.udt.CCC;
|
||||
|
||||
public class UDPBlast
|
||||
extends CCC {
|
||||
static final int iSMSS = 1500;
|
||||
|
||||
public UDPBlast() {
|
||||
this.setCWndSize(83333.0);
|
||||
}
|
||||
|
||||
public void setRate(int mbps) {
|
||||
this.setPacketSndPeriod(12000.0 / (double)mbps);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.lib;
|
||||
|
||||
public interface LibraryLoader {
|
||||
public void load(String var1) throws Exception;
|
||||
}
|
||||
|
||||
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.lib;
|
||||
|
||||
import com.barchart.udt.lib.LibraryLoader;
|
||||
import com.barchart.udt.lib.PluginPropsUDT;
|
||||
import com.barchart.udt.lib.ResourceManagerUDT;
|
||||
import com.barchart.udt.lib.VersionUDT;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class LibraryLoaderUDT
|
||||
implements LibraryLoader {
|
||||
private static final Logger log = LoggerFactory.getLogger(LibraryLoaderUDT.class);
|
||||
|
||||
@Override
|
||||
public void load(String targetFolder) throws Exception {
|
||||
if (!PluginPropsUDT.isSupportedPlatform()) {
|
||||
throw new IllegalStateException("Unsupported platform.");
|
||||
}
|
||||
log.info("Platform supported.");
|
||||
if (targetFolder == null || targetFolder.length() == 0) {
|
||||
throw new IllegalStateException("Invalid extract location.");
|
||||
}
|
||||
try {
|
||||
log.info("Loading release libraries.");
|
||||
this.loadRelease(targetFolder);
|
||||
log.info("Release libraries loaded.");
|
||||
return;
|
||||
}
|
||||
catch (Throwable e) {
|
||||
log.warn("Release libraries missing: {}", (Object)e.getMessage());
|
||||
try {
|
||||
log.info("Loading staging libraries.");
|
||||
this.loadStaging(targetFolder);
|
||||
log.info("Staging libraries loaded.");
|
||||
return;
|
||||
}
|
||||
catch (Throwable e2) {
|
||||
log.warn("Staging libraries missing: {}", (Object)e2.getMessage());
|
||||
try {
|
||||
log.info("Loading testing libraries.");
|
||||
this.loadTesting(targetFolder);
|
||||
log.info("Testing libraries loaded.");
|
||||
return;
|
||||
}
|
||||
catch (Throwable e3) {
|
||||
log.warn("Testing libraries missing: {}", (Object)e3.getMessage());
|
||||
throw new IllegalStateException("Fatal: library load failed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void loadAll(List<String> sourceList, String targetFolder) throws Exception {
|
||||
String targetPath;
|
||||
for (String sourcePath : sourceList) {
|
||||
targetPath = targetFolder + sourcePath;
|
||||
ResourceManagerUDT.extractResource(sourcePath, targetPath);
|
||||
}
|
||||
for (String sourcePath : sourceList) {
|
||||
targetPath = targetFolder + sourcePath;
|
||||
ResourceManagerUDT.systemLoad(targetPath);
|
||||
}
|
||||
}
|
||||
|
||||
protected void loadRelease(String targetFolder) throws Exception {
|
||||
String coreName = VersionUDT.BARCHART_NAME;
|
||||
List<String> sourceList = PluginPropsUDT.currentReleaseLibraries(coreName);
|
||||
this.loadAll(sourceList, targetFolder);
|
||||
}
|
||||
|
||||
protected void loadStaging(String targetFolder) throws Exception {
|
||||
String coreName = VersionUDT.BARCHART_NAME;
|
||||
List<String> sourceList = PluginPropsUDT.currentStagingLibraries(coreName);
|
||||
this.loadAll(sourceList, targetFolder);
|
||||
}
|
||||
|
||||
protected void loadTesting(String targetFolder) throws Exception {
|
||||
String coreName = VersionUDT.BARCHART_ARTIFACT + "-" + PluginPropsUDT.currentNarPath();
|
||||
List<String> sourceList = PluginPropsUDT.currentTestingLibraries(coreName);
|
||||
this.loadAll(sourceList, targetFolder);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.lib;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class PluginPropsUDT {
|
||||
protected static final String AOL_CPP_COMPILER = "cpp.compiler";
|
||||
protected static final String AOL_JNI_EXTENSION = "jni.extension";
|
||||
protected static final String AOL_LINKER_DEPENDENCY = "linker.dependency";
|
||||
protected static final String AOL_SHARED_PREFIX = "shared.prefix";
|
||||
protected static final String EMPTY_VALUE = "";
|
||||
protected static final Logger log = LoggerFactory.getLogger(PluginPropsUDT.class);
|
||||
protected static final String NAR_AOL_PROPERTIES = "aol.properties";
|
||||
protected static final String OS_ARCH = System.getProperty("os.arch");
|
||||
protected static final String OS_NAME = System.getProperty("os.name");
|
||||
protected static final Properties props = new Properties();
|
||||
|
||||
protected static List<String> currentDependencyLibraries() {
|
||||
String[] entryArray;
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
String entryText = PluginPropsUDT.property(PluginPropsUDT.currentNarKeyLinkerDependency());
|
||||
if (entryText == null || entryText.length() == 0) {
|
||||
return list;
|
||||
}
|
||||
for (String entry : entryArray = entryText.split("\\s")) {
|
||||
list.add(entry.trim());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
protected static String currentNarKey() {
|
||||
return PluginPropsUDT.formatNarKey(PluginPropsUDT.narARCH(), PluginPropsUDT.narOS(), PluginPropsUDT.narLINK());
|
||||
}
|
||||
|
||||
protected static String currentNarKey(String suffix) {
|
||||
return PluginPropsUDT.currentNarKey() + "." + suffix;
|
||||
}
|
||||
|
||||
protected static String currentNarKeyCppCompiler() {
|
||||
return PluginPropsUDT.currentNarKey(AOL_CPP_COMPILER);
|
||||
}
|
||||
|
||||
protected static String currentNarKeyJniExtension() {
|
||||
return PluginPropsUDT.currentNarKey(AOL_JNI_EXTENSION);
|
||||
}
|
||||
|
||||
protected static String currentNarKeyLinkerDependency() {
|
||||
return PluginPropsUDT.currentNarKey(AOL_LINKER_DEPENDENCY);
|
||||
}
|
||||
|
||||
protected static String currentNarKeySharedPrefix() {
|
||||
return PluginPropsUDT.currentNarKey(AOL_SHARED_PREFIX);
|
||||
}
|
||||
|
||||
protected static String currentNarPath() {
|
||||
return PluginPropsUDT.formatNarPath(PluginPropsUDT.narARCH(), PluginPropsUDT.narOS(), PluginPropsUDT.narLINK());
|
||||
}
|
||||
|
||||
protected static List<String> currentReleaseLibraries(String coreName) {
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
for (String name : PluginPropsUDT.currentDependencyLibraries()) {
|
||||
String path = PluginPropsUDT.formatMainReleasePath(name);
|
||||
list.add(path);
|
||||
}
|
||||
String name = PluginPropsUDT.formatMainLibraryName(coreName);
|
||||
String path = PluginPropsUDT.formatMainReleasePath(name);
|
||||
list.add(path);
|
||||
return list;
|
||||
}
|
||||
|
||||
protected static List<String> currentStagingLibraries(String coreName) {
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
for (String name : PluginPropsUDT.currentDependencyLibraries()) {
|
||||
String path = PluginPropsUDT.formatTestingDependencyPath(name);
|
||||
list.add(path);
|
||||
}
|
||||
String path = PluginPropsUDT.formatMainStagingPath(coreName);
|
||||
list.add(path);
|
||||
return list;
|
||||
}
|
||||
|
||||
protected static List<String> currentTestingLibraries(String coreName) {
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
for (String name : PluginPropsUDT.currentDependencyLibraries()) {
|
||||
String path = PluginPropsUDT.formatTestingDependencyPath(name);
|
||||
list.add(path);
|
||||
}
|
||||
String path = PluginPropsUDT.formatMainTestingPath(coreName);
|
||||
list.add(path);
|
||||
return list;
|
||||
}
|
||||
|
||||
protected static String formatMainLibraryName(String coreName) {
|
||||
String prefix = PluginPropsUDT.property(PluginPropsUDT.currentNarKeySharedPrefix());
|
||||
String extension = PluginPropsUDT.property(PluginPropsUDT.currentNarKeyJniExtension());
|
||||
return String.format("%s%s.%s", prefix, coreName, extension);
|
||||
}
|
||||
|
||||
protected static String formatMainReleasePath(String name) {
|
||||
String aol = PluginPropsUDT.currentNarPath();
|
||||
return String.format("/lib/%s/jni/%s", aol, name);
|
||||
}
|
||||
|
||||
protected static String formatMainStagingPath(String coreName) {
|
||||
String aol = PluginPropsUDT.currentNarPath();
|
||||
String mainName = PluginPropsUDT.formatMainLibraryName(coreName);
|
||||
return String.format("/%s-%s-jni/lib/%s/jni/%s", coreName, aol, aol, mainName);
|
||||
}
|
||||
|
||||
protected static String formatMainTestingPath(String coreName) {
|
||||
String mainName = PluginPropsUDT.formatMainLibraryName(coreName);
|
||||
return String.format("/%s", mainName);
|
||||
}
|
||||
|
||||
protected static String formatNarKey(String arch, String os, String link) {
|
||||
return String.format("%s.%s.%s", arch, os, link);
|
||||
}
|
||||
|
||||
protected static String formatNarPath(String arch, String os, String link) {
|
||||
return String.format("%s-%s-%s", arch, os, link);
|
||||
}
|
||||
|
||||
protected static String formatTestingDependencyPath(String name) {
|
||||
String aol = PluginPropsUDT.currentNarPath();
|
||||
return String.format("/aol/%s/lib/%s", aol, name);
|
||||
}
|
||||
|
||||
protected static boolean isSupportedPlatform() {
|
||||
return !EMPTY_VALUE.equals(PluginPropsUDT.property(PluginPropsUDT.currentNarKeyCppCompiler()));
|
||||
}
|
||||
|
||||
protected static String narARCH() {
|
||||
return OS_ARCH;
|
||||
}
|
||||
|
||||
protected static String narLINK() {
|
||||
return "gpp";
|
||||
}
|
||||
|
||||
protected static String narOS() {
|
||||
if (OS_NAME.contains("Mac OS X")) {
|
||||
return "MacOSX";
|
||||
}
|
||||
if (OS_NAME.contains("Windows")) {
|
||||
return "Windows";
|
||||
}
|
||||
return OS_NAME;
|
||||
}
|
||||
|
||||
protected static String property(String key) {
|
||||
String value = props.getProperty(key);
|
||||
if (value instanceof String) {
|
||||
return value;
|
||||
}
|
||||
return EMPTY_VALUE;
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
log.info("ARCH/OS/LINK = {}/{}/{}", PluginPropsUDT.narARCH(), PluginPropsUDT.narOS(), PluginPropsUDT.narLINK());
|
||||
log.debug("Loading aol.properties.");
|
||||
InputStream input = PluginPropsUDT.class.getClassLoader().getResourceAsStream(NAR_AOL_PROPERTIES);
|
||||
props.load(input);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
log.error("Failed to load aol.properties.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.lib;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ResourceManagerUDT {
|
||||
protected static final Logger log = LoggerFactory.getLogger(ResourceManagerUDT.class);
|
||||
protected static final int EOF = -1;
|
||||
|
||||
protected static boolean isSameResource(URLConnection conONE, URLConnection conTWO) throws Exception {
|
||||
long timeONE = conONE.getLastModified();
|
||||
long sizeONE = conONE.getContentLength();
|
||||
long timeTWO = conTWO.getLastModified();
|
||||
long sizeTWO = conTWO.getContentLength();
|
||||
return sizeONE == sizeTWO && timeONE == timeTWO;
|
||||
}
|
||||
|
||||
protected static URLConnection fileConnection(File file) throws Exception {
|
||||
URL url = file.toURI().toURL();
|
||||
URLConnection connection = url.openConnection();
|
||||
return connection;
|
||||
}
|
||||
|
||||
protected static long timeStamp(URLConnection connIN) {
|
||||
return connIN.getLastModified();
|
||||
}
|
||||
|
||||
protected static void extractResource(String sourcePath, String targetPath) throws Exception {
|
||||
URL sourceUrl = ResourceManagerUDT.class.getResource(sourcePath);
|
||||
if (sourceUrl == null) {
|
||||
log.warn("classpath resource not found: {}", (Object)sourcePath);
|
||||
throw new IllegalArgumentException("resource not found");
|
||||
}
|
||||
log.debug("sourceURL={} ", (Object)sourceUrl);
|
||||
URLConnection sourceConn = sourceUrl.openConnection();
|
||||
if (sourceConn == null) {
|
||||
log.warn("classpath resource connection not available: {}", (Object)sourcePath);
|
||||
throw new IllegalArgumentException("resource not found");
|
||||
}
|
||||
File targetFile = new File(targetPath).getAbsoluteFile();
|
||||
log.debug("targetFile={} ", (Object)targetFile);
|
||||
File targetFolder = targetFile.getParentFile().getAbsoluteFile();
|
||||
log.debug("targetFolder={} ", (Object)targetFolder);
|
||||
ResourceManagerUDT.ensureTargetFolder(targetFolder);
|
||||
URLConnection targetConn = ResourceManagerUDT.fileConnection(targetFile);
|
||||
if (ResourceManagerUDT.isSameResource(sourceConn, targetConn)) {
|
||||
log.debug("already extracted; sourcePath={} targetPath={}", (Object)sourcePath, (Object)targetPath);
|
||||
return;
|
||||
}
|
||||
log.debug("make new extraction destination for targetPath={}", (Object)targetPath);
|
||||
targetFile.delete();
|
||||
targetFile.createNewFile();
|
||||
long sourceTime = ResourceManagerUDT.timeStamp(sourceConn);
|
||||
BufferedInputStream sourceStream = new BufferedInputStream(sourceUrl.openStream());
|
||||
BufferedOutputStream targetStream = new BufferedOutputStream(new FileOutputStream(targetFile));
|
||||
byte[] array = new byte[65536];
|
||||
int readCount = 0;
|
||||
while ((readCount = ((InputStream)sourceStream).read(array)) != -1) {
|
||||
((OutputStream)targetStream).write(array, 0, readCount);
|
||||
}
|
||||
((OutputStream)targetStream).flush();
|
||||
((InputStream)sourceStream).close();
|
||||
((OutputStream)targetStream).close();
|
||||
targetFile.setLastModified(sourceTime);
|
||||
log.debug("extracted OK; sourcePath={} targetPath={}", (Object)sourcePath, (Object)targetPath);
|
||||
}
|
||||
|
||||
/*
|
||||
* Enabled aggressive block sorting
|
||||
*/
|
||||
protected static void ensureTargetFolder(File folder) throws Exception {
|
||||
if (folder.exists()) {
|
||||
if (folder.isDirectory()) {
|
||||
log.debug("found folder={}", (Object)folder);
|
||||
return;
|
||||
}
|
||||
log.error("not a directory; folder={}", (Object)folder);
|
||||
throw new IllegalArgumentException("extract destination exists, but as a file and not a folder");
|
||||
}
|
||||
boolean isSuccess = folder.mkdirs();
|
||||
if (isSuccess) {
|
||||
log.debug("mkdirs : folder={}", (Object)folder);
|
||||
return;
|
||||
}
|
||||
log.error("mkdirs failure; folder={}", (Object)folder);
|
||||
throw new IllegalStateException("failed to make extract destination folder");
|
||||
}
|
||||
|
||||
protected static void ensureTargetFolder(String targetFolder) throws Exception {
|
||||
File folder = new File(targetFolder).getAbsoluteFile();
|
||||
ResourceManagerUDT.ensureTargetFolder(folder);
|
||||
}
|
||||
|
||||
protected static void systemLoad(String targetPath) throws Exception {
|
||||
File loadFile = new File(targetPath);
|
||||
String loadPath = loadFile.getAbsolutePath();
|
||||
System.load(loadPath);
|
||||
}
|
||||
|
||||
protected static void systemLoad(String sourcePath, String targetPath) throws Exception {
|
||||
ResourceManagerUDT.extractResource(sourcePath, targetPath);
|
||||
ResourceManagerUDT.systemLoad(targetPath);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.lib;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class VersionUDT {
|
||||
protected static final Logger log = LoggerFactory.getLogger(VersionUDT.class);
|
||||
protected static final String PROP_JAVA_VENDOR = "java.vendor";
|
||||
protected static final String PROP_JAVA_VERSION = "java.version";
|
||||
protected static final String PROP_JAVA_VM_NAME = "java.vm.name";
|
||||
public static final String JAVA_VENDOR = System.getProperty("java.vendor");
|
||||
public static final String JAVA_VERSION = System.getProperty("java.version");
|
||||
public static final String JAVA_VM_NAME = System.getProperty("java.vm.name");
|
||||
protected static final String PROP_OS_NAME = "os.name";
|
||||
protected static final String PROP_OS_ARCH = "os.arch";
|
||||
protected static final String PROP_OS_VERSION = "os.version";
|
||||
public static final String OS_NAME = System.getProperty("os.name");
|
||||
public static final String OS_ARCH = System.getProperty("os.arch");
|
||||
public static final String OS_VERSION = System.getProperty("os.version");
|
||||
protected static final String PROP_FILE = "version.properties";
|
||||
protected static final String PROP_UDT_VERSION = "udt.version";
|
||||
protected static final String PROP_BARCHART_NAME = "barchart.name";
|
||||
protected static final String PROP_BARCHART_GROUP = "barchart.groupId";
|
||||
protected static final String PROP_BARCHART_ARTIFACT = "barchart.artifactId";
|
||||
protected static final String PROP_BARCHART_VERSION = "barchart.version";
|
||||
protected static final String PROP_BARCHART_TIMESTAMP = "barchart.timestamp";
|
||||
public static final String UDT_VERSION;
|
||||
public static final String BARCHART_NAME;
|
||||
public static final String BARCHART_GROUP;
|
||||
public static final String BARCHART_ARTIFACT;
|
||||
public static final String BARCHART_VERSION;
|
||||
public static final String BARCHART_TIMESTAMP;
|
||||
static final String UNKNOWN = "UNKNOWN";
|
||||
private static final String SNAPSHOT = "-SNAPSHOT";
|
||||
|
||||
protected static String barchartName(String name) {
|
||||
if (name.contains(SNAPSHOT)) {
|
||||
return name;
|
||||
}
|
||||
return name + SNAPSHOT;
|
||||
}
|
||||
|
||||
protected static void append(StringBuilder text, String EOL) {
|
||||
text.append(PROP_BARCHART_NAME);
|
||||
text.append(" = ");
|
||||
text.append(BARCHART_NAME);
|
||||
text.append(EOL);
|
||||
text.append(PROP_BARCHART_GROUP);
|
||||
text.append(" = ");
|
||||
text.append(BARCHART_GROUP);
|
||||
text.append(EOL);
|
||||
text.append(PROP_BARCHART_ARTIFACT);
|
||||
text.append(" = ");
|
||||
text.append(BARCHART_ARTIFACT);
|
||||
text.append(EOL);
|
||||
text.append(PROP_BARCHART_VERSION);
|
||||
text.append(" = ");
|
||||
text.append(BARCHART_VERSION);
|
||||
text.append(EOL);
|
||||
text.append(PROP_BARCHART_TIMESTAMP);
|
||||
text.append(" = ");
|
||||
text.append(BARCHART_TIMESTAMP);
|
||||
text.append(EOL);
|
||||
text.append(PROP_JAVA_VENDOR);
|
||||
text.append(" = ");
|
||||
text.append(JAVA_VENDOR);
|
||||
text.append(EOL);
|
||||
text.append(PROP_JAVA_VERSION);
|
||||
text.append(" = ");
|
||||
text.append(JAVA_VERSION);
|
||||
text.append(EOL);
|
||||
text.append(PROP_JAVA_VM_NAME);
|
||||
text.append(" = ");
|
||||
text.append(JAVA_VM_NAME);
|
||||
text.append(EOL);
|
||||
text.append(PROP_OS_NAME);
|
||||
text.append(" = ");
|
||||
text.append(OS_NAME);
|
||||
text.append(EOL);
|
||||
text.append(PROP_OS_ARCH);
|
||||
text.append(" = ");
|
||||
text.append(OS_ARCH);
|
||||
text.append(EOL);
|
||||
text.append(PROP_OS_VERSION);
|
||||
text.append(" = ");
|
||||
text.append(OS_VERSION);
|
||||
text.append(EOL);
|
||||
}
|
||||
|
||||
public static final void log() {
|
||||
log.info("\n{}", (Object)VersionUDT.asText());
|
||||
}
|
||||
|
||||
public static final String asText() {
|
||||
StringBuilder text = new StringBuilder(128);
|
||||
text.append("\n");
|
||||
text.append("#######################################");
|
||||
text.append("\n");
|
||||
VersionUDT.append(text, "\n");
|
||||
text.append("#######################################");
|
||||
text.append("\n");
|
||||
text.append("\n");
|
||||
return text.toString();
|
||||
}
|
||||
|
||||
public static final String asHtml() {
|
||||
StringBuilder text = new StringBuilder(128);
|
||||
text.append("<html><pre>");
|
||||
VersionUDT.append(text, "<br>");
|
||||
text.append("</pre></html>");
|
||||
return text.toString();
|
||||
}
|
||||
|
||||
static {
|
||||
String udtVersion = UNKNOWN;
|
||||
String name = UNKNOWN;
|
||||
String group = UNKNOWN;
|
||||
String artifact = UNKNOWN;
|
||||
String version = UNKNOWN;
|
||||
String timestamp = UNKNOWN;
|
||||
try {
|
||||
Properties props = new Properties();
|
||||
InputStream stream = VersionUDT.class.getClassLoader().getResourceAsStream(PROP_FILE);
|
||||
props.load(stream);
|
||||
udtVersion = props.getProperty(PROP_UDT_VERSION);
|
||||
name = props.getProperty(PROP_BARCHART_NAME);
|
||||
group = props.getProperty(PROP_BARCHART_GROUP);
|
||||
artifact = props.getProperty(PROP_BARCHART_ARTIFACT);
|
||||
version = props.getProperty(PROP_BARCHART_VERSION);
|
||||
timestamp = props.getProperty(PROP_BARCHART_TIMESTAMP);
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("failed to load version properties", e);
|
||||
}
|
||||
UDT_VERSION = udtVersion;
|
||||
BARCHART_NAME = VersionUDT.barchartName(name);
|
||||
BARCHART_GROUP = group;
|
||||
BARCHART_ARTIFACT = artifact;
|
||||
BARCHART_VERSION = version;
|
||||
BARCHART_TIMESTAMP = timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.net;
|
||||
|
||||
import com.barchart.udt.ErrorUDT;
|
||||
import com.barchart.udt.ExceptionUDT;
|
||||
|
||||
public class ExceptionReceiveUDT
|
||||
extends ExceptionUDT {
|
||||
protected ExceptionReceiveUDT(int socketID, ErrorUDT error, String comment) {
|
||||
super(socketID, error, comment);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.net;
|
||||
|
||||
import com.barchart.udt.ErrorUDT;
|
||||
import com.barchart.udt.ExceptionUDT;
|
||||
|
||||
public class ExceptionSendUDT
|
||||
extends ExceptionUDT {
|
||||
protected ExceptionSendUDT(int socketID, ErrorUDT error, String comment) {
|
||||
super(socketID, error, comment);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.net;
|
||||
|
||||
import com.barchart.udt.SocketUDT;
|
||||
|
||||
public interface IceCommon {
|
||||
public SocketUDT socketUDT();
|
||||
}
|
||||
|
||||
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.net;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.SocketException;
|
||||
import java.nio.channels.DatagramChannel;
|
||||
|
||||
public interface IceDatagramSocket {
|
||||
public void bind(SocketAddress var1) throws SocketException;
|
||||
|
||||
public void connect(InetAddress var1, int var2);
|
||||
|
||||
public void connect(SocketAddress var1) throws SocketException;
|
||||
|
||||
public void disconnect();
|
||||
|
||||
public boolean isBound();
|
||||
|
||||
public boolean isConnected();
|
||||
|
||||
public InetAddress getInetAddress();
|
||||
|
||||
public int getPort();
|
||||
|
||||
public SocketAddress getRemoteSocketAddress();
|
||||
|
||||
public SocketAddress getLocalSocketAddress();
|
||||
|
||||
public void send(DatagramPacket var1) throws IOException;
|
||||
|
||||
public void receive(DatagramPacket var1) throws IOException;
|
||||
|
||||
public InetAddress getLocalAddress();
|
||||
|
||||
public int getLocalPort();
|
||||
|
||||
public void setSoTimeout(int var1) throws SocketException;
|
||||
|
||||
public int getSoTimeout() throws SocketException;
|
||||
|
||||
public void setSendBufferSize(int var1) throws SocketException;
|
||||
|
||||
public int getSendBufferSize() throws SocketException;
|
||||
|
||||
public void setReceiveBufferSize(int var1) throws SocketException;
|
||||
|
||||
public int getReceiveBufferSize() throws SocketException;
|
||||
|
||||
public void setReuseAddress(boolean var1) throws SocketException;
|
||||
|
||||
public boolean getReuseAddress() throws SocketException;
|
||||
|
||||
public void setBroadcast(boolean var1) throws SocketException;
|
||||
|
||||
public boolean getBroadcast() throws SocketException;
|
||||
|
||||
public void setTrafficClass(int var1) throws SocketException;
|
||||
|
||||
public int getTrafficClass() throws SocketException;
|
||||
|
||||
public void close();
|
||||
|
||||
public boolean isClosed();
|
||||
|
||||
public DatagramChannel getChannel();
|
||||
}
|
||||
|
||||
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.net;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.SocketException;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
|
||||
public interface IceServerSocket {
|
||||
public void bind(SocketAddress var1) throws IOException;
|
||||
|
||||
public void bind(SocketAddress var1, int var2) throws IOException;
|
||||
|
||||
public InetAddress getInetAddress();
|
||||
|
||||
public int getLocalPort();
|
||||
|
||||
public SocketAddress getLocalSocketAddress();
|
||||
|
||||
public Socket accept() throws IOException;
|
||||
|
||||
public void close() throws IOException;
|
||||
|
||||
public ServerSocketChannel getChannel();
|
||||
|
||||
public boolean isBound();
|
||||
|
||||
public boolean isClosed();
|
||||
|
||||
public void setSoTimeout(int var1) throws SocketException;
|
||||
|
||||
public int getSoTimeout() throws IOException;
|
||||
|
||||
public void setReuseAddress(boolean var1) throws SocketException;
|
||||
|
||||
public boolean getReuseAddress() throws SocketException;
|
||||
|
||||
public String toString();
|
||||
|
||||
public void setReceiveBufferSize(int var1) throws SocketException;
|
||||
|
||||
public int getReceiveBufferSize() throws SocketException;
|
||||
|
||||
public void setPerformancePreferences(int var1, int var2, int var3);
|
||||
}
|
||||
|
||||
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.net;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.SocketException;
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
||||
public interface IceSocket {
|
||||
public void connect(SocketAddress var1) throws IOException;
|
||||
|
||||
public void connect(SocketAddress var1, int var2) throws IOException;
|
||||
|
||||
public void bind(SocketAddress var1) throws IOException;
|
||||
|
||||
public InetAddress getInetAddress();
|
||||
|
||||
public InetAddress getLocalAddress();
|
||||
|
||||
public int getPort();
|
||||
|
||||
public int getLocalPort();
|
||||
|
||||
public SocketAddress getRemoteSocketAddress();
|
||||
|
||||
public SocketAddress getLocalSocketAddress();
|
||||
|
||||
public SocketChannel getChannel();
|
||||
|
||||
public InputStream getInputStream() throws IOException;
|
||||
|
||||
public OutputStream getOutputStream() throws IOException;
|
||||
|
||||
public void setTcpNoDelay(boolean var1) throws SocketException;
|
||||
|
||||
public boolean getTcpNoDelay() throws SocketException;
|
||||
|
||||
public void setSoLinger(boolean var1, int var2) throws SocketException;
|
||||
|
||||
public int getSoLinger() throws SocketException;
|
||||
|
||||
public void sendUrgentData(int var1) throws IOException;
|
||||
|
||||
public void setOOBInline(boolean var1) throws SocketException;
|
||||
|
||||
public boolean getOOBInline() throws SocketException;
|
||||
|
||||
public void setSoTimeout(int var1) throws SocketException;
|
||||
|
||||
public int getSoTimeout() throws SocketException;
|
||||
|
||||
public void setSendBufferSize(int var1) throws SocketException;
|
||||
|
||||
public int getSendBufferSize() throws SocketException;
|
||||
|
||||
public void setReceiveBufferSize(int var1) throws SocketException;
|
||||
|
||||
public int getReceiveBufferSize() throws SocketException;
|
||||
|
||||
public void setKeepAlive(boolean var1) throws SocketException;
|
||||
|
||||
public boolean getKeepAlive() throws SocketException;
|
||||
|
||||
public void setTrafficClass(int var1) throws SocketException;
|
||||
|
||||
public int getTrafficClass() throws SocketException;
|
||||
|
||||
public void setReuseAddress(boolean var1) throws SocketException;
|
||||
|
||||
public boolean getReuseAddress() throws SocketException;
|
||||
|
||||
public void close() throws IOException;
|
||||
|
||||
public void shutdownInput() throws IOException;
|
||||
|
||||
public void shutdownOutput() throws IOException;
|
||||
|
||||
public String toString();
|
||||
|
||||
public boolean isConnected();
|
||||
|
||||
public boolean isBound();
|
||||
|
||||
public boolean isClosed();
|
||||
|
||||
public boolean isInputShutdown();
|
||||
|
||||
public boolean isOutputShutdown();
|
||||
|
||||
public void setPerformancePreferences(int var1, int var2, int var3);
|
||||
}
|
||||
|
||||
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.net;
|
||||
|
||||
import com.barchart.udt.ErrorUDT;
|
||||
import com.barchart.udt.SocketUDT;
|
||||
import com.barchart.udt.net.ExceptionReceiveUDT;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.channels.IllegalBlockingModeException;
|
||||
|
||||
public class NetInputStreamUDT
|
||||
extends InputStream {
|
||||
protected final SocketUDT socketUDT;
|
||||
|
||||
public NetInputStreamUDT(SocketUDT socketUDT) {
|
||||
if (!socketUDT.isBlocking()) {
|
||||
throw new IllegalBlockingModeException();
|
||||
}
|
||||
this.socketUDT = socketUDT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
byte[] data = new byte[1];
|
||||
int count = this.read(data);
|
||||
assert (count == 1);
|
||||
return data[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] bytes) throws IOException {
|
||||
return this.read(bytes, 0, bytes.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] bytes, int off, int len) throws IOException {
|
||||
int count = this.socketUDT.receive(bytes, off, off + len);
|
||||
if (count > 0) {
|
||||
assert (count <= len);
|
||||
return count;
|
||||
}
|
||||
if (count == 0) {
|
||||
throw new ExceptionReceiveUDT(this.socketUDT.id(), ErrorUDT.USER_DEFINED_MESSAGE, "UDT receive time out"){};
|
||||
}
|
||||
throw new IllegalStateException("should not happen");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
this.socketUDT.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long skip(long numbytes) throws IOException {
|
||||
int r;
|
||||
long n;
|
||||
if (numbytes <= 0L) {
|
||||
return 0L;
|
||||
}
|
||||
int buflen = (int)Math.min(1024L, n);
|
||||
byte[] data = new byte[buflen];
|
||||
for (n = numbytes; n > 0L && (r = this.read(data, 0, (int)Math.min((long)buflen, n))) >= 0; n -= (long)r) {
|
||||
}
|
||||
return numbytes - n;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mark(int readlimit) {
|
||||
throw new UnsupportedOperationException("mark not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() throws IOException {
|
||||
throw new UnsupportedOperationException("reset not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean markSupported() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.net;
|
||||
|
||||
import com.barchart.udt.ErrorUDT;
|
||||
import com.barchart.udt.SocketUDT;
|
||||
import com.barchart.udt.net.ExceptionSendUDT;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.channels.IllegalBlockingModeException;
|
||||
|
||||
public class NetOutputStreamUDT
|
||||
extends OutputStream {
|
||||
protected final SocketUDT socketUDT;
|
||||
|
||||
public NetOutputStreamUDT(SocketUDT socketUDT) {
|
||||
if (!socketUDT.isBlocking()) {
|
||||
throw new IllegalBlockingModeException();
|
||||
}
|
||||
this.socketUDT = socketUDT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
byte[] bytes = new byte[]{(byte)b};
|
||||
this.write(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] bytes) throws IOException {
|
||||
this.write(bytes, 0, bytes.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] bytes, int off, int len) throws IOException {
|
||||
int count;
|
||||
for (int bytesRemaining = len; bytesRemaining > 0; bytesRemaining -= count) {
|
||||
count = this.socketUDT.send(bytes, off + len - bytesRemaining, off + len);
|
||||
if (count > 0) {
|
||||
continue;
|
||||
}
|
||||
if (count == 0) {
|
||||
throw new ExceptionSendUDT(this.socketUDT.id(), ErrorUDT.USER_DEFINED_MESSAGE, "UDT send time out");
|
||||
}
|
||||
throw new IllegalStateException("Socket has been chaged to non-blocking");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
this.socketUDT.close();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.net;
|
||||
|
||||
import com.barchart.udt.ExceptionUDT;
|
||||
import com.barchart.udt.SocketUDT;
|
||||
import com.barchart.udt.TypeUDT;
|
||||
import com.barchart.udt.net.IceCommon;
|
||||
import com.barchart.udt.net.IceServerSocket;
|
||||
import com.barchart.udt.net.NetSocketUDT;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.SocketException;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
|
||||
public class NetServerSocketUDT
|
||||
extends ServerSocket
|
||||
implements IceServerSocket,
|
||||
IceCommon {
|
||||
protected final SocketUDT socketUDT;
|
||||
|
||||
public NetServerSocketUDT() throws IOException {
|
||||
this(new SocketUDT(TypeUDT.STREAM));
|
||||
this.socketUDT.setBlocking(true);
|
||||
}
|
||||
|
||||
protected NetServerSocketUDT(SocketUDT socketUDT) throws IOException {
|
||||
this.socketUDT = socketUDT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Socket accept() throws IOException {
|
||||
SocketUDT clientUDT = this.socketUDT.accept();
|
||||
return new NetSocketUDT(clientUDT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(SocketAddress endpoint) throws IOException {
|
||||
int backlog = 256;
|
||||
this.bind(endpoint, 256);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(SocketAddress bindpoint, int backlog) throws IOException {
|
||||
if (bindpoint == null) {
|
||||
bindpoint = new InetSocketAddress(0);
|
||||
}
|
||||
if (backlog <= 0) {
|
||||
backlog = 256;
|
||||
}
|
||||
this.socketUDT.bind((InetSocketAddress)bindpoint);
|
||||
this.socketUDT.listen(backlog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
this.socketUDT.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerSocketChannel getChannel() {
|
||||
throw new UnsupportedOperationException("feature not available");
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetAddress getInetAddress() {
|
||||
return this.socketUDT.getLocalInetAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLocalPort() {
|
||||
return this.socketUDT.getLocalInetPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getLocalSocketAddress() {
|
||||
try {
|
||||
return this.socketUDT.getLocalSocketAddress();
|
||||
}
|
||||
catch (ExceptionUDT e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getReceiveBufferSize() throws SocketException {
|
||||
return this.socketUDT.getReceiveBufferSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getReuseAddress() throws SocketException {
|
||||
return this.socketUDT.getReuseAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSoTimeout() throws IOException {
|
||||
return this.socketUDT.getSoTimeout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBound() {
|
||||
return this.socketUDT.isBound();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClosed() {
|
||||
return this.socketUDT.isClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPerformancePreferences(int connectionTime, int latency, int bandwidth) {
|
||||
throw new UnsupportedOperationException("feature not available");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReceiveBufferSize(int size) throws SocketException {
|
||||
this.socketUDT.setReceiveBufferSize(size);
|
||||
this.socketUDT.setSendBufferSize(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReuseAddress(boolean on) throws SocketException {
|
||||
this.socketUDT.setReuseAddress(on);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSoTimeout(int timeout) throws SocketException {
|
||||
this.socketUDT.setSoTimeout(timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketUDT socketUDT() {
|
||||
return this.socketUDT;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,269 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.net;
|
||||
|
||||
import com.barchart.udt.ExceptionUDT;
|
||||
import com.barchart.udt.SocketUDT;
|
||||
import com.barchart.udt.TypeUDT;
|
||||
import com.barchart.udt.anno.ThreadSafe;
|
||||
import com.barchart.udt.net.IceCommon;
|
||||
import com.barchart.udt.net.IceSocket;
|
||||
import com.barchart.udt.net.NetInputStreamUDT;
|
||||
import com.barchart.udt.net.NetOutputStreamUDT;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.SocketException;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class NetSocketUDT
|
||||
extends Socket
|
||||
implements IceSocket,
|
||||
IceCommon {
|
||||
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
@ThreadSafe(value="this")
|
||||
protected InputStream inputStream;
|
||||
@ThreadSafe(value="this")
|
||||
protected OutputStream outputStream;
|
||||
protected final SocketUDT socketUDT;
|
||||
|
||||
public NetSocketUDT() throws ExceptionUDT {
|
||||
this(new SocketUDT(TypeUDT.STREAM));
|
||||
this.socketUDT.setBlocking(true);
|
||||
}
|
||||
|
||||
protected NetSocketUDT(SocketUDT socketUDT) {
|
||||
this.socketUDT = socketUDT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(SocketAddress bindpoint) throws IOException {
|
||||
if (bindpoint == null) {
|
||||
bindpoint = new InetSocketAddress(0);
|
||||
}
|
||||
this.socketUDT.bind((InetSocketAddress)bindpoint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void close() throws IOException {
|
||||
this.socketUDT.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(SocketAddress endpoint) throws IOException {
|
||||
this.socketUDT.connect((InetSocketAddress)endpoint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(SocketAddress endpoint, int timeout) throws IOException {
|
||||
throw new UnsupportedOperationException("feature not available");
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketChannel getChannel() {
|
||||
throw new UnsupportedOperationException("feature not available");
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetAddress getInetAddress() {
|
||||
return this.socketUDT.getRemoteInetAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized InputStream getInputStream() throws IOException {
|
||||
if (this.inputStream == null) {
|
||||
this.inputStream = new NetInputStreamUDT(this.socketUDT);
|
||||
}
|
||||
return this.inputStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getKeepAlive() throws SocketException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetAddress getLocalAddress() {
|
||||
return this.socketUDT.getLocalInetAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLocalPort() {
|
||||
return this.socketUDT.getLocalInetPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getLocalSocketAddress() {
|
||||
try {
|
||||
return this.socketUDT.getLocalSocketAddress();
|
||||
}
|
||||
catch (ExceptionUDT e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getOOBInline() throws SocketException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized OutputStream getOutputStream() throws IOException {
|
||||
if (this.outputStream == null) {
|
||||
this.outputStream = new NetOutputStreamUDT(this.socketUDT);
|
||||
}
|
||||
return this.outputStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPort() {
|
||||
return this.socketUDT.getRemoteInetPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int getReceiveBufferSize() throws SocketException {
|
||||
return this.socketUDT.getReceiveBufferSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getRemoteSocketAddress() {
|
||||
try {
|
||||
return this.socketUDT.getRemoteSocketAddress();
|
||||
}
|
||||
catch (ExceptionUDT e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getReuseAddress() throws SocketException {
|
||||
return this.socketUDT.getReuseAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int getSendBufferSize() throws SocketException {
|
||||
return this.socketUDT.getSendBufferSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSoLinger() throws SocketException {
|
||||
return this.socketUDT.getSoLinger();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int getSoTimeout() throws SocketException {
|
||||
return this.socketUDT.getSoTimeout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getTcpNoDelay() throws SocketException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTrafficClass() throws SocketException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBound() {
|
||||
return this.socketUDT.isBound();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClosed() {
|
||||
return this.socketUDT.isClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return this.socketUDT.isConnected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInputShutdown() {
|
||||
return this.socketUDT.isClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOutputShutdown() {
|
||||
return this.socketUDT.isClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendUrgentData(int data) throws IOException {
|
||||
this.log.debug("Sending urgent data not supported in Barchart UDT...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKeepAlive(boolean on) throws SocketException {
|
||||
this.log.debug("Keep alive not supported in Barchart UDT...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOOBInline(boolean on) throws SocketException {
|
||||
this.log.debug("OOB inline not supported in Barchart UDT...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPerformancePreferences(int connectionTime, int latency, int bandwidth) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void setReceiveBufferSize(int size) throws SocketException {
|
||||
this.socketUDT.setReceiveBufferSize(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReuseAddress(boolean on) throws SocketException {
|
||||
this.socketUDT.setReuseAddress(on);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void setSendBufferSize(int size) throws SocketException {
|
||||
this.socketUDT.setSendBufferSize(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSoLinger(boolean on, int linger) throws SocketException {
|
||||
this.socketUDT.setSoLinger(on, linger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void setSoTimeout(int timeout) throws SocketException {
|
||||
this.socketUDT.setSoTimeout(timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTcpNoDelay(boolean on) throws SocketException {
|
||||
this.log.debug("TCP no delay not supported in Barchart UDT...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTrafficClass(int tc) throws SocketException {
|
||||
this.log.debug("Traffic class not supported in Barchart UDT...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdownInput() throws IOException {
|
||||
this.socketUDT.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdownOutput() throws IOException {
|
||||
this.socketUDT.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketUDT socketUDT() {
|
||||
return this.socketUDT;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.nio;
|
||||
|
||||
import com.barchart.udt.SocketUDT;
|
||||
import com.barchart.udt.TypeUDT;
|
||||
import com.barchart.udt.nio.KindUDT;
|
||||
import com.barchart.udt.nio.SelectorProviderUDT;
|
||||
import java.nio.channels.Channel;
|
||||
|
||||
public interface ChannelUDT
|
||||
extends Channel {
|
||||
public boolean isConnectFinished();
|
||||
|
||||
public KindUDT kindUDT();
|
||||
|
||||
public SelectorProviderUDT providerUDT();
|
||||
|
||||
public SocketUDT socketUDT();
|
||||
|
||||
public TypeUDT typeUDT();
|
||||
|
||||
public int validOps();
|
||||
}
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.nio;
|
||||
|
||||
public enum KindUDT {
|
||||
ACCEPTOR,
|
||||
CONNECTOR,
|
||||
RENDEZVOUS;
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.nio;
|
||||
|
||||
import com.barchart.udt.nio.SocketChannelUDT;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.IllegalBlockingModeException;
|
||||
|
||||
public class NioInputStreamUDT
|
||||
extends InputStream {
|
||||
protected final SocketChannelUDT channel;
|
||||
|
||||
protected NioInputStreamUDT(SocketChannelUDT channel) {
|
||||
if (channel == null) {
|
||||
throw new NullPointerException("channel == null");
|
||||
}
|
||||
if (!channel.isBlocking()) {
|
||||
throw new IllegalBlockingModeException();
|
||||
}
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
byte[] data = new byte[1];
|
||||
this.read(data);
|
||||
return data[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] bytes) throws IOException {
|
||||
return this.read(bytes, 0, bytes.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] bytes, int off, int len) throws IOException {
|
||||
if (len > bytes.length - off) {
|
||||
throw new IndexOutOfBoundsException("len > bytes.length - off");
|
||||
}
|
||||
ByteBuffer buffer = ByteBuffer.wrap(bytes);
|
||||
buffer.position(off);
|
||||
buffer.limit(off + len);
|
||||
int read = this.channel.read(buffer);
|
||||
return read;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long skip(long n) throws IOException {
|
||||
long remaining;
|
||||
int ret;
|
||||
ByteBuffer buffer = ByteBuffer.allocateDirect(32768);
|
||||
for (remaining = n; remaining > 0L; remaining -= (long)ret) {
|
||||
buffer.limit((int)Math.min(remaining, (long)buffer.capacity()));
|
||||
ret = this.channel.read(buffer);
|
||||
if (ret <= 0) break;
|
||||
buffer.rewind();
|
||||
}
|
||||
return n - remaining;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
this.channel.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mark(int readlimit) {
|
||||
throw new UnsupportedOperationException("mark not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() throws IOException {
|
||||
throw new UnsupportedOperationException("reset not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean markSupported() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.nio;
|
||||
|
||||
import com.barchart.udt.nio.SocketChannelUDT;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class NioOutputStreamUDT
|
||||
extends OutputStream {
|
||||
protected final SocketChannelUDT channel;
|
||||
|
||||
protected NioOutputStreamUDT(SocketChannelUDT channel) {
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] bytes, int off, int len) throws IOException {
|
||||
this.channel.write(ByteBuffer.wrap(bytes, off, len));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] bytes) throws IOException {
|
||||
this.channel.write(ByteBuffer.wrap(bytes));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
byte[] bytes = new byte[]{(byte)b};
|
||||
this.channel.write(ByteBuffer.wrap(bytes));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
this.channel.close();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.nio;
|
||||
|
||||
import com.barchart.udt.net.NetServerSocketUDT;
|
||||
import com.barchart.udt.nio.SelectorProviderUDT;
|
||||
import com.barchart.udt.nio.ServerSocketChannelUDT;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
|
||||
public class NioServerSocketUDT
|
||||
extends NetServerSocketUDT {
|
||||
protected final ServerSocketChannelUDT channelUDT;
|
||||
|
||||
protected NioServerSocketUDT(ServerSocketChannelUDT channelUDT) throws IOException {
|
||||
super(channelUDT.socketUDT());
|
||||
this.channelUDT = channelUDT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Socket accept() throws IOException {
|
||||
throw new RuntimeException("feature not available");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(SocketAddress endpoint) throws IOException {
|
||||
SelectorProviderUDT provider = (SelectorProviderUDT)this.channelUDT.provider();
|
||||
int backlog = provider.getAcceptQueueSize();
|
||||
this.bind(endpoint, backlog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerSocketChannelUDT getChannel() {
|
||||
return this.channelUDT;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.nio;
|
||||
|
||||
import com.barchart.udt.ExceptionUDT;
|
||||
import com.barchart.udt.net.NetSocketUDT;
|
||||
import com.barchart.udt.nio.NioInputStreamUDT;
|
||||
import com.barchart.udt.nio.NioOutputStreamUDT;
|
||||
import com.barchart.udt.nio.SocketChannelUDT;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class NioSocketUDT
|
||||
extends NetSocketUDT {
|
||||
protected final SocketChannelUDT channelUDT;
|
||||
|
||||
protected NioSocketUDT(SocketChannelUDT channelUDT) throws ExceptionUDT {
|
||||
super(channelUDT.socketUDT());
|
||||
this.channelUDT = channelUDT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketChannelUDT getChannel() {
|
||||
return this.channelUDT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized InputStream getInputStream() throws IOException {
|
||||
if (this.inputStream == null) {
|
||||
this.inputStream = new NioInputStreamUDT(this.channelUDT);
|
||||
}
|
||||
return this.inputStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized OutputStream getOutputStream() throws IOException {
|
||||
if (this.outputStream == null) {
|
||||
this.outputStream = new NioOutputStreamUDT(this.channelUDT);
|
||||
}
|
||||
return this.outputStream;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.nio;
|
||||
|
||||
import com.barchart.udt.ExceptionUDT;
|
||||
import com.barchart.udt.SocketUDT;
|
||||
import com.barchart.udt.nio.ChannelUDT;
|
||||
import com.barchart.udt.nio.KindUDT;
|
||||
import com.barchart.udt.nio.SelectorProviderUDT;
|
||||
import com.barchart.udt.nio.SocketChannelUDT;
|
||||
|
||||
public class RendezvousChannelUDT
|
||||
extends SocketChannelUDT
|
||||
implements ChannelUDT {
|
||||
protected RendezvousChannelUDT(SelectorProviderUDT provider, SocketUDT socketUDT) throws ExceptionUDT {
|
||||
super(provider, socketUDT);
|
||||
socketUDT.setReuseAddress(true);
|
||||
socketUDT.setRendezvous(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KindUDT kindUDT() {
|
||||
return KindUDT.RENDEZVOUS;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,349 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.nio;
|
||||
|
||||
import com.barchart.udt.EpollUDT;
|
||||
import com.barchart.udt.ExceptionUDT;
|
||||
import com.barchart.udt.OptionUDT;
|
||||
import com.barchart.udt.SocketUDT;
|
||||
import com.barchart.udt.nio.ChannelUDT;
|
||||
import com.barchart.udt.nio.KindUDT;
|
||||
import com.barchart.udt.nio.SelectorUDT;
|
||||
import java.nio.channels.CancelledKeyException;
|
||||
import java.nio.channels.SelectableChannel;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SelectionKeyUDT
|
||||
extends SelectionKey
|
||||
implements Comparable<SelectionKeyUDT> {
|
||||
protected static final int HAS_READ = 17;
|
||||
protected static final int HAS_WRITE = 12;
|
||||
protected static final Logger log = LoggerFactory.getLogger(SelectionKeyUDT.class);
|
||||
private final ChannelUDT channelUDT;
|
||||
private volatile EpollUDT.Opt epollOpt;
|
||||
private volatile int interestOps;
|
||||
private volatile boolean isValid;
|
||||
private volatile int readyOps;
|
||||
private volatile int resultIndex;
|
||||
private final SelectorUDT selectorUDT;
|
||||
|
||||
protected static EpollUDT.Opt from(int interestOps) {
|
||||
boolean hasWrite;
|
||||
boolean hasRead = (interestOps & 0x11) != 0;
|
||||
boolean bl = hasWrite = (interestOps & 0xC) != 0;
|
||||
if (hasRead && hasWrite) {
|
||||
return EpollUDT.Opt.ALL;
|
||||
}
|
||||
if (hasRead) {
|
||||
return EpollUDT.Opt.ERROR_READ;
|
||||
}
|
||||
if (hasWrite) {
|
||||
return EpollUDT.Opt.ERROR_WRITE;
|
||||
}
|
||||
return EpollUDT.Opt.ERROR;
|
||||
}
|
||||
|
||||
public static final String toStringOps(int selectOps) {
|
||||
char A = (0x10 & selectOps) != 0 ? (char)'A' : '-';
|
||||
char C = (8 & selectOps) != 0 ? (char)'C' : '-';
|
||||
char R = (1 & selectOps) != 0 ? (char)'R' : '-';
|
||||
char W = (4 & selectOps) != 0 ? (char)'W' : '-';
|
||||
return String.format("%c%c%c%c", Character.valueOf(A), Character.valueOf(C), Character.valueOf(R), Character.valueOf(W));
|
||||
}
|
||||
|
||||
protected SelectionKeyUDT(SelectorUDT selectorUDT, ChannelUDT channelUDT, Object attachment) {
|
||||
super.attach(attachment);
|
||||
this.selectorUDT = selectorUDT;
|
||||
this.channelUDT = channelUDT;
|
||||
this.makeValid(true);
|
||||
}
|
||||
|
||||
protected void assertValidKey() throws CancelledKeyException {
|
||||
if (this.isValid()) {
|
||||
return;
|
||||
}
|
||||
throw new CancelledKeyException();
|
||||
}
|
||||
|
||||
protected void assertValidOps(int interestOps) {
|
||||
if ((interestOps & ~this.channel().validOps()) != 0) {
|
||||
throw new IllegalArgumentException("invalid interestOps=" + interestOps);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
if (this.isValid()) {
|
||||
this.selector().cancel(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SelectableChannel channel() {
|
||||
return (SelectableChannel)((Object)this.channelUDT);
|
||||
}
|
||||
|
||||
protected ChannelUDT channelUDT() {
|
||||
return this.channelUDT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(SelectionKeyUDT that) {
|
||||
int thatId;
|
||||
int thisId = this.socketId();
|
||||
if (thisId > (thatId = that.socketId())) {
|
||||
return 1;
|
||||
}
|
||||
if (thisId < thatId) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
protected boolean doRead(int resultIndex) {
|
||||
int readyOps = 0;
|
||||
int interestOps = this.interestOps;
|
||||
this.resultIndex = resultIndex;
|
||||
try {
|
||||
if (!this.epollOpt.hasRead()) {
|
||||
if (this.isSocketBroken()) {
|
||||
readyOps = this.channel().validOps();
|
||||
boolean bl = true;
|
||||
return bl;
|
||||
}
|
||||
this.logError("Unexpected error report.");
|
||||
boolean bl = false;
|
||||
return bl;
|
||||
}
|
||||
switch (this.kindUDT()) {
|
||||
case ACCEPTOR: {
|
||||
if ((interestOps & 0x10) != 0) {
|
||||
readyOps = 16;
|
||||
boolean bl = true;
|
||||
return bl;
|
||||
}
|
||||
this.logError("Ready to ACCEPT while not interested.");
|
||||
boolean bl = false;
|
||||
return bl;
|
||||
}
|
||||
case CONNECTOR:
|
||||
case RENDEZVOUS: {
|
||||
if ((interestOps & 1) != 0) {
|
||||
readyOps = 1;
|
||||
boolean bl = true;
|
||||
return bl;
|
||||
}
|
||||
this.logError("Ready to READ while not interested.");
|
||||
boolean bl = false;
|
||||
return bl;
|
||||
}
|
||||
}
|
||||
this.logError("Wrong kind.");
|
||||
boolean bl = false;
|
||||
return bl;
|
||||
}
|
||||
finally {
|
||||
this.readyOps = readyOps;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
protected boolean doWrite(int resultIndex) {
|
||||
int readyOps = 0;
|
||||
int interestOps = this.interestOps;
|
||||
boolean hadReadBeforeWrite = this.resultIndex == resultIndex;
|
||||
try {
|
||||
if (!this.epollOpt.hasWrite()) {
|
||||
if (this.isSocketBroken()) {
|
||||
readyOps = this.channel().validOps();
|
||||
boolean bl = true;
|
||||
return bl;
|
||||
}
|
||||
this.logError("Unexpected error report.");
|
||||
boolean bl = false;
|
||||
return bl;
|
||||
}
|
||||
switch (this.kindUDT()) {
|
||||
case ACCEPTOR: {
|
||||
this.logError("Ready to WRITE for acceptor.");
|
||||
boolean bl = false;
|
||||
return bl;
|
||||
}
|
||||
case CONNECTOR:
|
||||
case RENDEZVOUS: {
|
||||
if (this.channelUDT().isConnectFinished()) {
|
||||
if ((interestOps & 4) != 0) {
|
||||
readyOps = 4;
|
||||
boolean bl = true;
|
||||
return bl;
|
||||
}
|
||||
this.logError("Ready to WRITE when not insterested.");
|
||||
boolean bl = false;
|
||||
return bl;
|
||||
}
|
||||
if ((interestOps & 8) != 0) {
|
||||
readyOps = 8;
|
||||
boolean bl = true;
|
||||
return bl;
|
||||
}
|
||||
this.logError("Ready to CONNECT when not interested.");
|
||||
boolean bl = false;
|
||||
return bl;
|
||||
}
|
||||
}
|
||||
this.logError("Wrong kind.");
|
||||
boolean bl = false;
|
||||
return bl;
|
||||
}
|
||||
finally {
|
||||
this.readyOps = hadReadBeforeWrite ? (this.readyOps |= readyOps) : readyOps;
|
||||
}
|
||||
}
|
||||
|
||||
protected EpollUDT.Opt epollOpt() {
|
||||
return this.epollOpt;
|
||||
}
|
||||
|
||||
protected EpollUDT epollUDT() {
|
||||
return this.selector().epollUDT();
|
||||
}
|
||||
|
||||
public boolean equals(Object otherKey) {
|
||||
if (otherKey instanceof SelectionKeyUDT) {
|
||||
SelectionKeyUDT other = (SelectionKeyUDT)otherKey;
|
||||
return other.socketId() == this.socketId();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean hasError() throws ExceptionUDT {
|
||||
int code = this.socketUDT().getOption(OptionUDT.Epoll_Event_Mask);
|
||||
return EpollUDT.Opt.from(code).hasError();
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.socketId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int interestOps() {
|
||||
return this.interestOps;
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
@Override
|
||||
public SelectionKey interestOps(int interestOps) {
|
||||
this.assertValidKey();
|
||||
this.assertValidOps(interestOps);
|
||||
try {
|
||||
EpollUDT.Opt epollNew = SelectionKeyUDT.from(interestOps);
|
||||
if (epollNew != this.epollOpt) {
|
||||
if (EpollUDT.Opt.ERROR == epollNew) {
|
||||
this.epollUDT().remove(this.socketUDT());
|
||||
} else {
|
||||
this.epollUDT().remove(this.socketUDT());
|
||||
this.epollUDT().add(this.socketUDT(), epollNew);
|
||||
}
|
||||
this.epollOpt = epollNew;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("epoll udpate failure", e);
|
||||
}
|
||||
finally {
|
||||
this.interestOps = interestOps;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
protected boolean isSocketBroken() {
|
||||
switch (this.socketUDT().status()) {
|
||||
case INIT:
|
||||
case OPENED:
|
||||
case LISTENING:
|
||||
case CONNECTING:
|
||||
case CONNECTED: {
|
||||
return false;
|
||||
}
|
||||
case BROKEN:
|
||||
case CLOSING:
|
||||
case CLOSED:
|
||||
case NONEXIST: {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
this.logError("Unknown socket status.");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return this.isValid;
|
||||
}
|
||||
|
||||
protected KindUDT kindUDT() {
|
||||
return this.channelUDT.kindUDT();
|
||||
}
|
||||
|
||||
protected void logError(String comment) {
|
||||
String message = "logic error : \n\t" + this;
|
||||
log.warn(message, new Exception("" + comment));
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
protected void makeValid(boolean isValid) {
|
||||
try {
|
||||
if (isValid) {
|
||||
this.epollOpt = EpollUDT.Opt.ERROR;
|
||||
this.epollUDT().add(this.socketUDT(), this.epollOpt);
|
||||
} else {
|
||||
this.epollUDT().remove(this.socketUDT());
|
||||
}
|
||||
}
|
||||
catch (Throwable e) {
|
||||
log.error("Epoll failure.", e);
|
||||
}
|
||||
finally {
|
||||
this.isValid = isValid;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readyOps() {
|
||||
return this.readyOps;
|
||||
}
|
||||
|
||||
protected void readyOps(int ops) {
|
||||
this.readyOps = ops;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SelectorUDT selector() {
|
||||
return this.selectorUDT;
|
||||
}
|
||||
|
||||
protected int socketId() {
|
||||
return this.socketUDT().id();
|
||||
}
|
||||
|
||||
protected SocketUDT socketUDT() {
|
||||
return this.channelUDT.socketUDT();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("[id: 0x%08x] poll=%s ready=%s inter=%s %s %s %s bind=%s:%s peer=%s:%s", new Object[]{this.socketUDT().id(), this.epollOpt, SelectionKeyUDT.toStringOps(this.readyOps), SelectionKeyUDT.toStringOps(this.interestOps), this.channelUDT.typeUDT(), this.channelUDT.kindUDT(), this.socketUDT().status(), this.socketUDT().getLocalInetAddress(), this.socketUDT().getLocalInetPort(), this.socketUDT().getRemoteInetAddress(), this.socketUDT().getRemoteInetPort()});
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.nio;
|
||||
|
||||
import com.barchart.udt.SocketUDT;
|
||||
import com.barchart.udt.TypeUDT;
|
||||
import com.barchart.udt.nio.RendezvousChannelUDT;
|
||||
import com.barchart.udt.nio.SelectorUDT;
|
||||
import com.barchart.udt.nio.ServerSocketChannelUDT;
|
||||
import com.barchart.udt.nio.SocketChannelUDT;
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.DatagramChannel;
|
||||
import java.nio.channels.Pipe;
|
||||
import java.nio.channels.spi.SelectorProvider;
|
||||
|
||||
public class SelectorProviderUDT
|
||||
extends SelectorProvider {
|
||||
public static final SelectorProviderUDT DATAGRAM = new SelectorProviderUDT(TypeUDT.DATAGRAM);
|
||||
public static final SelectorProviderUDT STREAM = new SelectorProviderUDT(TypeUDT.STREAM);
|
||||
private volatile int acceptQueueSize = 256;
|
||||
private volatile int maxSelectorSize = 1024;
|
||||
private final TypeUDT type;
|
||||
|
||||
public static SelectorProviderUDT from(TypeUDT type) {
|
||||
switch (type) {
|
||||
case DATAGRAM: {
|
||||
return DATAGRAM;
|
||||
}
|
||||
case STREAM: {
|
||||
return STREAM;
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("wrong type=" + (Object)((Object)type));
|
||||
}
|
||||
|
||||
public final TypeUDT type() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
protected SelectorProviderUDT(TypeUDT type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getAcceptQueueSize() {
|
||||
return this.acceptQueueSize;
|
||||
}
|
||||
|
||||
public int getMaxSelectorSize() {
|
||||
return this.maxSelectorSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatagramChannel openDatagramChannel() throws IOException {
|
||||
throw new UnsupportedOperationException("feature not available");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pipe openPipe() throws IOException {
|
||||
throw new UnsupportedOperationException("feature not available");
|
||||
}
|
||||
|
||||
public RendezvousChannelUDT openRendezvousChannel() throws IOException {
|
||||
SocketUDT socketUDT = new SocketUDT(this.type);
|
||||
return new RendezvousChannelUDT(this, socketUDT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SelectorUDT openSelector() throws IOException {
|
||||
return new SelectorUDT(this, this.maxSelectorSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerSocketChannelUDT openServerSocketChannel() throws IOException {
|
||||
SocketUDT serverSocketUDT = new SocketUDT(this.type);
|
||||
return new ServerSocketChannelUDT(this, serverSocketUDT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketChannelUDT openSocketChannel() throws IOException {
|
||||
SocketUDT socketUDT = new SocketUDT(this.type);
|
||||
return new SocketChannelUDT(this, socketUDT);
|
||||
}
|
||||
|
||||
public void setAcceptQueueSize(int queueSize) {
|
||||
this.acceptQueueSize = queueSize;
|
||||
}
|
||||
|
||||
public void setMaxSelectorSize(int selectorSize) {
|
||||
this.maxSelectorSize = selectorSize;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,277 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.nio;
|
||||
|
||||
import com.barchart.udt.EpollUDT;
|
||||
import com.barchart.udt.ExceptionUDT;
|
||||
import com.barchart.udt.SocketUDT;
|
||||
import com.barchart.udt.TypeUDT;
|
||||
import com.barchart.udt.nio.ChannelUDT;
|
||||
import com.barchart.udt.nio.SelectionKeyUDT;
|
||||
import com.barchart.udt.nio.SelectorProviderUDT;
|
||||
import com.barchart.udt.util.HelpUDT;
|
||||
import java.io.IOException;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.channels.ClosedSelectorException;
|
||||
import java.nio.channels.IllegalSelectorException;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.Selector;
|
||||
import java.nio.channels.spi.AbstractSelectableChannel;
|
||||
import java.nio.channels.spi.AbstractSelector;
|
||||
import java.nio.channels.spi.SelectorProvider;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SelectorUDT
|
||||
extends AbstractSelector {
|
||||
protected static final Logger log = LoggerFactory.getLogger(SelectorUDT.class);
|
||||
private final EpollUDT epollUDT = new EpollUDT();
|
||||
public final int maximimSelectorSize;
|
||||
private final IntBuffer readBuffer;
|
||||
private final ConcurrentMap<Integer, SelectionKeyUDT> registeredKeyMap = new ConcurrentHashMap<Integer, SelectionKeyUDT>();
|
||||
private final Set<? extends SelectionKey> registeredKeySet = HelpUDT.unmodifiableSet(this.registeredKeyMap.values());
|
||||
private volatile int resultIndex;
|
||||
private final ConcurrentMap<SelectionKeyUDT, SelectionKeyUDT> selectedKeyMap = new ConcurrentHashMap<SelectionKeyUDT, SelectionKeyUDT>();
|
||||
private final Set<? extends SelectionKey> selectedKeySet = HelpUDT.ungrowableSet(this.selectedKeyMap.keySet());
|
||||
private final Lock selectLock = new ReentrantLock();
|
||||
private final IntBuffer sizeBuffer;
|
||||
private final ConcurrentMap<SelectionKeyUDT, SelectionKeyUDT> terminatedKeyMap = new ConcurrentHashMap<SelectionKeyUDT, SelectionKeyUDT>();
|
||||
private volatile int wakeupBaseCount;
|
||||
private volatile int wakeupStepCount;
|
||||
private final IntBuffer writeBuffer;
|
||||
|
||||
protected static Selector open(TypeUDT type) throws IOException {
|
||||
SelectorProviderUDT provider;
|
||||
switch (type) {
|
||||
case DATAGRAM: {
|
||||
provider = SelectorProviderUDT.DATAGRAM;
|
||||
break;
|
||||
}
|
||||
case STREAM: {
|
||||
provider = SelectorProviderUDT.STREAM;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
log.error("unsupported type={}", (Object)type);
|
||||
throw new IOException("unsupported type");
|
||||
}
|
||||
}
|
||||
return provider.openSelector();
|
||||
}
|
||||
|
||||
protected SelectorUDT(SelectorProvider provider, int maximumSelectorSize) throws ExceptionUDT {
|
||||
super(provider);
|
||||
this.maximimSelectorSize = maximumSelectorSize;
|
||||
this.readBuffer = HelpUDT.newDirectIntBufer(maximumSelectorSize);
|
||||
this.writeBuffer = HelpUDT.newDirectIntBufer(maximumSelectorSize);
|
||||
this.sizeBuffer = HelpUDT.newDirectIntBufer(3);
|
||||
}
|
||||
|
||||
protected void cancel(SelectionKeyUDT keyUDT) {
|
||||
this.terminatedKeyMap.putIfAbsent(keyUDT, keyUDT);
|
||||
}
|
||||
|
||||
protected void doCancel() {
|
||||
if (this.terminatedKeyMap.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Iterator iterator = this.terminatedKeyMap.values().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
SelectionKeyUDT keyUDT = (SelectionKeyUDT)iterator.next();
|
||||
iterator.remove();
|
||||
if (!keyUDT.isValid()) continue;
|
||||
keyUDT.makeValid(false);
|
||||
this.registeredKeyMap.remove(keyUDT.socketId());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
protected int doEpollEnter(long millisTimeout) throws IOException {
|
||||
if (!this.isOpen()) {
|
||||
log.error("slector is closed");
|
||||
throw new ClosedSelectorException();
|
||||
}
|
||||
try {
|
||||
this.selectLock.lock();
|
||||
int n = this.doEpollExclusive(millisTimeout);
|
||||
return n;
|
||||
}
|
||||
finally {
|
||||
this.selectLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
protected int doEpollExclusive(long millisTimeout) throws IOException {
|
||||
this.doCancel();
|
||||
this.doEpollSelect(millisTimeout);
|
||||
this.doResults();
|
||||
return this.selectedKeyMap.size();
|
||||
}
|
||||
|
||||
protected int doEpollSelect(long millisTimeout) throws ExceptionUDT {
|
||||
this.wakeupMarkBase();
|
||||
int readyCount = 0;
|
||||
if (millisTimeout < 0L) {
|
||||
while ((readyCount = this.doEpollSelectUDT(10L)) <= 0 && !this.wakeupIsPending()) {
|
||||
}
|
||||
} else if (millisTimeout > 0L) {
|
||||
while ((readyCount = this.doEpollSelectUDT(10L)) <= 0 && !this.wakeupIsPending() && (millisTimeout -= 10L) > 0L) {
|
||||
}
|
||||
} else {
|
||||
readyCount = this.doEpollSelectUDT(0L);
|
||||
}
|
||||
return readyCount;
|
||||
}
|
||||
|
||||
protected int doEpollSelectUDT(long timeout) throws ExceptionUDT {
|
||||
return SocketUDT.selectEpoll(this.epollUDT.id(), this.readBuffer, this.writeBuffer, this.sizeBuffer, timeout);
|
||||
}
|
||||
|
||||
protected void doResults() {
|
||||
int resultIndex = this.resultIndex++;
|
||||
this.doResultsRead(resultIndex);
|
||||
this.doResultsWrite(resultIndex);
|
||||
}
|
||||
|
||||
protected void doResultsRead(int resultIndex) {
|
||||
int readSize = this.sizeBuffer.get(0);
|
||||
for (int index = 0; index < readSize; ++index) {
|
||||
int socketId = this.readBuffer.get(index);
|
||||
SelectionKeyUDT keyUDT = (SelectionKeyUDT)this.registeredKeyMap.get(socketId);
|
||||
if (keyUDT == null) {
|
||||
this.logSocketId("missing from read ", socketId);
|
||||
continue;
|
||||
}
|
||||
if (!keyUDT.doRead(resultIndex)) continue;
|
||||
this.selectedKeyMap.putIfAbsent(keyUDT, keyUDT);
|
||||
}
|
||||
}
|
||||
|
||||
protected void doResultsWrite(int resultIndex) {
|
||||
int writeSize = this.sizeBuffer.get(1);
|
||||
for (int index = 0; index < writeSize; ++index) {
|
||||
int socketId = this.writeBuffer.get(index);
|
||||
SelectionKeyUDT keyUDT = (SelectionKeyUDT)this.registeredKeyMap.get(socketId);
|
||||
if (keyUDT == null) {
|
||||
this.logSocketId("missing from write", socketId);
|
||||
continue;
|
||||
}
|
||||
if (!keyUDT.doWrite(resultIndex)) continue;
|
||||
this.selectedKeyMap.putIfAbsent(keyUDT, keyUDT);
|
||||
}
|
||||
}
|
||||
|
||||
protected EpollUDT epollUDT() {
|
||||
return this.epollUDT;
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
@Override
|
||||
protected void implCloseSelector() throws IOException {
|
||||
this.wakeup();
|
||||
try {
|
||||
this.selectLock.lock();
|
||||
for (SelectionKeyUDT keyUDT : this.registeredKeyMap.values()) {
|
||||
this.cancel(keyUDT);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
this.selectLock.unlock();
|
||||
}
|
||||
this.doCancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SelectionKey> keys() {
|
||||
if (!this.isOpen()) {
|
||||
throw new ClosedSelectorException();
|
||||
}
|
||||
return this.registeredKeySet;
|
||||
}
|
||||
|
||||
protected void logSocketId(String title, int socketId) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("{} {}", (Object)title, (Object)String.format("[id: 0x%08x]", socketId));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SelectionKey register(AbstractSelectableChannel channel, int interestOps, Object attachment) {
|
||||
if (this.registeredKeyMap.size() >= this.maximimSelectorSize) {
|
||||
log.error("reached maximimSelectorSize");
|
||||
throw new IllegalSelectorException();
|
||||
}
|
||||
if (!(channel instanceof ChannelUDT)) {
|
||||
log.error("!(channel instanceof ChannelUDT)");
|
||||
throw new IllegalSelectorException();
|
||||
}
|
||||
ChannelUDT channelUDT = (ChannelUDT)((Object)channel);
|
||||
Integer socketId = channelUDT.socketUDT().id();
|
||||
SelectionKeyUDT keyUDT = (SelectionKeyUDT)this.registeredKeyMap.get(socketId);
|
||||
if (keyUDT == null) {
|
||||
keyUDT = new SelectionKeyUDT(this, channelUDT, attachment);
|
||||
this.registeredKeyMap.putIfAbsent(socketId, keyUDT);
|
||||
keyUDT = (SelectionKeyUDT)this.registeredKeyMap.get(socketId);
|
||||
}
|
||||
keyUDT.interestOps(interestOps);
|
||||
return keyUDT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int select() throws IOException {
|
||||
return this.select(0L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int select(long timeout) throws IOException {
|
||||
if (timeout < 0L) {
|
||||
throw new IllegalArgumentException("negative timeout");
|
||||
}
|
||||
if (timeout > 0L) {
|
||||
return this.doEpollEnter(timeout);
|
||||
}
|
||||
return this.doEpollEnter(-1L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SelectionKey> selectedKeys() {
|
||||
if (!this.isOpen()) {
|
||||
throw new ClosedSelectorException();
|
||||
}
|
||||
return this.selectedKeySet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int selectNow() throws IOException {
|
||||
return this.doEpollEnter(SocketUDT.TIMEOUT_NONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Selector wakeup() {
|
||||
++this.wakeupStepCount;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected boolean wakeupIsPending() {
|
||||
return this.wakeupBaseCount != this.wakeupStepCount;
|
||||
}
|
||||
|
||||
protected void wakeupMarkBase() {
|
||||
this.wakeupBaseCount = this.wakeupStepCount;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.nio;
|
||||
|
||||
import com.barchart.udt.SocketUDT;
|
||||
import com.barchart.udt.TypeUDT;
|
||||
import com.barchart.udt.anno.ThreadSafe;
|
||||
import com.barchart.udt.nio.ChannelUDT;
|
||||
import com.barchart.udt.nio.KindUDT;
|
||||
import com.barchart.udt.nio.NioServerSocketUDT;
|
||||
import com.barchart.udt.nio.SelectorProviderUDT;
|
||||
import com.barchart.udt.nio.SocketChannelUDT;
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ServerSocketChannelUDT
|
||||
extends ServerSocketChannel
|
||||
implements ChannelUDT {
|
||||
protected static final Logger log = LoggerFactory.getLogger(ServerSocketChannelUDT.class);
|
||||
@ThreadSafe(value="this")
|
||||
protected NioServerSocketUDT socketAdapter;
|
||||
protected final SocketUDT socketUDT;
|
||||
|
||||
protected ServerSocketChannelUDT(SelectorProviderUDT provider, SocketUDT socketUDT) {
|
||||
super(provider);
|
||||
this.socketUDT = socketUDT;
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
@Override
|
||||
public SocketChannelUDT accept() throws IOException {
|
||||
try {
|
||||
this.begin();
|
||||
SocketUDT clientUDT = this.socketUDT.accept();
|
||||
if (clientUDT == null) {
|
||||
SocketChannelUDT socketChannelUDT = null;
|
||||
return socketChannelUDT;
|
||||
}
|
||||
SocketChannelUDT socketChannelUDT = new SocketChannelUDT(this.providerUDT(), clientUDT, clientUDT.isConnected());
|
||||
return socketChannelUDT;
|
||||
}
|
||||
finally {
|
||||
this.end(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void implCloseSelectableChannel() throws IOException {
|
||||
this.socketUDT.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void implConfigureBlocking(boolean block) throws IOException {
|
||||
this.socketUDT.setBlocking(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnectFinished() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KindUDT kindUDT() {
|
||||
return KindUDT.ACCEPTOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SelectorProviderUDT providerUDT() {
|
||||
return (SelectorProviderUDT)super.provider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized NioServerSocketUDT socket() {
|
||||
if (this.socketAdapter == null) {
|
||||
try {
|
||||
this.socketAdapter = new NioServerSocketUDT(this);
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.error("failed to make socket", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return this.socketAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketUDT socketUDT() {
|
||||
return this.socketUDT;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.socketUDT.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeUDT typeUDT() {
|
||||
return this.providerUDT().type();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,344 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.nio;
|
||||
|
||||
import com.barchart.udt.ExceptionUDT;
|
||||
import com.barchart.udt.SocketUDT;
|
||||
import com.barchart.udt.TypeUDT;
|
||||
import com.barchart.udt.anno.ThreadSafe;
|
||||
import com.barchart.udt.nio.ChannelUDT;
|
||||
import com.barchart.udt.nio.KindUDT;
|
||||
import com.barchart.udt.nio.NioSocketUDT;
|
||||
import com.barchart.udt.nio.SelectorProviderUDT;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.nio.channels.ConnectionPendingException;
|
||||
import java.nio.channels.IllegalBlockingModeException;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.nio.channels.UnresolvedAddressException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SocketChannelUDT
|
||||
extends SocketChannel
|
||||
implements ChannelUDT {
|
||||
protected static final Logger log = LoggerFactory.getLogger(SocketChannelUDT.class);
|
||||
protected final Object connectLock = new Object();
|
||||
protected volatile boolean isBlockingMode = this.isBlocking();
|
||||
protected volatile boolean isConnectFinished;
|
||||
protected volatile boolean isConnectionPending;
|
||||
@ThreadSafe(value="this")
|
||||
protected NioSocketUDT socketAdapter;
|
||||
protected final SocketUDT socketUDT;
|
||||
|
||||
protected SocketChannelUDT(SelectorProviderUDT provider, SocketUDT socketUDT) throws ExceptionUDT {
|
||||
super(provider);
|
||||
this.socketUDT = socketUDT;
|
||||
this.socketUDT.setBlocking(true);
|
||||
}
|
||||
|
||||
protected SocketChannelUDT(SelectorProviderUDT provider, SocketUDT socketUDT, boolean isConnected) throws ExceptionUDT {
|
||||
this(provider, socketUDT);
|
||||
if (isConnected) {
|
||||
this.isConnectFinished = true;
|
||||
this.isConnectionPending = false;
|
||||
} else {
|
||||
this.isConnectFinished = false;
|
||||
this.isConnectionPending = true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
@Override
|
||||
public boolean connect(SocketAddress remote) throws IOException {
|
||||
if (!this.isOpen()) {
|
||||
throw new ClosedChannelException();
|
||||
}
|
||||
if (this.isConnected()) {
|
||||
log.warn("already connected; ignoring remote={}", (Object)remote);
|
||||
return true;
|
||||
}
|
||||
if (remote == null) {
|
||||
this.close();
|
||||
log.error("remote == null");
|
||||
throw new NullPointerException();
|
||||
}
|
||||
InetSocketAddress remoteSocket = (InetSocketAddress)remote;
|
||||
if (remoteSocket.isUnresolved()) {
|
||||
log.error("can not use unresolved address: remote={}", (Object)remote);
|
||||
this.close();
|
||||
throw new UnresolvedAddressException();
|
||||
}
|
||||
if (this.isBlocking()) {
|
||||
Object object = this.connectLock;
|
||||
synchronized (object) {
|
||||
try {
|
||||
if (this.isConnectionPending) {
|
||||
this.close();
|
||||
throw new ConnectionPendingException();
|
||||
}
|
||||
this.isConnectionPending = true;
|
||||
this.begin();
|
||||
this.socketUDT.connect(remoteSocket);
|
||||
}
|
||||
finally {
|
||||
this.end(true);
|
||||
this.isConnectionPending = false;
|
||||
this.connectLock.notifyAll();
|
||||
}
|
||||
}
|
||||
return this.socketUDT.isConnected();
|
||||
}
|
||||
if (!this.isRegistered()) {
|
||||
log.error("UDT channel is in NON blocking mode; must register with a selector before trying to connect(); socketId=" + this.socketUDT.id());
|
||||
throw new IllegalBlockingModeException();
|
||||
}
|
||||
Object object = this.connectLock;
|
||||
synchronized (object) {
|
||||
if (this.isConnectionPending) {
|
||||
this.close();
|
||||
log.error("connection already in progress");
|
||||
throw new ConnectionPendingException();
|
||||
}
|
||||
this.isConnectFinished = false;
|
||||
this.isConnectionPending = true;
|
||||
this.socketUDT.connect(remoteSocket);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
@Override
|
||||
public boolean finishConnect() throws IOException {
|
||||
if (!this.isOpen()) {
|
||||
throw new ClosedChannelException();
|
||||
}
|
||||
if (this.isBlocking()) {
|
||||
Object object = this.connectLock;
|
||||
synchronized (object) {
|
||||
while (this.isConnectionPending) {
|
||||
try {
|
||||
this.connectLock.wait();
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.isConnected()) {
|
||||
this.isConnectFinished = true;
|
||||
this.isConnectionPending = false;
|
||||
return true;
|
||||
}
|
||||
log.error("connect failure : {}", (Object)this.socketUDT);
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void implCloseSelectableChannel() throws IOException {
|
||||
this.socketUDT.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void implConfigureBlocking(boolean block) throws IOException {
|
||||
this.socketUDT.setBlocking(block);
|
||||
this.isBlockingMode = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return this.socketUDT.isConnected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnectFinished() {
|
||||
return this.isConnectFinished;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnectionPending() {
|
||||
return this.isConnectionPending;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KindUDT kindUDT() {
|
||||
return KindUDT.CONNECTOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SelectorProviderUDT providerUDT() {
|
||||
return (SelectorProviderUDT)super.provider();
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
@Override
|
||||
public int read(ByteBuffer buffer) throws IOException {
|
||||
int sizeReceived;
|
||||
int remaining = buffer.remaining();
|
||||
if (remaining <= 0) {
|
||||
return 0;
|
||||
}
|
||||
SocketUDT socket = this.socketUDT;
|
||||
boolean isBlocking = this.isBlockingMode;
|
||||
try {
|
||||
if (isBlocking) {
|
||||
this.begin();
|
||||
}
|
||||
if (buffer.isDirect()) {
|
||||
sizeReceived = socket.receive(buffer);
|
||||
} else {
|
||||
int limit;
|
||||
int position;
|
||||
byte[] array = buffer.array();
|
||||
sizeReceived = socket.receive(array, position = buffer.position(), limit = buffer.limit());
|
||||
if (0 < sizeReceived && sizeReceived <= remaining) {
|
||||
buffer.position(position + sizeReceived);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (isBlocking) {
|
||||
this.end(true);
|
||||
}
|
||||
}
|
||||
if (sizeReceived < 0) {
|
||||
return 0;
|
||||
}
|
||||
if (sizeReceived == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (sizeReceived <= remaining) {
|
||||
return sizeReceived;
|
||||
}
|
||||
log.error("should not happen: socket={}", (Object)socket);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long read(ByteBuffer[] dsts, int offset, int length) throws IOException {
|
||||
throw new RuntimeException("feature not available");
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized NioSocketUDT socket() {
|
||||
if (this.socketAdapter == null) {
|
||||
try {
|
||||
this.socketAdapter = new NioSocketUDT(this);
|
||||
}
|
||||
catch (ExceptionUDT e) {
|
||||
log.error("failed to make socket", e);
|
||||
}
|
||||
}
|
||||
return this.socketAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketUDT socketUDT() {
|
||||
return this.socketUDT;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.socketUDT.toString();
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
* Enabled aggressive block sorting
|
||||
* Enabled unnecessary exception pruning
|
||||
* Enabled aggressive exception aggregation
|
||||
*/
|
||||
@Override
|
||||
public int write(ByteBuffer buffer) throws IOException {
|
||||
if (buffer == null) {
|
||||
throw new NullPointerException("buffer == null");
|
||||
}
|
||||
int remaining = buffer.remaining();
|
||||
if (remaining <= 0) {
|
||||
return 0;
|
||||
}
|
||||
SocketUDT socket = this.socketUDT;
|
||||
boolean isBlocking = this.isBlockingMode;
|
||||
int sizeSent = 0;
|
||||
int ret = 0;
|
||||
try {
|
||||
if (isBlocking) {
|
||||
this.begin();
|
||||
}
|
||||
if (buffer.isDirect()) {
|
||||
do {
|
||||
if ((ret = socket.send(buffer)) <= 0) continue;
|
||||
sizeSent += ret;
|
||||
} while (buffer.hasRemaining() && isBlocking);
|
||||
} else {
|
||||
byte[] array = buffer.array();
|
||||
int position = buffer.position();
|
||||
int limit = buffer.limit();
|
||||
do {
|
||||
if (0 >= (ret = socket.send(array, position, limit)) || ret > remaining) continue;
|
||||
sizeSent += ret;
|
||||
buffer.position(position += ret);
|
||||
} while (buffer.hasRemaining() && isBlocking);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (isBlocking) {
|
||||
this.end(true);
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
return 0;
|
||||
}
|
||||
if (ret == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (sizeSent <= remaining) {
|
||||
return sizeSent;
|
||||
}
|
||||
log.error("should not happen; socket={}", (Object)socket);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long write(ByteBuffer[] bufferArray, int offset, int length) throws IOException {
|
||||
try {
|
||||
long total = 0L;
|
||||
for (int index = offset; index < offset + length; ++index) {
|
||||
int processed;
|
||||
ByteBuffer buffer = bufferArray[index];
|
||||
int remaining = buffer.remaining();
|
||||
if (remaining == (processed = this.write(buffer))) {
|
||||
total += (long)processed;
|
||||
continue;
|
||||
}
|
||||
throw new IllegalStateException("failed to write buffer in array");
|
||||
}
|
||||
return total;
|
||||
}
|
||||
catch (Throwable e) {
|
||||
throw new IOException("failed to write buffer array", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeUDT typeUDT() {
|
||||
return this.providerUDT().type();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketChannelUDT bind(SocketAddress localAddress) throws IOException {
|
||||
this.socketUDT.bind((InetSocketAddress)localAddress);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.util;
|
||||
|
||||
import com.barchart.udt.EpollUDT;
|
||||
import com.barchart.udt.util.UngrowableSet;
|
||||
import com.barchart.udt.util.UnmodifiableSet;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.IntBuffer;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class HelpUDT {
|
||||
protected static final Logger log = LoggerFactory.getLogger(EpollUDT.class);
|
||||
|
||||
public static long md5sum(String text) {
|
||||
byte[] defaultBytes = text.getBytes();
|
||||
try {
|
||||
MessageDigest algorithm = MessageDigest.getInstance("MD5");
|
||||
algorithm.reset();
|
||||
algorithm.update(defaultBytes);
|
||||
byte[] digest = algorithm.digest();
|
||||
ByteBuffer buffer = ByteBuffer.wrap(digest);
|
||||
return buffer.getLong();
|
||||
}
|
||||
catch (NoSuchAlgorithmException e) {
|
||||
log.error("md5 failed", e);
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
public static final IntBuffer newDirectIntBufer(int capacity) {
|
||||
return ByteBuffer.allocateDirect(capacity * 4).order(ByteOrder.nativeOrder()).asIntBuffer();
|
||||
}
|
||||
|
||||
public static <E> Set<E> ungrowableSet(Set<E> set) {
|
||||
return new UngrowableSet<E>(set);
|
||||
}
|
||||
|
||||
public static <E> Set<E> unmodifiableSet(Collection<E> values) {
|
||||
return new UnmodifiableSet<E>(values);
|
||||
}
|
||||
|
||||
private HelpUDT() {
|
||||
}
|
||||
|
||||
public static final void checkBuffer(ByteBuffer buffer) {
|
||||
if (buffer == null) {
|
||||
throw new IllegalArgumentException("buffer == null");
|
||||
}
|
||||
if (!buffer.isDirect()) {
|
||||
throw new IllegalArgumentException("must use DirectByteBuffer");
|
||||
}
|
||||
}
|
||||
|
||||
public static final void checkArray(byte[] array) {
|
||||
if (array == null) {
|
||||
throw new IllegalArgumentException("array == null");
|
||||
}
|
||||
}
|
||||
|
||||
public static String constantFieldName(Class<?> klaz, Object instance) {
|
||||
Field[] filedArray;
|
||||
for (Field field : filedArray = klaz.getDeclaredFields()) {
|
||||
boolean isConstant;
|
||||
int modifiers = field.getModifiers();
|
||||
boolean bl = isConstant = Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers);
|
||||
if (!isConstant) continue;
|
||||
try {
|
||||
if (instance != field.get(null)) continue;
|
||||
return field.getName();
|
||||
}
|
||||
catch (Throwable e) {
|
||||
log.debug("", e);
|
||||
}
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
public static void checkSocketAddress(InetSocketAddress socketAddress) {
|
||||
if (socketAddress == null) {
|
||||
throw new IllegalArgumentException("socketAddress can't be null");
|
||||
}
|
||||
if (socketAddress.isUnresolved()) {
|
||||
throw new IllegalArgumentException("socketAddress is unresolved : " + socketAddress + " : check your DNS settings");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.util;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
class UngrowableSet<E>
|
||||
implements Set<E> {
|
||||
private final Set<E> set;
|
||||
|
||||
UngrowableSet(Set<E> set) {
|
||||
this.set = set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(E o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends E> coll) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
this.set.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
return this.set.contains(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> coll) {
|
||||
return this.set.containsAll(coll);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return ((Object)this.set).equals(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ((Object)this.set).hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.set.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
return this.set.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
return this.set.remove(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> coll) {
|
||||
return this.set.removeAll(coll);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> coll) {
|
||||
return this.set.retainAll(coll);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return this.set.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
return this.set.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T[] toArray(T[] a) {
|
||||
return this.set.toArray(a);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.set.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.barchart.udt.util;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
class UnmodifiableSet<E>
|
||||
implements Set<E> {
|
||||
private final Collection<E> values;
|
||||
|
||||
UnmodifiableSet(Collection<E> values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(E e) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends E> c) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
return this.values.contains(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
return this.values.containsAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.values.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
return this.values.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> c) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return this.values.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
return this.values.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T[] toArray(T[] a) {
|
||||
return this.values.toArray(a);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.google.common.annotations;
|
||||
|
||||
import com.google.common.annotations.GwtCompatible;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(value=RetentionPolicy.CLASS)
|
||||
@Target(value={ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE})
|
||||
@Documented
|
||||
@GwtCompatible
|
||||
public @interface Beta {
|
||||
}
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.google.common.annotations;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(value=RetentionPolicy.CLASS)
|
||||
@Target(value={ElementType.TYPE, ElementType.METHOD})
|
||||
@Documented
|
||||
@GwtCompatible
|
||||
public @interface GwtCompatible {
|
||||
public boolean serializable() default false;
|
||||
|
||||
public boolean emulated() default false;
|
||||
}
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.google.common.annotations;
|
||||
|
||||
import com.google.common.annotations.GwtCompatible;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(value=RetentionPolicy.CLASS)
|
||||
@Target(value={ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD})
|
||||
@Documented
|
||||
@GwtCompatible
|
||||
public @interface GwtIncompatible {
|
||||
public String value();
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user