Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
X
XXL-JOB
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
靳帅
XXL-JOB
Commits
f48ac05c
提交
f48ac05c
authored
7月 25, 2016
作者:
xueli.xue
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
coding
上级
a6968642
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
213 行增加
和
7 行删除
+213
-7
ByteHexConverter.java
...src/main/java/com/xxl/job/core/util/ByteHexConverter.java
+18
-0
ByteReadFactory.java
.../src/main/java/com/xxl/job/core/util/ByteReadFactory.java
+98
-0
ByteWriteFactory.java
...src/main/java/com/xxl/job/core/util/ByteWriteFactory.java
+64
-0
XxlJobNetCommUtil.java
...rc/main/java/com/xxl/job/core/util/XxlJobNetCommUtil.java
+32
-6
pom.xml
xxl-job-executor-example/pom.xml
+1
-1
没有找到文件。
xxl-job-core/src/main/java/com/xxl/job/core/util/ByteHexConverter.java
浏览文件 @
f48ac05c
...
...
@@ -43,6 +43,24 @@ public class ByteHexConverter {
return
new
BigInteger
(
val
,
radix
).
toByteArray
();
}
/**
* get length of string
* @param str
* @return
*/
public
static
int
getByteLen
(
String
str
){
if
(
str
==
null
||
str
.
length
()==
0
)
{
return
0
;
}
// because java base on unicode, and one china code's length is one, but it's cost 2 bytes.
int
len
=
str
.
getBytes
().
length
*
2
;
if
(
len
%
4
!=
0
)
{
// Length is best in multiples of four
len
=
(
len
/
4
+
1
)
*
4
;
}
return
len
;
}
public
static
void
main
(
String
[]
args
)
{
// hex - byte[] 方案A:位移
String
temp
=
"1111111111113d1f3a51sd3f1a32sd1f32as1df2a13sd21f3a2s1df32a13sd2f123s2a3d13fa13sd9999999999"
;
...
...
xxl-job-core/src/main/java/com/xxl/job/core/util/ByteReadFactory.java
0 → 100644
浏览文件 @
f48ac05c
package
com
.
xxl
.
job
.
core
.
util
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.UnsupportedEncodingException
;
/**
* byte read util
* @author xuxueli 2015-11-15 03:50:10
*/
public
class
ByteReadFactory
{
private
static
transient
Logger
logger
=
LoggerFactory
.
getLogger
(
ByteReadFactory
.
class
);
private
int
m_iPos
;
private
int
m_iReqLen
;
private
byte
[]
m_byte
=
null
;
public
ByteReadFactory
(
byte
[]
hexBytes
){
m_iPos
=
0
;
m_byte
=
hexBytes
;
m_iReqLen
=
m_byte
.
length
;
}
public
int
readInt
()
{
if
(
m_iPos
+
4
>
m_iReqLen
)
{
return
0
;
}
int
iInt
=
(
m_byte
[
m_iPos
]
&
0xff
)
|
((
m_byte
[
m_iPos
+
1
]
&
0xff
)
<<
8
)
|
((
m_byte
[
m_iPos
+
2
]
&
0xff
)
<<
16
)
|
((
m_byte
[
m_iPos
+
3
]
&
0xff
)
<<
24
);
m_iPos
+=
4
;
return
iInt
;
}
public
long
readLong
()
{
if
(
m_iPos
+
8
>
m_iReqLen
)
{
return
0
;
}
long
iLong
=
(
m_byte
[
m_iPos
]
&
0xff
)
|
((
m_byte
[
m_iPos
+
1
]
&
0xff
)
<<
8
)
|
((
m_byte
[
m_iPos
+
2
]
&
0xff
)
<<
16
)
|
((
m_byte
[
m_iPos
+
3
]
&
0xff
)
<<
24
)
|
((
m_byte
[
m_iPos
+
4
]
&
0xff
)
<<
32
)
|
((
m_byte
[
m_iPos
+
5
]
&
0xff
)
<<
40
)
|
((
m_byte
[
m_iPos
+
6
]
&
0xff
)
<<
48
)
|
((
m_byte
[
m_iPos
+
7
]
&
0xff
)
<<
56
);
m_iPos
+=
8
;
return
iLong
;
}
public
String
readString
(
int
length
)
{
if
(
m_iPos
+
length
>
m_iReqLen
)
{
logger
.
error
(
"[byte stream factory read string length error.]"
);
return
""
;
}
int
index
=
0
;
for
(
index
=
0
;
index
<
length
;
index
++)
{
if
(
m_byte
[
m_iPos
+
index
]
==
0
)
{
break
;
}
}
String
msg
=
""
;
try
{
msg
=
new
String
(
m_byte
,
m_iPos
,
index
,
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
e
)
{
logger
.
error
(
"[byte stream factory read string exception.]"
,
e
);
}
m_iPos
+=
length
;
return
msg
;
}
public
byte
[]
read
(
int
length
)
{
if
(
m_iPos
+
length
>
m_iReqLen
||
length
<=
0
)
{
logger
.
error
(
"[byte stream factory read string length error.]"
);
return
null
;
}
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
if
(
m_byte
[
m_iPos
+
i
]
==
0
)
{
break
;
}
}
byte
[]
result
=
new
byte
[
length
];
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
result
[
i
]
=
m_byte
[
m_iPos
+
i
];
}
m_iPos
+=
length
;
return
result
;
}
public
byte
[]
readByteAll
()
{
return
read
(
m_iReqLen
-
m_iPos
);
}
}
xxl-job-core/src/main/java/com/xxl/job/core/util/ByteWriteFactory.java
0 → 100644
浏览文件 @
f48ac05c
package
com
.
xxl
.
job
.
core
.
util
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.UnsupportedEncodingException
;
import
java.nio.ByteBuffer
;
/**
* byte write util
* @author xuxueli 2015-11-15 03:49:36
*/
public
class
ByteWriteFactory
{
private
static
transient
Logger
logger
=
LoggerFactory
.
getLogger
(
ByteWriteFactory
.
class
);
private
ByteBuffer
m_byteBuf
=
null
;
public
ByteWriteFactory
()
{
m_byteBuf
=
ByteBuffer
.
allocate
(
1024
*
4
);
}
public
void
writeInt
(
int
intValue
)
{
byte
[]
intBytes
=
new
byte
[
4
];
for
(
int
index
=
0
;
index
<
4
;
index
++)
{
intBytes
[
index
]
=
(
byte
)
(
intValue
>>>
(
index
*
8
));
}
m_byteBuf
.
put
(
intBytes
);
}
public
void
write
(
int
[]
intArr
)
{
for
(
int
index
=
0
;
index
<
intArr
.
length
;
index
++)
{
writeInt
(
intArr
[
index
]);
}
}
public
void
write
(
byte
[]
byteArr
)
{
m_byteBuf
.
put
(
byteArr
);
}
public
void
writeString
(
String
value
,
int
length
)
{
byte
[]
bytes
=
new
byte
[
length
];
if
(
value
!=
null
&&
value
.
trim
().
length
()
>
0
)
{
try
{
byte
[]
infoBytes
=
value
.
getBytes
(
"UTF-8"
);
int
len
=
infoBytes
.
length
<
length
?
infoBytes
.
length
:
length
;
System
.
arraycopy
(
infoBytes
,
0
,
bytes
,
0
,
len
);
}
catch
(
UnsupportedEncodingException
e
)
{
logger
.
error
(
"[response stream factory encoding exception.]"
,
e
);
}
}
m_byteBuf
.
put
(
bytes
);
}
public
byte
[]
getBytes
()
{
m_byteBuf
.
flip
();
if
(
m_byteBuf
.
limit
()
==
0
)
{
return
null
;
}
byte
[]
bytes
=
new
byte
[
m_byteBuf
.
limit
()];
m_byteBuf
.
get
(
bytes
);
return
bytes
;
}
}
xxl-job-core/src/main/java/com/xxl/job/core/util/XxlJobNetCommUtil.java
浏览文件 @
f48ac05c
...
...
@@ -30,14 +30,25 @@ public class XxlJobNetCommUtil {
// hex param key
public
static
final
String
HEX
=
"hex"
;
/**
* format object to hex-json
* @param obj
* @return
*/
public
static
String
formatObj2HexJson
(
Object
obj
){
// obj to json
String
json
=
JacksonUtil
.
writeValueAsString
(
obj
);
String
hex
=
ByteHexConverter
.
byte2hex
(
json
.
getBytes
());
int
len
=
ByteHexConverter
.
getByteLen
(
json
);
// json to byte[]
ByteWriteFactory
byteWriteFactory
=
new
ByteWriteFactory
();
byteWriteFactory
.
writeInt
(
len
);
byteWriteFactory
.
writeString
(
json
,
len
);
byte
[]
bytes
=
byteWriteFactory
.
getBytes
();
// byte to hex
String
hex
=
ByteHexConverter
.
byte2hex
(
bytes
);
return
hex
;
}
...
...
@@ -48,14 +59,25 @@ public class XxlJobNetCommUtil {
* @return
*/
public
static
<
T
>
T
parseHexJson2Obj
(
String
hex
,
Class
<
T
>
clazz
){
String
json
=
new
String
(
ByteHexConverter
.
hex2Byte
(
hex
));
// hex to byte[]
byte
[]
bytes
=
ByteHexConverter
.
hex2Byte
(
hex
);
// byte[] to json
ByteReadFactory
byteReadFactory
=
new
ByteReadFactory
(
bytes
);
String
json
=
byteReadFactory
.
readString
(
byteReadFactory
.
readInt
());
// json to obj
T
obj
=
JacksonUtil
.
readValue
(
json
,
clazz
);
return
obj
;
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
parseHexJson2Obj
(
"7B2274696D657374616D70223A313436393432323136303032362C22616374696F6E223A2252554E222C226A6F6247726F7570223A2264656661756C7473222C226A6F624E616D65223A22323031363037323530393030353730363632222C226578656375746F7248616E646C6572223A2264656D6F4A6F6248616E646C6572222C226578656375746F72506172616D73223A2231303030303030222C22676C7565537769746368223A66616C73652C226C6F6741646472657373223A2231302E35372E3132332E32383A38383838222C226C6F674964223A3138382C226C6F674461746554696D223A302C22737461747573223A2253554343455353222C226D7367223A6E756C6C7D"
,
RequestModel
.
class
));
System
.
out
.
println
(
parseHexJson2Obj
(
"7B22737461747573223A2253554343455353222C226D7367223A6E756C6C7D"
,
ResponseModel
.
class
));
RequestModel
requestModel
=
new
RequestModel
();
requestModel
.
setJobGroup
(
"group"
);
String
hex
=
formatObj2HexJson
(
requestModel
);
System
.
out
.
println
(
hex
);
System
.
out
.
println
(
parseHexJson2Obj
(
hex
,
RequestModel
.
class
));
}
/**
...
...
@@ -94,8 +116,12 @@ public class XxlJobNetCommUtil {
EntityUtils
.
consume
(
entity
);
// i do not know why
responseHex
=
responseHex
.
replace
(
"\n"
,
""
);
responseHex
=
responseHex
.
replace
(
"\r"
,
""
);
//responseHex = responseHex.replace("\n", "");
//responseHex = responseHex.replace("\r", "");
if
(
responseHex
!=
null
)
{
responseHex
=
responseHex
.
trim
();
}
// parse hex-json to ResponseModel
ResponseModel
responseModel
=
XxlJobNetCommUtil
.
parseHexJson2Obj
(
responseHex
,
ResponseModel
.
class
);
...
...
xxl-job-executor-example/pom.xml
浏览文件 @
f48ac05c
...
...
@@ -101,7 +101,7 @@
<artifactId>
maven-war-plugin
</artifactId>
<version>
2.2
</version>
<configuration>
<archiveClasses>
tru
e
</archiveClasses>
<archiveClasses>
fals
e
</archiveClasses>
</configuration>
</plugin>
<plugin>
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论