|
28 | 28 | import joptsimple.NonOptionArgumentSpec;
|
29 | 29 | import joptsimple.OptionSet;
|
30 | 30 |
|
| 31 | +import org.elasticsearch.core.internal.io.IOUtils; |
| 32 | + |
31 | 33 | /**
|
32 | 34 | * A cli tool which is made up of multiple subcommands.
|
33 | 35 | */
|
@@ -78,46 +80,8 @@ protected void execute(Terminal terminal, OptionSet options) throws Exception {
|
78 | 80 | }
|
79 | 81 |
|
80 | 82 | @Override
|
81 |
| - public void close() throws IOException, RuntimeException { |
82 |
| - Throwable th = null; |
83 |
| - for (Closeable object : subcommands.values()) { |
84 |
| - try { |
85 |
| - if (object != null) { |
86 |
| - object.close(); |
87 |
| - } |
88 |
| - } catch (Throwable t) { |
89 |
| - addSuppressed(th, t); |
90 |
| - if (th == null) { |
91 |
| - th = t; |
92 |
| - } |
93 |
| - } |
94 |
| - } |
95 |
| - if (th != null) { |
96 |
| - throw reThrowAlways(th); |
97 |
| - } |
| 83 | + public void close() throws IOException { |
| 84 | + IOUtils.close(subcommands.values()); |
98 | 85 | }
|
99 | 86 |
|
100 |
| - // Following methods are similar to IOUtils, |
101 |
| - // avoiding lucene dependency in CLI. |
102 |
| - private static void addSuppressed(Throwable t, Throwable suppressed) { |
103 |
| - if (t != null && suppressed != null) { |
104 |
| - t.addSuppressed(suppressed); |
105 |
| - } |
106 |
| - } |
107 |
| - |
108 |
| - private static Error reThrowAlways(Throwable th) throws IOException, RuntimeException { |
109 |
| - if (th instanceof IOException) { |
110 |
| - throw (IOException) th; |
111 |
| - } |
112 |
| - |
113 |
| - if (th instanceof RuntimeException) { |
114 |
| - throw (RuntimeException) th; |
115 |
| - } |
116 |
| - |
117 |
| - if (th instanceof Error) { |
118 |
| - throw (Error) th; |
119 |
| - } |
120 |
| - |
121 |
| - throw new RuntimeException(th); |
122 |
| - } |
123 | 87 | }
|
0 commit comments