Skip to content

Commit 0dd22af

Browse files
committed
Merge pull request qiniu#27 from qiniu/develop
support fileop
2 parents 4a6d589 + e28e61f commit 0dd22af

File tree

12 files changed

+306
-5
lines changed

12 files changed

+306
-5
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
language: java

pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@
88
<packaging>jar</packaging>
99
<name>java-sdk</name>
1010
<url>http://www.qiniutek.com/</url>
11+
12+
<build>
13+
<plugins>
14+
<plugin>
15+
<groupId>org.apache.maven.plugins</groupId>
16+
<artifactId>maven-compiler-plugin</artifactId>
17+
<configuration>
18+
<source>1.6</source>
19+
<target>1.6</target>
20+
<encoding>utf-8</encoding>
21+
</configuration>
22+
</plugin>
23+
24+
25+
</plugins>
26+
27+
</build>
1128

1229
<properties>
1330
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

src/main/java/com/qiniu/qbox/auth/CallRet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public String getResponse() {
3131
}
3232

3333
public boolean ok() {
34-
return this.statusCode / 100 == 2;
34+
return this.statusCode / 100 == 2 && this.exception == null;
3535
}
3636

3737
public Exception getException() {

src/main/java/com/qiniu/qbox/auth/Client.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
import org.apache.http.message.BasicNameValuePair;
2121
import org.apache.http.util.EntityUtils;
2222

23-
public abstract class Client {
23+
public class Client {
2424

25-
public abstract void setAuth(HttpPost post);
25+
public void setAuth(HttpPost post) {
26+
}
2627

2728
public CallRet call(String url) {
2829
HttpPost postMethod = new HttpPost(url);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.qiniu.qbox.fileop;
2+
3+
import com.qiniu.qbox.auth.CallRet;
4+
import com.qiniu.qbox.auth.Client;
5+
6+
public class ImageExif {
7+
8+
public static String makeRequest(String url) {
9+
return url + "?exif";
10+
}
11+
12+
public static CallRet call(String url) {
13+
CallRet ret = new Client().call(url) ;
14+
return ret;
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.qiniu.qbox.fileop;
2+
3+
import com.qiniu.qbox.auth.CallRet;
4+
import com.qiniu.qbox.auth.Client;
5+
6+
public class ImageInfo {
7+
8+
public static String makeRequest(String url) {
9+
return url + "?imageInfo" ;
10+
}
11+
12+
public static ImageInfoRet call(String url) {
13+
CallRet ret = new Client().call(url) ;
14+
return new ImageInfoRet(ret) ;
15+
}
16+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.qiniu.qbox.fileop;
2+
3+
import org.json.JSONException;
4+
import org.json.JSONObject;
5+
6+
import com.qiniu.qbox.auth.CallRet;
7+
8+
public class ImageInfoRet extends CallRet {
9+
public String format ;
10+
/** The width of the original image, in pixel */
11+
public int width ;
12+
/** The height of the original image, in pixel */
13+
public int height ;
14+
public String colorModel ;
15+
16+
public ImageInfoRet(CallRet ret) {
17+
super(ret);
18+
if (ret.ok() && ret.getResponse() != null) {
19+
try {
20+
unmarshal(ret.getResponse());
21+
} catch (Exception e) {
22+
this.exception = e;
23+
}
24+
}
25+
}
26+
private void unmarshal(String json) throws JSONException {
27+
JSONObject jsonObj = new JSONObject(json) ;
28+
if (jsonObj.has("format") && jsonObj.has("width")
29+
&& jsonObj.has("height") && jsonObj.has("colorModel")) {
30+
this.format = jsonObj.getString("format") ;
31+
this.width = jsonObj.getInt("width") ;
32+
this.height = jsonObj.getInt("height") ;
33+
this.colorModel = jsonObj.getString("colorModel") ;
34+
} else {
35+
throw new JSONException("Bad result!") ;
36+
}
37+
}
38+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.qiniu.qbox.fileop;
2+
3+
import com.qiniu.qbox.auth.CallRet;
4+
import com.qiniu.qbox.auth.Client;
5+
6+
7+
public class ImageMogrify {
8+
public String thumbnail ;
9+
public String gravity ;
10+
public String crop ;
11+
public int quality ;
12+
public int rotate ;
13+
public String format ;
14+
public boolean autoOrient ;
15+
16+
public String makeParams() {
17+
StringBuilder params = new StringBuilder() ;
18+
if (this.thumbnail != null && this.thumbnail != "") {
19+
params.append("/thumbnail/" + this.thumbnail) ;
20+
}
21+
if (this.gravity != null && this.gravity != "") {
22+
params.append("/gravity/" + this.gravity) ;
23+
}
24+
if (this.crop != null && this.crop != "") {
25+
params.append("/crop/" + this.crop) ;
26+
}
27+
if (this.quality > 0) {
28+
params.append("/quality/" + this.quality) ;
29+
}
30+
if (this.rotate > 0) {
31+
params.append("/rotate/" + this.rotate) ;
32+
}
33+
if (this.format != null && this.format != "") {
34+
params.append("/format/" + this.format) ;
35+
}
36+
if (this.autoOrient) {
37+
params.append("/auto-orient") ;
38+
}
39+
return params.toString() ;
40+
}
41+
42+
public String makeRequest(String url) {
43+
return url + "?imageMogr" + this.makeParams() ;
44+
}
45+
46+
public CallRet call(String url) {
47+
CallRet ret = new Client().call(url) ;
48+
return ret;
49+
}
50+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.qiniu.qbox.fileop;
2+
3+
import com.qiniu.qbox.auth.CallRet;
4+
import com.qiniu.qbox.auth.Client;
5+
6+
7+
public class ImageView {
8+
public int mode ;
9+
public int width ;
10+
public int height ;
11+
public int quality ;
12+
public String format ;
13+
public int sharpen ;
14+
15+
public String makeParams() {
16+
StringBuilder params = new StringBuilder() ;
17+
if (this.mode != 1 && this.mode != 2) {
18+
throw new IllegalArgumentException("Mode value must be 1 or 2!") ;
19+
} else {
20+
params.append("/" + this.mode) ;
21+
}
22+
if (this.width > 0) {
23+
params.append("/w/" + this.width) ;
24+
}
25+
if (this.height > 0) {
26+
params.append("/h/" + this.height) ;
27+
}
28+
if (this.quality > 0) {
29+
params.append("/q/" + this.quality) ;
30+
}
31+
if (this.format != null && this.format != "") {
32+
params.append("/format/" + this.format) ;
33+
}
34+
if (this.sharpen > 0) {
35+
params.append("/sharpen/" + this.sharpen) ;
36+
}
37+
return params.toString() ;
38+
}
39+
40+
public String makeRequest(String url) {
41+
return url + "?imageView" + this.makeParams() ;
42+
}
43+
44+
public CallRet call(String url) {
45+
CallRet ret = new Client().call(url) ;
46+
return ret;
47+
}
48+
}

src/main/java/com/qiniu/qbox/rs/RSService.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,14 @@ public DropRet drop() throws Exception {
139139
CallRet callRet = conn.call(url);
140140
return new DropRet(callRet);
141141
}
142+
143+
/**
144+
* func Mkbucket(bucketname string) => Bool
145+
* 创建一个资源表
146+
*/
147+
public CallRet mkBucket(String newBucketName) throws Exception {
148+
String url = Config.RS_HOST + "/mkbucket/" + newBucketName ;
149+
CallRet callRet = conn.call(url) ;
150+
return callRet ;
151+
}
142152
}

0 commit comments

Comments
 (0)