FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
UnpackABFile/src/unpack/UnpackABFile.java at master · space9bug/UnpackABFile · GitHub
space9bug
/
UnpackABFile
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
UnpackABFile
/
src
/
unpack
/
UnpackABFile.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
99 lines (84 loc) · 2.94 KB
Breadcrumbs
UnpackABFile
/
src
/
unpack
/
UnpackABFile.java
Copy path
File metadata and controls
99 lines (84 loc) · 2.94 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
91
92
93
94
95
96
97
98
99
package
unpack
;
import
java
.
io
.
File
;
import
java
.
io
.
FileInputStream
;
import
java
.
io
.
FileOutputStream
;
import
java
.
io
.
InputStream
;
import
java
.
io
.
OutputStream
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
List
;
import
java
.
util
.
regex
.
Matcher
;
import
java
.
util
.
regex
.
Pattern
;
import
org
.
apache
.
commons
.
compress
.
archivers
.
tar
.
TarArchiveEntry
;
import
org
.
apache
.
commons
.
compress
.
archivers
.
tar
.
TarArchiveInputStream
;
import
org
.
apache
.
commons
.
compress
.
utils
.
IOUtils
;
import
org
.
apache
.
commons
.
lang3
.
StringUtils
;
import
org
.
nick
.
abe
.
Main
;
public
class
UnpackABFile
{
public
static
int
BUFFER_SIZE
=
2048
;
public
static
void
createDirectory
(
String
outputDir
,
String
subDir
) {
File
file
=
new
File
(
outputDir
);
if
(!(
subDir
==
null
||
subDir
.
trim
().
equals
(
""
))) {
// 子目录不为空
file
=
new
File
(
outputDir
+
File
.
separator
+
subDir
);
}
if
(!
file
.
exists
()) {
file
.
mkdirs
();
}
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
String
abPath
=
args
[
0
];
String
dbPath
=
args
[
1
];
String
abPassword
=
args
[
2
];
String
tempPath
=
dbPath
+
File
.
separator
+
"temp"
;
createDirectory
(
tempPath
,
null
);
String
[]
arg
= {
"unpack"
,
abPath
,
tempPath
+
File
.
separator
+
"soul.tar"
,
abPassword
};
Main
.
main
(
arg
);
System
.
out
.
println
(
unTar
(
tempPath
+
File
.
separator
+
"soul.tar"
,
dbPath
));
System
.
out
.
println
(
"解压完成"
);
}
public
static
List
<
String
>
unTar
(
File
tarFile
,
String
destDir
)
throws
Exception
{
if
(
StringUtils
.
isBlank
(
destDir
)) {
destDir
=
tarFile
.
getParent
();
}
destDir
=
destDir
.
endsWith
(
File
.
separator
) ?
destDir
:
destDir
+
File
.
separator
;
return
unTar
(
new
FileInputStream
(
tarFile
),
destDir
);
}
private
static
List
<
String
>
unTar
(
InputStream
inputStream
,
String
destDir
)
throws
Exception
{
String
match
=
"apps/cn.soulapp.android/f/"
;
String
match2
=
"apps/cn.soulapp.android/f/easemobDB/[0-9]{0,}.db$"
;
List
<
String
>
fileNames
=
new
ArrayList
<
String
>();
TarArchiveInputStream
tarIn
=
new
TarArchiveInputStream
(
inputStream
,
BUFFER_SIZE
);
TarArchiveEntry
entry
=
null
;
try
{
while
((
entry
=
tarIn
.
getNextTarEntry
()) !=
null
) {
fileNames
.
add
(
entry
.
getName
());
Pattern
p
=
Pattern
.
compile
(
match2
);
Matcher
m
=
p
.
matcher
(
entry
.
getName
());
if
(
m
.
matches
()) {
File
tmpFile
=
new
File
(
destDir
+
File
.
separator
+
entry
.
getName
().
substring
(
match
.
length
()));
createDirectory
(
tmpFile
.
getParent
() +
File
.
separator
,
null
);
// 创建输出目录
OutputStream
out
=
null
;
try
{
out
=
new
FileOutputStream
(
tmpFile
);
int
length
=
0
;
byte
[]
b
=
new
byte
[
2048
];
while
((
length
=
tarIn
.
read
(
b
)) != -
1
) {
out
.
write
(
b
,
0
,
length
);
}
}
finally
{
IOUtils
.
closeQuietly
(
out
);
}
}
}
}
catch
(
Exception
e
) {
e
.
printStackTrace
();
throw
e
;
}
finally
{
IOUtils
.
closeQuietly
(
tarIn
);
}
return
fileNames
;
}
public
static
List
<
String
>
unTar
(
String
tarFile
,
String
destDir
)
throws
Exception
{
File
file
=
new
File
(
tarFile
);
return
unTar
(
file
,
destDir
);
}
}
Back
|
FazBrowse Home
|
New Git URL