20
20
import com .microsoft .azure .batch .protocol .models .FileProperties ;
21
21
import com .microsoft .azure .batch .protocol .models .NodeFile ;
22
22
import com .microsoft .rest .ServiceResponseWithHeaders ;
23
- import rx .exceptions .Exceptions ;
24
- import rx .functions .Func1 ;
25
23
26
24
import java .io .*;
27
25
import java .util .Collection ;
@@ -261,12 +259,12 @@ public void deleteFileFromComputeNode(String poolId, String nodeId, String fileN
261
259
* @param jobId The ID of the job containing the task.
262
260
* @param taskId The ID of the task.
263
261
* @param fileName The name of the file to download.
264
- * @return A stream into which the file contents will be written.
262
+ * @param outputStream A stream into which the file contents will be written.
265
263
* @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
266
264
* @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
267
265
*/
268
- public InputStream getFileFromTask (String jobId , String taskId , String fileName ) throws BatchErrorException , IOException {
269
- return getFileFromTask (jobId , taskId , fileName , null );
266
+ public void getFileFromTask (String jobId , String taskId , String fileName , OutputStream outputStream ) throws BatchErrorException , IOException {
267
+ getFileFromTask (jobId , taskId , fileName , null , outputStream );
270
268
}
271
269
272
270
/**
@@ -276,36 +274,16 @@ public InputStream getFileFromTask(String jobId, String taskId, String fileName)
276
274
* @param taskId The ID of the task.
277
275
* @param fileName The name of the file to download.
278
276
* @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
279
- * @return A stream into which the file contents will be written.
277
+ * @param outputStream A stream into which the file contents will be written.
280
278
* @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
281
279
* @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
282
280
*/
283
- public InputStream getFileFromTask (String jobId , String taskId , String fileName , Iterable <BatchClientBehavior > additionalBehaviors ) throws BatchErrorException , IOException {
281
+ public void getFileFromTask (String jobId , String taskId , String fileName , Iterable <BatchClientBehavior > additionalBehaviors , OutputStream outputStream ) throws BatchErrorException , IOException {
284
282
FileGetFromTaskOptions options = new FileGetFromTaskOptions ();
285
283
BehaviorManager bhMgr = new BehaviorManager (this .customBehaviors (), additionalBehaviors );
286
284
bhMgr .applyRequestBehaviors (options );
287
285
288
- // Duplicate the stream due to AutoRest issue https://github.com/Azure/autorest/issues/1385
289
- ByteArrayOutputStream output = this ._parentBatchClient .protocolLayer ().files ().getFromTaskAsync (jobId , taskId , fileName , options )
290
- .map (new Func1 <InputStream , ByteArrayOutputStream >() {
291
- @ Override
292
- public ByteArrayOutputStream call (InputStream input ) {
293
- ByteArrayOutputStream buffer = new ByteArrayOutputStream ();
294
- byte [] data = new byte [16384 ];
295
- int nRead ;
296
- try {
297
- while ((nRead = input .read (data , 0 , data .length )) != -1 ) {
298
- buffer .write (data , 0 , nRead );
299
- }
300
- buffer .flush ();
301
- return buffer ;
302
- } catch (IOException e ) {
303
- throw Exceptions .propagate (e );
304
- }
305
- }
306
- }).toBlocking ().single ();
307
-
308
- return new ByteArrayInputStream (output .toByteArray ());
286
+ this ._parentBatchClient .protocolLayer ().files ().getFromTask (jobId , taskId , fileName , options , outputStream );
309
287
}
310
288
311
289
/**
@@ -314,12 +292,12 @@ public ByteArrayOutputStream call(InputStream input) {
314
292
* @param poolId The ID of the pool that contains the compute node.
315
293
* @param nodeId The ID of the compute node.
316
294
* @param fileName The name of the file to download.
317
- * @return A stream into which the file contents will be written.
295
+ * @param outputStream A stream into which the file contents will be written.
318
296
* @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
319
297
* @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
320
298
*/
321
- public InputStream getFileFromComputeNode (String poolId , String nodeId , String fileName ) throws BatchErrorException , IOException {
322
- return getFileFromComputeNode (poolId , nodeId , fileName , null );
299
+ public void getFileFromComputeNode (String poolId , String nodeId , String fileName , OutputStream outputStream ) throws BatchErrorException , IOException {
300
+ getFileFromComputeNode (poolId , nodeId , fileName , null , outputStream );
323
301
}
324
302
325
303
/**
@@ -329,36 +307,16 @@ public InputStream getFileFromComputeNode(String poolId, String nodeId, String f
329
307
* @param nodeId The ID of the compute node.
330
308
* @param fileName The name of the file to download.
331
309
* @param additionalBehaviors A collection of {@link BatchClientBehavior} instances that are applied to the Batch service request.
332
- * @return A stream into which the file contents will be written.
310
+ * @param outputStream A stream into which the file contents will be written.
333
311
* @throws BatchErrorException Exception thrown when an error response is received from the Batch service.
334
312
* @throws IOException Exception thrown when there is an error in serialization/deserialization of data sent to/received from the Batch service.
335
313
*/
336
- public InputStream getFileFromComputeNode (String poolId , String nodeId , String fileName , Iterable <BatchClientBehavior > additionalBehaviors ) throws BatchErrorException , IOException {
314
+ public void getFileFromComputeNode (String poolId , String nodeId , String fileName , Iterable <BatchClientBehavior > additionalBehaviors , OutputStream outputStream ) throws BatchErrorException , IOException {
337
315
FileGetFromComputeNodeOptions options = new FileGetFromComputeNodeOptions ();
338
316
BehaviorManager bhMgr = new BehaviorManager (this .customBehaviors (), additionalBehaviors );
339
317
bhMgr .applyRequestBehaviors (options );
340
318
341
- // Duplicate the stream due to AutoRest issue https://github.com/Azure/autorest/issues/1385
342
- ByteArrayOutputStream output = this ._parentBatchClient .protocolLayer ().files ().getFromComputeNodeAsync (poolId , nodeId , fileName , options )
343
- .map (new Func1 <InputStream , ByteArrayOutputStream >() {
344
- @ Override
345
- public ByteArrayOutputStream call (InputStream input ) {
346
- ByteArrayOutputStream buffer = new ByteArrayOutputStream ();
347
- byte [] data = new byte [16384 ];
348
- int nRead ;
349
- try {
350
- while ((nRead = input .read (data , 0 , data .length )) != -1 ) {
351
- buffer .write (data , 0 , nRead );
352
- }
353
- buffer .flush ();
354
- return buffer ;
355
- } catch (IOException e ) {
356
- throw Exceptions .propagate (e );
357
- }
358
- }
359
- }).toBlocking ().single ();
360
-
361
- return new ByteArrayInputStream (output .toByteArray ());
319
+ this ._parentBatchClient .protocolLayer ().files ().getFromComputeNode (poolId , nodeId , fileName , options , outputStream );
362
320
}
363
321
364
322
/**
0 commit comments