Skip to content

Commit 60470e4

Browse files
author
Hans-Peter Klett
committed
Updated the samples directory based on the new API
1 parent 04003e9 commit 60470e4

File tree

3 files changed

+28
-30
lines changed

3 files changed

+28
-30
lines changed

sdk/src/samples/java/com/spectralogic/ds3client/samples/BulkPutExample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ public static void main(final String args[]) throws IOException, SignatureExcept
3838

3939
// Create the write job with the bucket we want to write to and the list
4040
// of objects that will be written
41-
final Ds3ClientHelpers.WriteJob job = helper.startWriteJob(bucketName, objects);
41+
final Ds3ClientHelpers.Job job = helper.startWriteJob(bucketName, objects);
4242

4343
// Start the write job using an Object Putter that will read the files
4444
// from the local file system.
45-
job.write(new FileObjectPutter(inputPath));
45+
job.transfer(new FileObjectPutter(inputPath));
4646
}
4747
}

sdk/src/samples/java/com/spectralogic/ds3client/samples/Ds3BulkGetExample.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@
1111
import com.spectralogic.ds3client.models.bulk.Objects;
1212
import com.spectralogic.ds3client.serializer.XmlProcessingException;
1313

14-
import org.apache.commons.io.IOUtils;
15-
1614
import java.io.IOException;
17-
import java.io.InputStream;
18-
import java.io.OutputStream;
15+
import java.nio.channels.FileChannel;
1916
import java.nio.file.FileSystems;
2017
import java.nio.file.Files;
2118
import java.nio.file.Path;
19+
import java.nio.file.StandardOpenOption;
2220
import java.security.SignatureException;
2321
import java.util.ArrayList;
2422
import java.util.List;
@@ -51,26 +49,27 @@ public static void main(final String args[]) throws IOException, SignatureExcept
5149
}
5250

5351
// Prime DS3 with the BulkGet command so that it can start to get objects off of tape.
54-
// All Response objects to the SDK implement the Closeable interface and can be used in try-with-resource blocks
55-
try (final BulkGetResponse bulkResponse = client.bulkGet(new BulkGetRequest(bucket, objectList))) {
56-
57-
// The bulk response returns a list of lists which is designed to optimize data transmission from DS3.
58-
final MasterObjectList list = bulkResponse.getResult();
59-
for (final Objects objects : list.getObjects()) {
60-
for (final BulkObject obj : objects) {
52+
final BulkGetResponse bulkResponse = client.bulkGet(new BulkGetRequest(bucket, objectList));
6153

62-
// Perform the operation to get the object from DS3.
63-
try (final GetObjectResponse getObjectResponse = client.getObject(
64-
new GetObjectRequest(bucket, obj.getName(), obj.getOffset(), list.getJobId()))) {
54+
// The bulk response returns a list of lists which is designed to optimize data transmission from DS3.
55+
final MasterObjectList list = bulkResponse.getResult();
56+
for (final Objects objects : list.getObjects()) {
57+
for (final BulkObject obj : objects) {
58+
final FileChannel channel = FileChannel.open(
59+
dirPath.resolve(obj.getName()),
60+
StandardOpenOption.WRITE,
61+
StandardOpenOption.CREATE,
62+
StandardOpenOption.TRUNCATE_EXISTING
63+
);
6564

66-
final Path filePath = dirPath.resolve(obj.getName());
67-
// Here we are using automatic resource cleanup to make sure the streams we use are cleaned up after use.
68-
try (final InputStream objStream = getObjectResponse.getContent();
69-
final OutputStream fileOut = Files.newOutputStream(filePath)) {
70-
IOUtils.copy(objStream, fileOut); //Using IOUtils to copy the object contents to a file.
71-
}
72-
}
73-
}
65+
// Perform the operation to get the object from DS3.
66+
client.getObject(new GetObjectRequest(
67+
bucket,
68+
obj.getName(),
69+
obj.getOffset(),
70+
list.getJobId(),
71+
channel
72+
));
7473
}
7574
}
7675
}

sdk/src/samples/java/com/spectralogic/ds3client/samples/Ds3ServiceListExample.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import com.spectralogic.ds3client.Ds3ClientBuilder;
55
import com.spectralogic.ds3client.commands.GetServiceRequest;
66
import com.spectralogic.ds3client.commands.GetServiceResponse;
7-
import com.spectralogic.ds3client.models.Credentials;
87
import com.spectralogic.ds3client.models.Bucket;
8+
import com.spectralogic.ds3client.models.Credentials;
99

1010
import java.io.IOException;
1111
import java.security.SignatureException;
@@ -19,12 +19,11 @@ public static void main(final String args[]) throws IOException, SignatureExcept
1919
new Credentials("accessKey", "secretKey")).withHttpSecure(false).build();
2020

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

24-
// Iterate through all the buckets and print them to the console.
25-
for (final Bucket bucket : response.getResult().getBuckets()) {
26-
System.out.println(bucket.getName());
27-
}
24+
// Iterate through all the buckets and print them to the console.
25+
for (final Bucket bucket : response.getResult().getBuckets()) {
26+
System.out.println(bucket.getName());
2827
}
2928
}
3029
}

0 commit comments

Comments
 (0)