-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJarUtil.java
More file actions
84 lines (83 loc) · 2.13 KB
/
Copy pathJarUtil.java
File metadata and controls
84 lines (83 loc) · 2.13 KB
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
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.Date;
import java.io.InputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class JarUtil {
public static void unjar(File jarFile, File dir) throws FileNotFoundException, IOException {
ZipInputStream zis = null;
try {
// code from WarExpand
zis = new ZipInputStream(new FileInputStream(jarFile));
ZipEntry ze = null;
while ((ze = zis.getNextEntry()) != null) {
extractFile(
jarFile,
dir,
zis,
ze.getName(),
new Date(ze.getTime()),
ze.isDirectory());
}
} finally {
if (zis != null) {
try {
zis.close();
} catch (IOException e) {
}
}
}
}
protected static void debug(String msg) {
//System.out.println(msg);
}
protected static void extractFile(
File srcF,
File dir,
InputStream compressedInputStream,
String entryName,
Date entryDate,
boolean isDirectory)
throws IOException {
//File f = fileUtils.resolveFile(dir, entryName);
File f = new File(dir, entryName);
debug("expanding " + entryName);
// create intermediary directories - sometimes zip don't add them
File dirF = f.getParentFile();
dirF.mkdirs();
if (isDirectory) {
f.mkdirs();
} else {
byte[] buffer = new byte[1024];
int length = 0;
FileOutputStream fos = null;
try {
fos = new FileOutputStream(f);
while ((length = compressedInputStream.read(buffer)) >= 0) {
fos.write(buffer, 0, length);
}
fos.close();
fos = null;
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
}
}
}
}
//fileUtils.setFileLastModified(f, entryDate.getTime());
}
public static void main(String args[]) throws Exception {
File jarFile = new File(args[0]);
File destFile = new File(args[1]);
System.out.println("Unjarring " + jarFile.getPath() + " to " + destFile.getPath());
unjar(jarFile, destFile);
System.out.println("Done!");
}
}