- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileExtraction.java
More file actions
Latest commit
49 lines (41 loc) · 1.4 KB
/
Copy pathFileExtraction.java
File metadata and controls
49 lines (41 loc) · 1.4 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
importjava.io.BufferedInputStream;
importjava.io.BufferedOutputStream;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.FileOutputStream;
importjava.io.IOException;
importjava.util.zip.ZipEntry;
importjava.util.zip.ZipInputStream;
publicclassFileExtraction {
/**
* Max extraction buffer...4 MB
*/
privatestaticfinalintBUFFER_SIZE = 4096;
publicstaticvoidunzip(StringfileLocation, StringdestinationPath) throwsIOException {
finalFilefile = newFile(fileLocation);
finalBufferedInputStreaminput = newBufferedInputStream(newFileInputStream(file));
finalZipInputStreamzin = newZipInputStream(input);
ZipEntrye;
while ((e = zin.getNextEntry()) != null) {
if (e.isDirectory()) {
(newFile(destinationPath + e.getName())).mkdir();
} else {
if (e.getName().equals(fileLocation)) {
extract(zin, fileLocation);
break;
}
extract(zin, destinationPath + e.getName());
}
}
zin.close();
}
privatestaticvoidextract(ZipInputStreamzipIn, StringfilePath) throwsIOException {
BufferedOutputStreambos = newBufferedOutputStream(newFileOutputStream(filePath));
byte[] bytesIn = newbyte[BUFFER_SIZE];
intread = 0;
while ((read = zipIn.read(bytesIn)) != -1) {
bos.write(bytesIn, 0, read);
}
bos.close();
}
}