Skip to content

Commit 6d46407

Browse files
committed
add bucketInfo, setBucketAcl, setIndexPage
1 parent f52e776 commit 6d46407

File tree

9 files changed

+283
-34
lines changed

9 files changed

+283
-34
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public final class Constants {
99
/**
1010
* 版本号
1111
*/
12-
public static final String VERSION = "7.2.16";
12+
public static final String VERSION = "7.2.17";
1313
/**
1414
* 块大小,不能改变
1515
*/

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

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
import com.qiniu.common.QiniuException;
55
import com.qiniu.http.Client;
66
import com.qiniu.http.Response;
7-
import com.qiniu.storage.model.FetchRet;
8-
import com.qiniu.storage.model.FileInfo;
9-
import com.qiniu.storage.model.FileListing;
7+
import com.qiniu.storage.model.*;
108
import com.qiniu.util.*;
119

1210
import java.util.ArrayList;
@@ -98,7 +96,7 @@ public String[] buckets() throws QiniuException {
9896
return r.jsonToObject(String[].class);
9997
}
10098

101-
public void createBucket(String bucketName, String region) throws Exception {
99+
public void createBucket(String bucketName, String region) throws QiniuException {
102100
String url = String.format("%s/mkbucketv2/%s/region/%s", configuration.rsHost(),
103101
UrlSafeBase64.encodeToString(bucketName), region);
104102
post(url, null).close();
@@ -233,14 +231,6 @@ public Response changeHeaders(String bucket, String key, Map<String, String> hea
233231
}
234232

235233

236-
//存储类型
237-
public enum StorageType {
238-
//普通存储
239-
COMMON,
240-
//低频存储
241-
INFREQUENCY
242-
}
243-
244234
/**
245235
* 修改文件的类型(普通存储或低频存储)
246236
*
@@ -510,6 +500,33 @@ public Response deleteAfterDays(String bucket, String key, int days) throws Qini
510500
return rsPost(bucket, String.format("/deleteAfterDays/%s/%d", encodedEntry(bucket, key), days), null);
511501
}
512502

503+
public void setBucketAcl(String bucket, AclType acl) throws QiniuException {
504+
String url = String.format("%s/private?bucket=%s&private=%s", configuration.ucHost(), bucket, acl.getType());
505+
Response res = post(url, null);
506+
res.close();
507+
if (!res.isOK()) {
508+
throw new QiniuException(res);
509+
}
510+
}
511+
512+
public BucketInfo getBucketInfo(String bucket) throws QiniuException {
513+
String url = String.format("%s/v2/bucketInfo?bucket=%s", configuration.ucHost(), bucket);
514+
Response res = post(url, null);
515+
if (!res.isOK()) {
516+
res.close();
517+
throw new QiniuException(res);
518+
}
519+
BucketInfo info = res.jsonToObject(BucketInfo.class);
520+
return info;
521+
}
522+
523+
524+
public void setIndexPage(String bucket, IndexPageType type) throws QiniuException {
525+
String url = String.format("%s/noIndexPage?bucket=%s&noIndexPage=%s", configuration.ucHost(), bucket, type.getType());
526+
Response res = post(url, null);
527+
}
528+
529+
513530
/*
514531
* 相关请求的方法列表
515532
* */
@@ -722,4 +739,5 @@ public void remove() {
722739
throw new UnsupportedOperationException("remove");
723740
}
724741
}
742+
725743
}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public final class Configuration implements Cloneable {
1717
*/
1818
public Zone zone;
1919
/**
20-
* 空间相关上传管理操作是否使用 https , 默认否
20+
* 空间相关上传管理操作是否使用 https , 默认 是
2121
*/
22-
public boolean useHttpsDomains = false;
22+
public boolean useHttpsDomains = true;
2323
/**
2424
* 如果文件大小大于此值则使用断点上传, 否则使用Form上传
2525
*/
@@ -74,6 +74,7 @@ public final class Configuration implements Cloneable {
7474
*/
7575
public static String defaultRsHost = "rs.qiniu.com";
7676
public static String defaultApiHost = "api.qiniu.com";
77+
public static String defaultUcHost = "uc.qbox.me";
7778

7879
public Configuration() {
7980

@@ -165,4 +166,12 @@ public String rsfHost(String ak, String bucket) {
165166
return useHttpsDomains ? zone.getRsfHttps(zoneReqInfo)
166167
: zone.getRsfHttp(zoneReqInfo);
167168
}
169+
170+
public String ucHost() {
171+
String scheme = "http://";
172+
if (useHttpsDomains) {
173+
scheme = "https://";
174+
}
175+
return scheme + defaultUcHost;
176+
}
168177
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.qiniu.storage.model;
2+
3+
/**
4+
* 空间类型:公开空间、私有空间
5+
*/
6+
public enum AclType {
7+
/**
8+
* 公开空间
9+
*/
10+
PUBLIC(0),
11+
/**
12+
* 私有空间
13+
*/
14+
PRIVATE(1);
15+
16+
private int type = 0;
17+
18+
AclType(int t) {
19+
type = t;
20+
}
21+
22+
public int getType() {
23+
return type;
24+
}
25+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package com.qiniu.storage.model;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
5+
import java.util.Map;
6+
7+
public class BucketInfo {
8+
@SerializedName("source")
9+
private String imageSource;
10+
@SerializedName("host")
11+
private String imageHost;
12+
@SerializedName("protected")
13+
private int _protected;
14+
@SerializedName("private")
15+
private int _private;
16+
@SerializedName("no_index_page")
17+
private int noIndexPage;
18+
private int imgsft;
19+
private String separator;
20+
private Map<String, String> styles;
21+
private String zone;
22+
private String region;
23+
private boolean global;
24+
25+
public String getImageSource() {
26+
return imageSource;
27+
}
28+
29+
public void setImageSource(String imageSource) {
30+
this.imageSource = imageSource;
31+
}
32+
33+
public String getImageHost() {
34+
return imageHost;
35+
}
36+
37+
public void setImageHost(String imageHost) {
38+
this.imageHost = imageHost;
39+
}
40+
41+
public int getProtected() {
42+
return _protected;
43+
}
44+
45+
public void setProtected(int _protected) {
46+
this._protected = _protected;
47+
}
48+
49+
public int getPrivate() {
50+
return _private;
51+
}
52+
53+
public void setPrivate(int _private) {
54+
this._private = _private;
55+
}
56+
57+
public int getNoIndexPage() {
58+
return noIndexPage;
59+
}
60+
61+
public void setNoIndexPage(int noIndexPage) {
62+
this.noIndexPage = noIndexPage;
63+
}
64+
65+
public int getImgsft() {
66+
return imgsft;
67+
}
68+
69+
public void setImgsft(int imgsft) {
70+
this.imgsft = imgsft;
71+
}
72+
73+
public String getSeparator() {
74+
return separator;
75+
}
76+
77+
public void setSeparator(String separator) {
78+
this.separator = separator;
79+
}
80+
81+
public Map<String, String> getStyles() {
82+
return styles;
83+
}
84+
85+
public void setStyles(Map<String, String> styles) {
86+
this.styles = styles;
87+
}
88+
89+
public String getZone() {
90+
return zone;
91+
}
92+
93+
public void setZone(String zone) {
94+
this.zone = zone;
95+
}
96+
97+
public String getRegion() {
98+
return region;
99+
}
100+
101+
public void setRegion(String region) {
102+
this.region = region;
103+
}
104+
105+
public boolean isGlobal() {
106+
return global;
107+
}
108+
109+
public void setGlobal(boolean global) {
110+
this.global = global;
111+
}
112+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.qiniu.storage.model;
2+
3+
public enum IndexPageType {
4+
HAS(0),
5+
NO(1);
6+
7+
private int type = 0;
8+
9+
IndexPageType(int t) {
10+
type = t;
11+
}
12+
13+
public int getType() {
14+
return type;
15+
}
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.qiniu.storage.model;
2+
3+
/**
4+
* 存储类型
5+
*/
6+
public enum StorageType {
7+
/**
8+
* 普通存储
9+
*/
10+
COMMON,
11+
/**
12+
* 低频存储
13+
*/
14+
INFREQUENCY
15+
}

src/test/java/test/com/qiniu/DnsTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ public void setUp() throws UnknownHostException {
3535
@Override
3636
public List<InetAddress> lookup(String hostname) throws UnknownHostException {
3737
InetAddress[] ips;
38-
try{
39-
Domain domain = new Domain(hostname, true, true);
40-
ips = dnsClient.queryInetAddress(domain);
41-
} catch (IOException e) {
42-
e.printStackTrace();
43-
throw new UnknownHostException(e.getMessage());
44-
}
38+
try {
39+
Domain domain = new Domain(hostname, true, true);
40+
ips = dnsClient.queryInetAddress(domain);
41+
} catch (IOException e) {
42+
e.printStackTrace();
43+
throw new UnknownHostException(e.getMessage());
44+
}
4545
if (ips == null) {
46-
throw new UnknownHostException(hostname + " resolve failed.");
47-
}
48-
List<InetAddress> l = new ArrayList<>(ips.length);
46+
throw new UnknownHostException(hostname + " resolve failed.");
47+
}
48+
List<InetAddress> l = new ArrayList<>(ips.length);
4949
Collections.addAll(l, ips);
5050
return l;
5151
}

0 commit comments

Comments
 (0)