Skip to content

Commit 5dff199

Browse files
committed
Update README.md
1 parent 5a3b324 commit 5dff199

File tree

1 file changed

+37
-24
lines changed

1 file changed

+37
-24
lines changed

README.md

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ This example lists all the buckets available to the specific user (specified by
1515

1616
```java
1717

18+
package com.spectralogic.ds3client.samples;
19+
1820
import com.spectralogic.ds3client.Ds3Client;
1921
import com.spectralogic.ds3client.Ds3ClientBuilder;
2022
import com.spectralogic.ds3client.commands.GetServiceRequest;
@@ -28,17 +30,18 @@ import java.security.SignatureException;
2830
public class Ds3ServiceListExample {
2931

3032
public static void main(final String args[]) throws IOException, SignatureException {
31-
33+
3234
// Get a client builder and then build a client instance. This is the main entry point to the SDK.
3335
final Ds3Client client = Ds3ClientBuilder.create("ds3Endpoint:8080",
34-
new Credentials("accessKey", "secretKey")).build();
36+
new Credentials("accessKey", "secretKey")).withHttpSecure(false).build();
3537

3638
// Tell the client to get us a list of all buckets, this is called a service list.
37-
final GetServiceResponse response = client.getService(new GetServiceRequest());
39+
try (final GetServiceResponse response = client.getService(new GetServiceRequest())) {
3840

39-
// Iterate through all the buckets and print them to the console.
40-
for(final Bucket bucket: response.getResult().getBuckets()) {
41-
System.out.println(bucket.getName());
41+
// Iterate through all the buckets and print them to the console.
42+
for (final Bucket bucket : response.getResult().getBuckets()) {
43+
System.out.println(bucket.getName());
44+
}
4245
}
4346
}
4447
}
@@ -51,6 +54,8 @@ This example will explore a user specified diretory on the local filesystem and
5154

5255
```java
5356

57+
package com.spectralogic.ds3client.samples;
58+
5459
import com.spectralogic.ds3client.Ds3Client;
5560
import com.spectralogic.ds3client.Ds3ClientBuilder;
5661
import com.spectralogic.ds3client.helpers.Ds3ClientHelpers;
@@ -69,6 +74,7 @@ public class BulkPutExample {
6974
public static void main(final String args[]) throws IOException, SignatureException, XmlProcessingException {
7075
final Ds3Client client = Ds3ClientBuilder.create("endpoint:8080",
7176
new Credentials("accessId", "secretKey"))
77+
.withHttpSecure(false)
7278
.build();
7379

7480
// Wrap the Ds3Client with the helper functions
@@ -102,12 +108,16 @@ This next example is a little more complex and will perform a bulk get from a DS
102108

103109
```java
104110

111+
package com.spectralogic.ds3client.samples;
112+
105113
import com.spectralogic.ds3client.Ds3Client;
106114
import com.spectralogic.ds3client.Ds3ClientBuilder;
107115
import com.spectralogic.ds3client.commands.*;
108116
import com.spectralogic.ds3client.models.Contents;
109117
import com.spectralogic.ds3client.models.Credentials;
118+
import com.spectralogic.ds3client.models.bulk.BulkObject;
110119
import com.spectralogic.ds3client.models.bulk.Ds3Object;
120+
import com.spectralogic.ds3client.models.bulk.MasterObjectList;
111121
import com.spectralogic.ds3client.models.bulk.Objects;
112122
import com.spectralogic.ds3client.serializer.XmlProcessingException;
113123

@@ -126,10 +136,10 @@ import java.util.List;
126136
public class Ds3BulkGetExample {
127137

128138
public static void main(final String args[]) throws IOException, SignatureException, XmlProcessingException {
129-
139+
130140
// Get a client builder and then build a client instance. This is the main entry point to the SDK.
131141
final Ds3Client client = Ds3ClientBuilder.create("ds3Endpoint:8080",
132-
new Credentials("accessKey", "secretKey")).build();
142+
new Credentials("accessKey", "secretKey")).withHttpSecure(false).build();
133143

134144
final String bucket = "bucketName"; //The bucket we are interested in getting objects from.
135145

@@ -151,23 +161,26 @@ public class Ds3BulkGetExample {
151161
}
152162

153163
// Prime DS3 with the BulkGet command so that it can start to get objects off of tape.
154-
final BulkGetResponse bulkResponse = client.bulkGet(new BulkGetRequest(bucket, objectList));
155-
156-
// The bulk response returns a list of lists which is designed to optimize data transmission from DS3.
157-
final MasterObjectList list = bulkResponse.getResult();
158-
for(final Objects objects: list.getObjects()) {
159-
for(final Ds3Object obj: objects) {
160-
161-
// Perform the operation to get the object from DS3.
162-
final GetObjectResponse getObjectResponse = client.getObject(new GetObjectRequest(bucket, obj.getName(), list.getJobid()));
163-
164-
final Path filePath = dirPath.resolve(obj.getName());
165-
// Here we are using automatic resource cleanup to make sure the streams we use are cleaned up after use.
166-
try(final InputStream objStream = getObjectResponse.getContent();
167-
final OutputStream fileOut = Files.newOutputStream(filePath)) {
168-
IOUtils.copy(objStream, fileOut); //Using IOUtils to copy the object contents to a file.
164+
// All Response objects to the SDK implement the Closeable interface and can be used in try-with-resource blocks
165+
try (final BulkGetResponse bulkResponse = client.bulkGet(new BulkGetRequest(bucket, objectList))) {
166+
167+
// The bulk response returns a list of lists which is designed to optimize data transmission from DS3.
168+
final MasterObjectList list = bulkResponse.getResult();
169+
for (final Objects objects : list.getObjects()) {
170+
for (final BulkObject obj : objects) {
171+
172+
// Perform the operation to get the object from DS3.
173+
try (final GetObjectResponse getObjectResponse = client.getObject(
174+
new GetObjectRequest(bucket, obj.getName(), obj.getOffset(), list.getJobId()))) {
175+
176+
final Path filePath = dirPath.resolve(obj.getName());
177+
// Here we are using automatic resource cleanup to make sure the streams we use are cleaned up after use.
178+
try (final InputStream objStream = getObjectResponse.getContent();
179+
final OutputStream fileOut = Files.newOutputStream(filePath)) {
180+
IOUtils.copy(objStream, fileOut); //Using IOUtils to copy the object contents to a file.
181+
}
182+
}
169183
}
170-
171184
}
172185
}
173186
}

0 commit comments

Comments
 (0)