15
15
16
16
package com .spectralogic .ds3client .helpers ;
17
17
18
+ import com .google .common .base .Function ;
19
+ import com .google .common .collect .FluentIterable ;
18
20
import com .spectralogic .ds3client .Ds3Client ;
19
21
import com .spectralogic .ds3client .helpers .options .ReadJobOptions ;
20
22
import com .spectralogic .ds3client .helpers .options .WriteJobOptions ;
23
25
import com .spectralogic .ds3client .serializer .XmlProcessingException ;
24
26
import com .spectralogic .ds3client .utils .Predicate ;
25
27
28
+ import javax .annotation .Nullable ;
26
29
import java .io .IOException ;
27
30
import java .nio .channels .SeekableByteChannel ;
28
31
import java .nio .file .Path ;
@@ -100,8 +103,8 @@ public static Ds3ClientHelpers wrap(final Ds3Client client, final int retryAfter
100
103
}
101
104
102
105
/**
103
- * Performs a bulk put job creation request and returns an {@link WriteJob }.
104
- * See {@link WriteJob } for information on how to write the objects for the job.
106
+ * Performs a bulk put job creation request and returns an {@link WriteJobImpl }.
107
+ * See {@link WriteJobImpl } for information on how to write the objects for the job.
105
108
*
106
109
* @throws SignatureException
107
110
* @throws IOException
@@ -111,8 +114,8 @@ public abstract Ds3ClientHelpers.Job startWriteJob(final String bucket, final It
111
114
throws SignatureException , IOException , XmlProcessingException ;
112
115
113
116
/**
114
- * Performs a bulk put job creation request and returns an {@link WriteJob }.
115
- * See {@link WriteJob } for information on how to write the objects for the job.
117
+ * Performs a bulk put job creation request and returns an {@link WriteJobImpl }.
118
+ * See {@link WriteJobImpl } for information on how to write the objects for the job.
116
119
*
117
120
* @throws SignatureException
118
121
* @throws IOException
@@ -122,8 +125,8 @@ public abstract Ds3ClientHelpers.Job startWriteJob(final String bucket, final It
122
125
throws SignatureException , IOException , XmlProcessingException ;
123
126
124
127
/**
125
- * Performs a bulk get job creation request and returns an {@link ReadJob }.
126
- * See {@link ReadJob } for information on how to read the objects for the job.
128
+ * Performs a bulk get job creation request and returns an {@link ReadJobImpl }.
129
+ * See {@link ReadJobImpl } for information on how to read the objects for the job.
127
130
*
128
131
* @throws SignatureException
129
132
* @throws IOException
@@ -133,8 +136,8 @@ public abstract Ds3ClientHelpers.Job startReadJob(final String bucket, final Ite
133
136
throws SignatureException , IOException , XmlProcessingException ;
134
137
135
138
/**
136
- * Performs a bulk get job creation request and returns an {@link ReadJob }.
137
- * See {@link ReadJob } for information on how to read the objects for the job.
139
+ * Performs a bulk get job creation request and returns an {@link ReadJobImpl }.
140
+ * See {@link ReadJobImpl } for information on how to read the objects for the job.
138
141
*
139
142
* @throws SignatureException
140
143
* @throws IOException
@@ -147,7 +150,7 @@ public abstract Ds3ClientHelpers.Job startReadJob(
147
150
throws SignatureException , IOException , XmlProcessingException ;
148
151
149
152
/**
150
- * Performs a bulk get job creation request for all of the objects in the given bucket and returns an {@link ReadJob }.
153
+ * Performs a bulk get job creation request for all of the objects in the given bucket and returns an {@link ReadJobImpl }.
151
154
*
152
155
* @throws SignatureException
153
156
* @throws IOException
@@ -157,7 +160,7 @@ public abstract Ds3ClientHelpers.Job startReadAllJob(final String bucket)
157
160
throws SignatureException , IOException , XmlProcessingException ;
158
161
159
162
/**
160
- * Performs a bulk get job creation request for all of the objects in the given bucket and returns an {@link ReadJob }.
163
+ * Performs a bulk get job creation request for all of the objects in the given bucket and returns an {@link ReadJobImpl }.
161
164
*
162
165
* @throws SignatureException
163
166
* @throws IOException
@@ -167,7 +170,7 @@ public abstract Ds3ClientHelpers.Job startReadAllJob(final String bucket, final
167
170
throws SignatureException , IOException , XmlProcessingException ;
168
171
169
172
/**
170
- * Queries job information based on job id and returns a {@link ReadJob } that can resume the job.
173
+ * Queries job information based on job id and returns a {@link ReadJobImpl } that can resume the job.
171
174
* @throws SignatureException
172
175
* @throws IOException
173
176
* @throws XmlProcessingException
@@ -177,7 +180,7 @@ public abstract Ds3ClientHelpers.Job recoverWriteJob(final UUID jobId)
177
180
throws SignatureException , IOException , XmlProcessingException , JobRecoveryException ;
178
181
179
182
/**
180
- * Queries job information based on job id and returns a {@link WriteJob } that can resume the job.
183
+ * Queries job information based on job id and returns a {@link WriteJobImpl } that can resume the job.
181
184
* @throws SignatureException
182
185
* @throws IOException
183
186
* @throws XmlProcessingException
@@ -265,7 +268,7 @@ public abstract Iterable<Contents> listObjects(final String bucket, final String
265
268
266
269
267
270
/**
268
- * Returns an object list with which you can call {@code startWriteJob } based on the files in a {@code directory}.
271
+ * Returns an object list with which you can call {@code startWriteJobImpl } based on the files in a {@code directory}.
269
272
* This method traverses the {@code directory} recursively.
270
273
*
271
274
* @throws IOException
@@ -288,14 +291,41 @@ public abstract Iterable<Contents> listObjects(final String bucket, final String
288
291
*/
289
292
public abstract Iterable <Ds3Object > removePrefixFromDs3ObjectsList (final Iterable <Ds3Object > objectsList , final String prefix );
290
293
291
- /**
292
- * Filter out folders from the object list. Use this method when piping the list of objects from listObjects to a bulk job.
293
- * @param objects
294
- * @return
295
- */
296
- public abstract Iterable <Ds3Object > toDs3Iterable (final Iterable <Contents > objects );
294
+ public Iterable <Ds3Object > toDs3Iterable (final Iterable <Contents > objects ) {
295
+ return toDs3Iterable (objects , null );
296
+ }
297
297
298
- public abstract Iterable <Ds3Object > toDs3Iterable (final Iterable <Contents > objects , final Predicate <Contents > filter );
298
+ @ SafeVarargs
299
+ public final Iterable <Ds3Object > toDs3Iterable (final Iterable <Contents > objects , final Predicate <Contents >... filters ) {
300
+
301
+ FluentIterable <Contents > fluentIterable = FluentIterable .from (objects ).filter (new com .google .common .base .Predicate <Contents >() {
302
+ @ Override
303
+ public boolean apply (@ Nullable final Contents input ) {
304
+ return input != null ;
305
+ }
306
+ });
307
+
308
+ for (final Predicate <Contents > filter : filters ) {
309
+ fluentIterable = fluentIterable .filter (new com .google .common .base .Predicate <Contents >() {
310
+ @ Override
311
+ public boolean apply (@ Nullable final Contents input ) {
312
+ if (filter != null ) {
313
+ return filter .test (input );
314
+ } else {
315
+ return true ; // do not filter anything if filter is null
316
+ }
317
+ }
318
+ });
319
+ }
320
+
321
+ return fluentIterable .transform (new Function <Contents , Ds3Object >() {
322
+ @ Nullable
323
+ @ Override
324
+ public Ds3Object apply (@ Nullable final Contents input ) {
325
+ return new Ds3Object (input .getKey (), input .getSize ());
326
+ }
327
+ });
328
+ }
299
329
/**
300
330
* Strip prefix from the beginning of objectName. If objectName does not start with prefix, return objectName unmodified.
301
331
* @param objectName
0 commit comments