1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.archive;
12
13 import java.beans.Statement;
14 import java.io.IOException;
15 import java.text.MessageFormat;
16 import java.util.Map;
17
18 import org.apache.commons.compress.archivers.ArchiveOutputStream;
19 import org.eclipse.jgit.archive.internal.ArchiveText;
20 import org.eclipse.jgit.util.StringUtils;
21
22
23
24
25
26
27 public class BaseFormat {
28
29
30
31
32 protected static final String COMPRESSION_LEVEL = "compression-level";
33
34
35
36
37
38
39
40
41
42
43
44 protected ArchiveOutputStream applyFormatOptions(ArchiveOutputStream s,
45 Map<String, Object> o) throws IOException {
46 for (Map.Entry<String, Object> p : o.entrySet()) {
47 try {
48 if (p.getKey().equals(COMPRESSION_LEVEL)) {
49 continue;
50 }
51 new Statement(s, "set" + StringUtils.capitalize(p.getKey()),
52 new Object[] { p.getValue() }).execute();
53 } catch (Exception e) {
54 throw new IOException(MessageFormat.format(
55 ArchiveText.get().cannotSetOption, p.getKey()), e);
56 }
57 }
58 return s;
59 }
60
61
62
63
64
65
66
67
68
69
70
71
72
73 protected int getCompressionLevel(Map<String, Object> o) {
74 if (!o.containsKey(COMPRESSION_LEVEL)) {
75 return -1;
76 }
77 Object option = o.get(COMPRESSION_LEVEL);
78 try {
79 Integer compressionLevel = (Integer) option;
80 return compressionLevel.intValue();
81 } catch (ClassCastException e) {
82 throw new IllegalArgumentException(
83 MessageFormat.format(
84 ArchiveText.get().invalidCompressionLevel, option),
85 e);
86 }
87 }
88 }