ZipFilesHandler.java
2.09 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.granite.infocollector.impl;
import com.adobe.granite.infocollector.impl.FilesHandler;
import com.adobe.granite.infocollector.impl.FilesTraversal;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
final class ZipFilesHandler
implements FilesHandler {
private static final int DEFAULT_BUFFER_SIZE = 1024;
private final FilesTraversal filesTraversal;
private final ZipOutputStream target;
private final String namePrefix;
public ZipFilesHandler(FilesTraversal filesTraversal, ZipOutputStream target, String namePrefix) {
this.filesTraversal = filesTraversal;
this.target = target;
this.namePrefix = namePrefix;
}
@Override
public void beginDirectory(File directory) throws IOException {
this.putNextEntry(directory);
}
@Override
public void endDirectory(File directory) throws IOException {
this.target.closeEntry();
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public void onFile(File file) throws IOException {
this.putNextEntry(file);
FileInputStream sourceStream = null;
try {
int bytesRead;
sourceStream = new FileInputStream(file);
byte[] buffer = new byte[1024];
while ((bytesRead = sourceStream.read(buffer)) > 0) {
this.target.write(buffer, 0, bytesRead);
}
this.target.flush();
}
finally {
if (sourceStream != null) {
try {
sourceStream.close();
}
catch (IOException e) {}
}
this.target.closeEntry();
}
}
private void putNextEntry(File file) throws IOException {
String name = this.namePrefix + this.filesTraversal.relativize(file);
ZipEntry entry = new ZipEntry(name);
entry.setSize(file.length());
this.target.putNextEntry(entry);
}
}