You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BaseFormat.java 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (C) 2015, David Ostrovsky <david@ostrovsky.org> and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.archive;
  11. import java.beans.Statement;
  12. import java.io.IOException;
  13. import java.text.MessageFormat;
  14. import java.util.Map;
  15. import org.apache.commons.compress.archivers.ArchiveOutputStream;
  16. import org.eclipse.jgit.archive.internal.ArchiveText;
  17. import org.eclipse.jgit.util.StringUtils;
  18. /**
  19. * Base format class
  20. *
  21. * @since 4.0
  22. */
  23. public class BaseFormat {
  24. /**
  25. * Apply options to archive output stream
  26. *
  27. * @param s
  28. * stream to apply options to
  29. * @param o
  30. * options map
  31. * @return stream with option applied
  32. * @throws IOException
  33. */
  34. protected ArchiveOutputStream applyFormatOptions(ArchiveOutputStream s,
  35. Map<String, Object> o) throws IOException {
  36. for (Map.Entry<String, Object> p : o.entrySet()) {
  37. try {
  38. new Statement(s, "set" + StringUtils.capitalize(p.getKey()), //$NON-NLS-1$
  39. new Object[] { p.getValue() }).execute();
  40. } catch (Exception e) {
  41. throw new IOException(MessageFormat.format(
  42. ArchiveText.get().cannotSetOption, p.getKey()), e);
  43. }
  44. }
  45. return s;
  46. }
  47. }