Skip to content

Commit 66fefe2

Browse files
authored
Merge pull request #218 from longbai/happydns
add happydns
2 parents 294a175 + 0273b9f commit 66fefe2

File tree

18 files changed

+84
-85
lines changed

18 files changed

+84
-85
lines changed

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ repositories {
1212
}
1313

1414
dependencies {
15-
// String version = System.getProperty("java.version")
16-
// println("JDK: " + version)
15+
// String ver = System.getProperty("java.version")
16+
// println("JDK: " + ver)
1717
// int c = version.compareTo("1.7")
1818
// if (c < 0) {
1919
// compile fileTree(dir: 'libs', include: '*.jar')
2020
// } else {
2121
compile group:'com.squareup.okhttp3', name:'okhttp', version:'3.3.1'
2222
// }
2323
compile group:'com.google.code.gson', name:'gson', version:'2.6.2'
24+
compile group:'com.qiniu', name:'happy-dns-java', version:'0.1.3'
2425
testCompile group: 'junit', name: 'junit', version: '4.12'
25-
println("JDK : " + version)
2626
}
2727

2828

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Wed Jan 07 13:33:33 CST 2015
1+
#Thu Jul 14 15:30:24 CST 2016
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip

src/main/java/com/qiniu/common/Config.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.qiniu.common;
22

3+
import qiniu.happydns.DnsClient;
4+
35
import java.nio.charset.Charset;
46

57
// CHECKSTYLE:OFF
68

79
public final class Config {
810

9-
public static final String VERSION = "7.1.1";
11+
public static final String VERSION = "7.1.2";
1012
/**
1113
* 断点上传时的分块大小(默认的分块大小, 不允许改变)
1214
*/
@@ -54,6 +56,11 @@ public final class Config {
5456
*/
5557
public static int RETRY_MAX = 5;
5658

59+
/**
60+
* 外部dns
61+
*/
62+
public static DnsClient dns = null;
63+
5764
private Config() {
5865
}
5966
}

src/main/java/com/qiniu/common/QiniuException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.io.IOException;
66

77

8-
public class QiniuException extends IOException {
8+
public final class QiniuException extends IOException {
99
public final Response response;
1010

1111

src/main/java/com/qiniu/http/Client.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@
66
import com.qiniu.util.StringUtils;
77
import okhttp3.*;
88
import okio.BufferedSink;
9+
import qiniu.happydns.DnsClient;
10+
import qiniu.happydns.Domain;
911

1012
import java.io.File;
1113
import java.io.IOException;
14+
import java.net.InetAddress;
15+
import java.net.UnknownHostException;
16+
import java.util.ArrayList;
17+
import java.util.Collections;
18+
import java.util.List;
1219
import java.util.concurrent.TimeUnit;
1320

1421
/**
@@ -46,10 +53,32 @@ public okhttp3.Response intercept(Chain chain) throws IOException {
4653
return response;
4754
}
4855
});
56+
if (Config.dns != null) {
57+
final DnsClient d = Config.dns;
58+
builder.dns(new Dns() {
59+
@Override
60+
public List<InetAddress> lookup(String hostname) throws UnknownHostException {
61+
InetAddress[] ips;
62+
try {
63+
ips = d.queryInetAddress(new Domain(hostname));
64+
} catch (IOException e) {
65+
e.printStackTrace();
66+
throw new UnknownHostException(e.getMessage());
67+
}
68+
if (ips == null) {
69+
throw new UnknownHostException(hostname + " resolve failed");
70+
}
71+
List<InetAddress> l = new ArrayList<>();
72+
Collections.addAll(l, ips);
73+
return l;
74+
}
75+
});
76+
}
4977
builder.connectTimeout(Config.CONNECT_TIMEOUT, TimeUnit.SECONDS);
5078
builder.readTimeout(Config.RESPONSE_TIMEOUT, TimeUnit.SECONDS);
5179
builder.writeTimeout(Config.WRITE_TIMEOUT, TimeUnit.SECONDS);
5280
httpClient = builder.build();
81+
5382
}
5483

5584
private static String userAgent() {

src/main/java/com/qiniu/http/Proxy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* http 代理
55
*/
6-
public class Proxy {
6+
public final class Proxy {
77

88
public final String hostAddress;
99
public final int port;

src/main/java/com/qiniu/processing/OperationManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* 触发持久化处理
1313
* 针对七牛空间文件,触发异步文件处理。如异步视频转码等
1414
*/
15-
public class OperationManager {
15+
public final class OperationManager {
1616
private final Client client;
1717
private final Auth auth;
1818

src/main/java/com/qiniu/storage/AsyncResumeUploader.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/main/java/com/qiniu/storage/model/BatchStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
/**
44
* Created by bailong on 15/2/22.
55
*/
6-
public class BatchStatus {
6+
public final class BatchStatus {
77
public int code;
88
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.qiniu.storage.model;
22

3-
public class DefaultPutRet {
3+
public final class DefaultPutRet {
44
public String hash;
55
public String key;
66
}

0 commit comments

Comments
 (0)