[LIB-13] Several options for working through a proxy server
[chesshog-scanner.git] / src / main / java / org / hedgecode / chess / scanner / proxy / client / LocalDnsResolver.java
1 /*
2  * Copyright (c) 2019-2020. Developed by Hedgecode.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.hedgecode.chess.scanner.proxy.client;
18
19 import java.net.InetAddress;
20 import java.net.UnknownHostException;
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import org.apache.http.conn.DnsResolver;
25
26 /**
27  * LocalDnsResolver
28  *
29  * @author Dmitry Samoshin aka gotty
30  */
31 public class LocalDnsResolver implements DnsResolver {
32
33     private static final String LOCALHOST = "localhost";
34     private static final byte[] IP_ADDRESS = { 127, 0, 0, 1 };
35
36     private final Map<String, byte[]> resolvers = new HashMap<String, byte[]>() {
37         {
38             put( LOCALHOST, IP_ADDRESS );
39         }
40     };
41
42     @Override
43     public InetAddress[] resolve(String host) throws UnknownHostException {
44         return new InetAddress[] {
45                 InetAddress.getByAddress(
46                         LOCALHOST, resolvers.get(LOCALHOST)
47                 )
48         };
49     }
50
51 }