1 /**
2 * Copyright (C) 2016 Gary Gregory. All rights reserved.
3 *
4 * See the NOTICE.txt file distributed with this work for additional
5 * information regarding copyright ownership.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20 package com.garygregory.jcommander.converters.net;
21
22 import java.net.InetAddress;
23 import java.net.UnknownHostException;
24
25 import com.garygregory.jcommander.converters.AbstractBaseConverter;
26
27 /**
28 * Converts a {@link String} into a {@link InetAddress}.
29 * <p>
30 * For a description of the format, see {@link InetAddress#getAllByName(String)}.
31 * </p>
32 *
33 * <p>
34 * Example:
35 * </p>
36 *
37 * <pre class="prettyprint">
38 * <code class="language-java">@Parameter(names = { "--inetAddress" }, converter = InetAddressConverter.class)
39 * private InetAddress inetAddress;</code>
40 * </pre>
41 * <p>
42 *
43 * @see InetAddress
44 * @see InetAddress#getAllByName(String)
45 *
46 * @since 1.0.0
47 * @author <a href="mailto:ggregory@garygregory.com">Gary Gregory</a>
48 */
49 public class AllInetAddressesNameConverter extends AbstractBaseConverter<InetAddress[]> {
50
51 /**
52 * Constructs a converter.
53 *
54 * @param optionName
55 * The option name, may be null.
56 */
57 public AllInetAddressesNameConverter(final String optionName) {
58 super(optionName, InetAddress[].class);
59 }
60
61 @Override
62 protected InetAddress[] convertImpl(final String value) throws UnknownHostException {
63 return InetAddress.getAllByName(value);
64 }
65
66 }