/
GenerateZips.java
47 lines (42 loc) · 1.54 KB
/
GenerateZips.java
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
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import org.apache.commons.compress.archivers.zip.UnicodePathExtraField;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
public class GenerateZips {
private static void generate(String outfilename, boolean languageEncodingFlag) {
try {
ZipArchiveOutputStream zs = new ZipArchiveOutputStream(new File(outfilename));
zs.setUseLanguageEncodingFlag(languageEncodingFlag);
zs.setMethod(ZipArchiveOutputStream.STORED);
ZipArchiveEntry ze = new ZipArchiveEntry("nameonly-name");
ze.setTime(0);
zs.putArchiveEntry(ze);
//zs.write(nothing);
zs.closeArchiveEntry();
ze = new ZipArchiveEntry("goodextra-name");
ze.setTime(0);
ze.addExtraField(new UnicodePathExtraField("goodextra-extra", "goodextra-name".getBytes(Charset.forName("UTF-8"))));
zs.putArchiveEntry(ze);
//zs.write(nothing);
zs.closeArchiveEntry();
ze = new ZipArchiveEntry("badextra-name");
ze.setTime(0);
ze.addExtraField(new UnicodePathExtraField("badextra-extra", "bogus".getBytes(Charset.forName("UTF-8"))));
zs.putArchiveEntry(ze);
//zs.write(nothing);
zs.closeArchiveEntry();
zs.finish();
zs.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
generate("efsclear.zip", false);
// with the flag set, decoders tend to not look at the extra field
generate("efsset.zip", true);
System.out.println("done");
}
}