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.URI;
23 import java.net.URISyntaxException;
24
25 import com.garygregory.jcommander.converters.AbstractBaseConverter;
26
27 /**
28 * Converts a {@link String} into a {@link URI}.
29 * <p>
30 * For a description of the format, see {@link URI#URI(String)}.
31 * </p>
32 *
33 * <p>
34 * Example:
35 * </p>
36 *
37 * <pre class="prettyprint">
38 * <code class="language-java">@Parameter(names = { "--uRI" }, converter = URIConverter.class)
39 * private URI uri;</code>
40 * </pre>
41 * <p>
42 *
43 * @see URI
44 * @see URI#URI(String)
45 *
46 * @since 1.0.0
47 * @author <a href="mailto:ggregory@garygregory.com">Gary Gregory</a>
48 */
49 public class URIConverter extends AbstractBaseConverter<URI> {
50
51 /**
52 * Constructs a converter.
53 *
54 * @param optionName
55 * The option name, may be null.
56 */
57 public URIConverter(final String optionName) {
58 super(optionName, URI.class);
59 }
60
61 @Override
62 protected URI convertImpl(final String value) throws URISyntaxException {
63 return new URI(value);
64 }
65
66 }