|
11 | 11 | import com.spectralogic.ds3client.models.bulk.Objects; |
12 | 12 | import com.spectralogic.ds3client.serializer.XmlProcessingException; |
13 | 13 |
|
14 | | -import org.apache.commons.io.IOUtils; |
15 | | - |
16 | 14 | import java.io.IOException; |
17 | | -import java.io.InputStream; |
18 | | -import java.io.OutputStream; |
| 15 | +import java.nio.channels.FileChannel; |
19 | 16 | import java.nio.file.FileSystems; |
20 | 17 | import java.nio.file.Files; |
21 | 18 | import java.nio.file.Path; |
| 19 | +import java.nio.file.StandardOpenOption; |
22 | 20 | import java.security.SignatureException; |
23 | 21 | import java.util.ArrayList; |
24 | 22 | import java.util.List; |
@@ -51,26 +49,27 @@ public static void main(final String args[]) throws IOException, SignatureExcept |
51 | 49 | } |
52 | 50 |
|
53 | 51 | // 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)); |
61 | 53 |
|
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 | + ); |
65 | 64 |
|
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 | + )); |
74 | 73 | } |
75 | 74 | } |
76 | 75 | } |
|
0 commit comments