Repository navigation
Expand file tree
/
Copy pathTest.java
More file actions
182 lines (163 loc) · 6.95 KB
/
Copy pathTest.java
File metadata and controls
182 lines (163 loc) · 6.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import com.qcloud.*;
import java.io.*;
import java.util.ArrayList;
public class Test {
// appid, access id, access key请去http://app.qcloud.com申请使用
// 下面的的demo代码请使用自己的appid等信息
public static final int APP_ID_V1 = 111;
public static final String SECRET_ID_V1 = "SECRET_ID_V1";
public static final String SECRET_KEY_V1 = "SECRET_KEY_V1";
public static final int APP_ID_V2 = 111;
public static final String SECRET_ID_V2 = "SECRET_ID_V2";
public static final String SECRET_KEY_V2 = "SECRET_KEY_V2";
public static final String BUCKET = "BUCKET"; //空间名
public static void main(String[] args) throws Exception {
//sign_test();
//v1版本api的demo
//picV1Test("D:/sss.jpg");
//v2版本api的demo
//picV2Test("D:/original.jpg");
//分片上传
//sliceUpload("D:/testa.jpg");
//黄图识别
String url = "http://b.hiphotos.baidu.com/image/pic/item/8ad4b31c8701a18b1efd50a89a2f07082938fec7.jpg";
pornTest(url);
//黄图识别(Url)
String[] pornUrl = {"http://b.hiphotos.baidu.com/image/pic/item/8ad4b31c8701a18b1efd50a89a2f07082938fec7.jpg",
"http://c.hiphotos.baidu.com/image/h%3D200/sign=7b991b465eee3d6d3dc680cb73176d41/96dda144ad3459829813ed730bf431adcaef84b1.jpg"
};
pornUrlTest(pornUrl);
//黄图识别(File)
String[] pornFile = {"D:\\porn\\test1.jpg",
"D:\\porn\\test2.jpg",
"..\\..\\..\\..\\..\\porn\\测试.png"
};
pornFileTest(pornFile);
}
public static void pornTest(String url){
PicCloud pc = new PicCloud(APP_ID_V2, SECRET_ID_V2, SECRET_KEY_V2, BUCKET);
PornDetectInfoData info = pc.pornDetect(url);
if (info != null) {
System.out.println("detect porn pic success");
info.print();
} else {
System.out.println("detect porn pic error, error=" + pc.getError());
}
}
public static void pornUrlTest(String[] pornUrl){
PicCloud pc = new PicCloud(APP_ID_V2, SECRET_ID_V2, SECRET_KEY_V2, BUCKET);
ArrayList<PornDetectInfo> info = pc.pornDetectUrl(pornUrl);
if (info != null) {
System.out.println("detect porn pic success");
System.out.println("result_list = {");
for(int i=0; i<info.size(); i++){
System.out.println("url-" + Integer.toString(i) + " = {");
info.get(i).print();
System.out.println("}");
}
System.out.println("}");
} else {
System.out.println("detect porn pic error, " + pc.getError());
}
}
public static void pornFileTest(String[] pornFile){
PicCloud pc = new PicCloud(APP_ID_V2, SECRET_ID_V2, SECRET_KEY_V2, BUCKET);
ArrayList<PornDetectInfo> info = pc.pornDetectFile(pornFile);
if (info != null) {
System.out.println("detect porn pic success");
System.out.println("result_list = {");
for(int i=0; i<info.size(); i++){
System.out.println("file-" + Integer.toString(i) + " = {");
info.get(i).print();
System.out.println("}");
}
System.out.println("}");
} else {
System.out.println("detect porn pic error, " + pc.getError());
}
}
public static void signTest() {
PicCloud pc = new PicCloud(APP_ID_V2, SECRET_ID_V2, SECRET_KEY_V2, BUCKET);
long expired = System.currentTimeMillis() / 1000 + 3600;
String sign = pc.getSign(expired);
System.out.println("sign="+sign);
}
public static void picV1Test(String pic) throws Exception {
PicCloud pc = new PicCloud(APP_ID_V1, SECRET_ID_V1, SECRET_KEY_V1);
picBase(pc, pic);
}
public static void picV2Test(String pic) throws Exception {
PicCloud pc = new PicCloud(APP_ID_V2, SECRET_ID_V2, SECRET_KEY_V2, BUCKET);
picBase(pc, pic);
}
public static void picBase(PicCloud pc, String pic) throws Exception {
String url = "";
String downloadUrl = "";
// 上传一张图片�
System.out.println("======================================================");
UploadResult uInfo = pc.upload(pic);
if (uInfo != null) {
System.out.println("upload pic success");
uInfo.print();
} else {
System.out.println("upload pic error, error=" + pc.getError());
}
FileInputStream fileStream = new FileInputStream(pic);
uInfo = pc.upload(fileStream);
fileStream.close();
if (uInfo != null) {
System.out.println("upload pic2 success");
uInfo.print();
} else {
System.out.println("upload pic2 error, error=" + pc.getError());
}
FileInputStream fileStream2 = new FileInputStream(pic);
byte[] data = new byte[fileStream2.available()];
fileStream2.read(data);
ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
uInfo = pc.upload(inputStream);
fileStream2.close();
if (uInfo != null) {
System.out.println("upload pic3 success");
uInfo.print();
} else {
System.out.println("upload pic3 error, error=" + pc.getError());
}
// 查询图片的状态��
System.out.println("======================================================");
PicInfo pInfo = pc.stat(uInfo.fileId);
if (pInfo != null) {
System.out.println("Stat pic success");
pInfo.print();
} else {
System.out.println("Stat pic error, error=" + pc.getError());
}
// 复制一张图片
System.out.println("======================================================");
uInfo = pc.copy(uInfo.fileId);
if (uInfo != null) {
System.out.println("copy pic success");
uInfo.print();
} else {
System.out.println("copy pic error, error=" + pc.getError());
}
// 删除一张图片
System.out.println("======================================================");
int ret = pc.delete(uInfo.fileId);
if (ret == 0) {
System.out.println("delete pic success");
} else {
System.out.println("delete pic error, error=" + pc.getError());
}
}
public static void sliceUpload(String url){
PicCloud pc = new PicCloud(APP_ID_V2, SECRET_ID_V2, SECRET_KEY_V2, BUCKET);
SliceUploadInfo info = pc.simpleUploadSlice(url, 8*1024);
if (info != null) {
System.out.println("slice upload pic success");
info.print();
} else {
System.out.println("slice upload pic error, error=" + pc.getError());
}
}
}