Skip to content

Commit 70ca795

Browse files
committed
Refine samples
1 parent 7cb7b5b commit 70ca795

18 files changed

+400
-40
lines changed

src/samples/AppendObjectSample.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
package samples;
221

322
import java.io.ByteArrayInputStream;
@@ -9,7 +28,8 @@
928
import java.io.Writer;
1029

1130
import com.aliyun.oss.ClientException;
12-
import com.aliyun.oss.OSSClient;
31+
import com.aliyun.oss.OSS;
32+
import com.aliyun.oss.OSSClientBuilder;
1333
import com.aliyun.oss.OSSException;
1434
import com.aliyun.oss.model.AppendObjectRequest;
1535
import com.aliyun.oss.model.AppendObjectResult;
@@ -32,7 +52,7 @@ public static void main(String[] args) throws IOException {
3252
/*
3353
* Constructs a client instance with your account for accessing OSS
3454
*/
35-
OSSClient client = new OSSClient(endpoint, accessKeyId, accessKeySecret);
55+
OSS client = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
3656

3757
try {
3858
/*

src/samples/BucketOperationsSample.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
package samples;
221

322
import java.io.IOException;
@@ -11,7 +30,8 @@
1130
import java.util.UUID;
1231

1332
import com.aliyun.oss.ClientException;
14-
import com.aliyun.oss.OSSClient;
33+
import com.aliyun.oss.OSS;
34+
import com.aliyun.oss.OSSClientBuilder;
1535
import com.aliyun.oss.OSSException;
1636
import com.aliyun.oss.model.AccessControlList;
1737
import com.aliyun.oss.model.BucketLoggingResult;
@@ -37,7 +57,7 @@ public class BucketOperationsSample {
3757
private static String accessKeyId = "*** Provide your AccessKeyId ***";
3858
private static String accessKeySecret = "*** Provide your AccessKeySecret ***";
3959

40-
private static OSSClient client = null;
60+
private static OSS client = null;
4161

4262
private static String bucketName = "my-oss-bucket" + UUID.randomUUID();
4363

@@ -46,7 +66,7 @@ public static void main(String[] args) throws IOException {
4666
/*
4767
* Constructs a client instance with your account for accessing OSS
4868
*/
49-
client = new OSSClient(endpoint, accessKeyId, accessKeySecret);
69+
client = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
5070

5171
try {
5272
/*

src/samples/CRCSample.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
package samples;
221

322
import java.io.ByteArrayInputStream;
@@ -6,7 +25,8 @@
625

726
import com.aliyun.oss.ClientException;
827
import com.aliyun.oss.InconsistentException;
9-
import com.aliyun.oss.OSSClient;
28+
import com.aliyun.oss.OSS;
29+
import com.aliyun.oss.OSSClientBuilder;
1030
import com.aliyun.oss.OSSException;
1131
import com.aliyun.oss.common.utils.IOUtils;
1232
import com.aliyun.oss.internal.OSSUtils;
@@ -38,7 +58,7 @@ public static void main(String[] args) throws IOException {
3858
// ClientConfiguration config = new ClientConfiguration();
3959
// config.setCrcCheckEnabled(false);
4060
// OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
41-
OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
61+
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
4262

4363
try {
4464

src/samples/CallbackSample.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
package samples;
221

322
import java.io.ByteArrayInputStream;
423
import java.io.IOException;
524

625
import com.aliyun.oss.ClientException;
7-
import com.aliyun.oss.OSSClient;
26+
import com.aliyun.oss.OSS;
27+
import com.aliyun.oss.OSSClientBuilder;
828
import com.aliyun.oss.OSSException;
929
import com.aliyun.oss.model.Callback;
1030
import com.aliyun.oss.model.Callback.CalbackBodyType;
@@ -29,7 +49,7 @@ public class CallbackSample {
2949

3050
public static void main(String[] args) throws IOException {
3151

32-
OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
52+
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
3353

3454
try {
3555
String content = "Hello OSS";
@@ -49,8 +69,8 @@ public static void main(String[] args) throws IOException {
4969

5070
PutObjectResult putObjectResult = ossClient.putObject(putObjectRequest);
5171
byte[] buffer = new byte[1024];
52-
putObjectResult.getCallbackResponseBody().read(buffer);
53-
putObjectResult.getCallbackResponseBody().close();
72+
putObjectResult.getResponse().getContent().read(buffer);
73+
putObjectResult.getResponse().getContent().close();
5474

5575
} catch (OSSException oe) {
5676
System.out.println("Caught an OSSException, which means your request made it to OSS, "

src/samples/ConcurrentGetObjectSample.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
package samples;
221

322
import java.io.File;
@@ -13,7 +32,8 @@
1332
import java.util.concurrent.atomic.AtomicInteger;
1433

1534
import com.aliyun.oss.ClientException;
16-
import com.aliyun.oss.OSSClient;
35+
import com.aliyun.oss.OSS;
36+
import com.aliyun.oss.OSSClientBuilder;
1737
import com.aliyun.oss.OSSException;
1838
import com.aliyun.oss.model.GetObjectRequest;
1939
import com.aliyun.oss.model.OSSObject;
@@ -30,7 +50,7 @@ public class ConcurrentGetObjectSample {
3050
private static String accessKeyId = "*** Provide your AccessKeyId ***";
3151
private static String accessKeySecret = "*** Provide your AccessKeySecret ***";
3252

33-
private static OSSClient client = null;
53+
private static OSS client = null;
3454

3555
private static String bucketName = "*** Provide bucket name ***";
3656
private static String key = "*** Provide key ***";
@@ -43,7 +63,7 @@ public static void main(String[] args) throws IOException {
4363
/*
4464
* Constructs a client instance with your account for accessing OSS
4565
*/
46-
client = new OSSClient(endpoint, accessKeyId, accessKeySecret);
66+
client = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
4767

4868
try {
4969
/*

src/samples/CreateFolderSample.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
package samples;
221

322
import java.io.ByteArrayInputStream;
423
import java.io.IOException;
524

625
import com.aliyun.oss.ClientException;
7-
import com.aliyun.oss.OSSClient;
26+
import com.aliyun.oss.OSS;
27+
import com.aliyun.oss.OSSClientBuilder;
828
import com.aliyun.oss.OSSException;
929
import com.aliyun.oss.model.OSSObject;
1030

@@ -24,7 +44,7 @@ public static void main(String[] args) throws IOException {
2444
/*
2545
* Constructs a client instance with your account for accessing OSS
2646
*/
27-
OSSClient client = new OSSClient(endpoint, accessKeyId, accessKeySecret);
47+
OSS client = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
2848

2949
try {
3050
/*

src/samples/DeleteObjectsSample.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
package samples;
221

322
import java.io.ByteArrayInputStream;
@@ -7,7 +26,8 @@
726
import java.util.List;
827

928
import com.aliyun.oss.ClientException;
10-
import com.aliyun.oss.OSSClient;
29+
import com.aliyun.oss.OSS;
30+
import com.aliyun.oss.OSSClientBuilder;
1131
import com.aliyun.oss.OSSException;
1232
import com.aliyun.oss.model.DeleteObjectsRequest;
1333
import com.aliyun.oss.model.DeleteObjectsResult;
@@ -28,7 +48,7 @@ public static void main(String[] args) throws IOException {
2848
/*
2949
* Constructs a client instance with your account for accessing OSS
3050
*/
31-
OSSClient client = new OSSClient(endpoint, accessKeyId, accessKeySecret);
51+
OSS client = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
3252

3353
try {
3454
/*

src/samples/DownloadSample.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
120
package samples;
221

322
import java.io.IOException;
423

524
import com.aliyun.oss.ClientException;
6-
import com.aliyun.oss.OSSClient;
25+
import com.aliyun.oss.OSS;
26+
import com.aliyun.oss.OSSClientBuilder;
727
import com.aliyun.oss.OSSException;
828
import com.aliyun.oss.model.DownloadFileRequest;
929
import com.aliyun.oss.model.DownloadFileResult;
@@ -25,7 +45,7 @@ public class DownloadSample {
2545

2646
public static void main(String[] args) throws IOException {
2747

28-
OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
48+
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
2949

3050
try {
3151
DownloadFileRequest downloadFileRequest = new DownloadFileRequest(bucketName, key);

0 commit comments

Comments
 (0)