Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
JDChain
Utils
提交
51042eea
U
Utils
项目概览
JDChain
/
Utils
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
Utils
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
51042eea
编写于
1月 29, 2021
作者:
H
huanghaiquan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
optimized BytesUtils;
上级
9de865b6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
14 addition
and
14 deletion
+14
-14
utils-common/src/main/java/utils/io/BytesUtils.java
utils-common/src/main/java/utils/io/BytesUtils.java
+14
-14
未找到文件。
utils-common/src/main/java/utils/io/BytesUtils.java
浏览文件 @
51042eea
...
...
@@ -43,7 +43,7 @@ public class BytesUtils {
*
* @param bytes1 要比较的数组1;
* @param bytes2 要比较的数组2;
* @return boolean
* @return boolean
*/
public
static
boolean
equals
(
byte
[]
bytes1
,
byte
[]
bytes2
)
{
if
(
bytes1
==
bytes2
)
{
...
...
@@ -64,7 +64,8 @@ public class BytesUtils {
}
/**
* 验证两个数组中,从指定偏移开始的相同长度的数据是否相等;<p>
* 验证两个数组中,从指定偏移开始的相同长度的数据是否相等;
* <p>
*
* 注:<br>
* 要比较的两个数组中任意一个的有效长度不满足指定的长度时,返回 false;
...
...
@@ -83,8 +84,8 @@ public class BytesUtils {
if
(
bytes1
==
null
||
bytes2
==
null
)
{
return
false
;
}
//验证两个数组的有效长度;
//
验证两个数组的有效长度;
if
(
bytes1
.
length
>=
(
offset1
+
length
)
&&
bytes2
.
length
>=
(
offset2
+
length
))
{
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
if
(
bytes1
[
offset1
+
i
]
!=
bytes2
[
offset2
+
i
])
{
...
...
@@ -93,7 +94,7 @@ public class BytesUtils {
}
return
true
;
}
return
false
;
}
...
...
@@ -315,7 +316,7 @@ public class BytesUtils {
bytes
[
offset
]
=
(
byte
)
((
value
>>>
8
)
&
0x00FF
);
bytes
[
offset
+
1
]
=
(
byte
)
(
value
&
0x00FF
);
}
public
static
void
toBytes_BigEndian
(
short
value
,
byte
[]
bytes
,
int
offset
)
{
bytes
[
offset
]
=
(
byte
)
((
value
>>>
8
)
&
0x00FF
);
bytes
[
offset
+
1
]
=
(
byte
)
(
value
&
0x00FF
);
...
...
@@ -633,15 +634,14 @@ public class BytesUtils {
public
static
int
readInt
(
InputStream
in
)
{
try
{
int
value
=
0
;
int
v
;
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
v
=
in
.
read
();
if
(
v
<
0
)
{
throw
new
IllegalDataException
(
"No enough data to read as integer from the specified input stream!"
);
}
value
=
value
|
((
v
&
0xFF
)
<<
(
8
*
(
3
-
i
)));
int
v0
=
in
.
read
();
int
v1
=
in
.
read
();
int
v2
=
in
.
read
();
int
v3
=
in
.
read
();
if
(
v0
<
0
||
v1
<
0
||
v2
<
0
||
v3
<
0
)
{
throw
new
IllegalDataException
(
"No enough data to read as integer from the specified input stream!"
);
}
value
=
(
v0
<<
24
)
|
(
v1
<<
16
)
|
(
v2
<<
8
)
|
v3
;
return
value
;
}
catch
(
IOException
e
)
{
throw
new
RuntimeIOException
(
e
.
getMessage
(),
e
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录