Skip to content

Commit 60f1738

Browse files
author
Hans-Peter Klett
committed
Updated the README based on the samples.
1 parent 60470e4 commit 60f1738

File tree

1 file changed

+31
-33
lines changed

1 file changed

+31
-33
lines changed

README.md

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import com.spectralogic.ds3client.Ds3Client;
2727
import com.spectralogic.ds3client.Ds3ClientBuilder;
2828
import com.spectralogic.ds3client.commands.GetServiceRequest;
2929
import com.spectralogic.ds3client.commands.GetServiceResponse;
30-
import com.spectralogic.ds3client.models.Credentials;
3130
import com.spectralogic.ds3client.models.Bucket;
31+
import com.spectralogic.ds3client.models.Credentials;
3232

3333
import java.io.IOException;
3434
import java.security.SignatureException;
@@ -42,12 +42,11 @@ public class Ds3ServiceListExample {
4242
new Credentials("accessKey", "secretKey")).withHttpSecure(false).build();
4343

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

47-
// Iterate through all the buckets and print them to the console.
48-
for (final Bucket bucket : response.getResult().getBuckets()) {
49-
System.out.println(bucket.getName());
50-
}
47+
// Iterate through all the buckets and print them to the console.
48+
for (final Bucket bucket : response.getResult().getBuckets()) {
49+
System.out.println(bucket.getName());
5150
}
5251
}
5352
}
@@ -100,17 +99,17 @@ public class BulkPutExample {
10099

101100
// Create the write job with the bucket we want to write to and the list
102101
// of objects that will be written
103-
final Ds3ClientHelpers.WriteJob job = helper.startWriteJob(bucketName, objects);
102+
final Ds3ClientHelpers.Job job = helper.startWriteJob(bucketName, objects);
104103

105104
// Start the write job using an Object Putter that will read the files
106105
// from the local file system.
107-
job.write(new FileObjectPutter(inputPath));
106+
job.transfer(new FileObjectPutter(inputPath));
108107
}
109108
}
110109

111110
```
112111

113-
This next example is a little more complex and will perform a bulk get from a DS3 Appliance using the commands that directly correspond to the REST commands that are actually made against the DS3 Appliance. This example is meant to demonstrate the flexibilty of the SDK when writing applications where the helper functions cannot be used. The [Apache Commons IO](http://commons.apache.org/proper/commons-io/) library is used in this example for dealing with IO Streams.
112+
This next example is a little more complex and will perform a bulk get from a DS3 Appliance using the commands that directly correspond to the REST commands that are actually made against the DS3 Appliance. This example is meant to demonstrate the flexibilty of the SDK when writing applications where the helper functions cannot be used.
114113

115114
```java
116115

@@ -127,14 +126,12 @@ import com.spectralogic.ds3client.models.bulk.MasterObjectList;
127126
import com.spectralogic.ds3client.models.bulk.Objects;
128127
import com.spectralogic.ds3client.serializer.XmlProcessingException;
129128

130-
import org.apache.commons.io.IOUtils;
131-
132129
import java.io.IOException;
133-
import java.io.InputStream;
134-
import java.io.OutputStream;
130+
import java.nio.channels.FileChannel;
135131
import java.nio.file.FileSystems;
136132
import java.nio.file.Files;
137133
import java.nio.file.Path;
134+
import java.nio.file.StandardOpenOption;
138135
import java.security.SignatureException;
139136
import java.util.ArrayList;
140137
import java.util.List;
@@ -167,26 +164,27 @@ public class Ds3BulkGetExample {
167164
}
168165

169166
// Prime DS3 with the BulkGet command so that it can start to get objects off of tape.
170-
// All Response objects to the SDK implement the Closeable interface and can be used in try-with-resource blocks
171-
try (final BulkGetResponse bulkResponse = client.bulkGet(new BulkGetRequest(bucket, objectList))) {
172-
173-
// The bulk response returns a list of lists which is designed to optimize data transmission from DS3.
174-
final MasterObjectList list = bulkResponse.getResult();
175-
for (final Objects objects : list.getObjects()) {
176-
for (final BulkObject obj : objects) {
177-
178-
// Perform the operation to get the object from DS3.
179-
try (final GetObjectResponse getObjectResponse = client.getObject(
180-
new GetObjectRequest(bucket, obj.getName(), obj.getOffset(), list.getJobId()))) {
181-
182-
final Path filePath = dirPath.resolve(obj.getName());
183-
// Here we are using automatic resource cleanup to make sure the streams we use are cleaned up after use.
184-
try (final InputStream objStream = getObjectResponse.getContent();
185-
final OutputStream fileOut = Files.newOutputStream(filePath)) {
186-
IOUtils.copy(objStream, fileOut); //Using IOUtils to copy the object contents to a file.
187-
}
188-
}
189-
}
167+
final BulkGetResponse bulkResponse = client.bulkGet(new BulkGetRequest(bucket, objectList));
168+
169+
// The bulk response returns a list of lists which is designed to optimize data transmission from DS3.
170+
final MasterObjectList list = bulkResponse.getResult();
171+
for (final Objects objects : list.getObjects()) {
172+
for (final BulkObject obj : objects) {
173+
final FileChannel channel = FileChannel.open(
174+
dirPath.resolve(obj.getName()),
175+
StandardOpenOption.WRITE,
176+
StandardOpenOption.CREATE,
177+
StandardOpenOption.TRUNCATE_EXISTING
178+
);
179+
180+
// Perform the operation to get the object from DS3.
181+
client.getObject(new GetObjectRequest(
182+
bucket,
183+
obj.getName(),
184+
obj.getOffset(),
185+
list.getJobId(),
186+
channel
187+
));
190188
}
191189
}
192190
}

0 commit comments

Comments
 (0)