aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/BaseFormat.java
blob: 27f001e220b62c599f5b152c9e782a341766313e (plain)
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
/*
 * Copyright (C) 2015, David Ostrovsky <david@ostrovsky.org> and others
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Distribution License v. 1.0 which is available at
 * https://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

package org.eclipse.jgit.archive;

import java.beans.Statement;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Map;

import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.eclipse.jgit.archive.internal.ArchiveText;
import org.eclipse.jgit.util.StringUtils;

/**
 * Base format class
 *
 * @since 4.0
 */
public class BaseFormat {

	/**
	 * Apply options to archive output stream
	 *
	 * @param s
	 *            stream to apply options to
	 * @param o
	 *            options map
	 * @return stream with option applied
	 * @throws IOException
	 */
	protected ArchiveOutputStream applyFormatOptions(ArchiveOutputStream s,
			Map<String, Object> o) throws IOException {
		for (Map.Entry<String, Object> p : o.entrySet()) {
			try {
				new Statement(s, "set" + StringUtils.capitalize(p.getKey()), //$NON-NLS-1$
						new Object[] { p.getValue() }).execute();
			} catch (Exception e) {
				throw new IOException(MessageFormat.format(
						ArchiveText.get().cannotSetOption, p.getKey()), e);
			}
		}
		return s;
	}
}