Skip to content

Commit f43dd10

Browse files
committed
Use Flowable<ByteBuffer> for streaming
1 parent 21a2ad2 commit f43dd10

File tree

7 files changed

+124
-148
lines changed

7 files changed

+124
-148
lines changed

src/JavaCodeGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public class JavaCodeGenerator : CodeGenerator
100100
"Duration",
101101
"Period",
102102
"BigDecimal",
103-
"Flowable<byte[]>"
103+
"Flowable<ByteBuffer>"
104104
};
105105

106106
private const string ClientRuntimePackage = "com.microsoft.rest.v2:client-runtime:2.0.0-SNAPSHOT from snapshot repo https://oss.sonatype.org/content/repositories/snapshots/";
@@ -2136,7 +2136,7 @@ private static IEnumerable<string> GetIModelTypeImports(IModelType modelType, Ja
21362136
result = new[] { "java.math.BigDecimal" };
21372137
break;
21382138
case KnownPrimaryType.Stream:
2139-
result = new[] { "io.reactivex.Flowable" };
2139+
result = new[] { "io.reactivex.Flowable", "java.nio.ByteBuffer" };
21402140
break;
21412141
case KnownPrimaryType.TimeSpan:
21422142
result = new[] { "org.joda.time.Period" };
@@ -2392,7 +2392,7 @@ private static string IModelTypeName(IModelType modelType, JavaSettings settings
23922392
result = PrimaryTypeGetWantNullable(primaryType) ? "Long" : "long";
23932393
break;
23942394
case KnownPrimaryType.Stream:
2395-
result = "Flowable<byte[]>";
2395+
result = "Flowable<ByteBuffer>";
23962396
break;
23972397
case KnownPrimaryType.String:
23982398
result = "String";

test/vanilla/src/main/java/fixtures/bodyfile/Files.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import io.reactivex.Maybe;
1919
import io.reactivex.Observable;
2020
import io.reactivex.Single;
21+
import java.nio.ByteBuffer;
2122

2223
/**
2324
* An instance of this class provides access to all the operations defined in
@@ -30,102 +31,102 @@ public interface Files {
3031
* @throws IllegalArgumentException thrown if parameters fail the validation.
3132
* @throws ErrorException thrown if the request is rejected by server.
3233
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
33-
* @return the Flowable&lt;byte[]&gt; object if successful.
34+
* @return the Flowable&lt;ByteBuffer&gt; object if successful.
3435
*/
35-
Flowable<byte[]> getFile();
36+
Flowable<ByteBuffer> getFile();
3637

3738
/**
3839
* Get file.
3940
*
4041
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
4142
* @throws IllegalArgumentException thrown if parameters fail the validation.
42-
* @return the {@link ServiceFuture&lt;Flowable&lt;byte[]&gt;&gt;} object.
43+
* @return the {@link ServiceFuture&lt;Flowable&lt;ByteBuffer&gt;&gt;} object.
4344
*/
44-
ServiceFuture<Flowable<byte[]>> getFileAsync(final ServiceCallback<Flowable<byte[]>> serviceCallback);
45+
ServiceFuture<Flowable<ByteBuffer>> getFileAsync(final ServiceCallback<Flowable<ByteBuffer>> serviceCallback);
4546

4647
/**
4748
* Get file.
4849
*
4950
* @throws IllegalArgumentException thrown if parameters fail the validation.
50-
* @return the {@link Single&lt;RestResponse&lt;Void, Flowable&lt;byte[]&gt;&gt;&gt;} object if successful.
51+
* @return the {@link Single&lt;RestResponse&lt;Void, Flowable&lt;ByteBuffer&gt;&gt;&gt;} object if successful.
5152
*/
52-
Single<RestResponse<Void, Flowable<byte[]>>> getFileWithRestResponseAsync();
53+
Single<RestResponse<Void, Flowable<ByteBuffer>>> getFileWithRestResponseAsync();
5354

5455
/**
5556
* Get file.
5657
*
5758
* @throws IllegalArgumentException thrown if parameters fail the validation.
58-
* @return the {@link Maybe&lt;Flowable&lt;byte[]&gt;&gt;} object if successful.
59+
* @return the {@link Maybe&lt;Flowable&lt;ByteBuffer&gt;&gt;} object if successful.
5960
*/
60-
Maybe<Flowable<byte[]>> getFileAsync();
61+
Maybe<Flowable<ByteBuffer>> getFileAsync();
6162

6263
/**
6364
* Get a large file.
6465
*
6566
* @throws IllegalArgumentException thrown if parameters fail the validation.
6667
* @throws ErrorException thrown if the request is rejected by server.
6768
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
68-
* @return the Flowable&lt;byte[]&gt; object if successful.
69+
* @return the Flowable&lt;ByteBuffer&gt; object if successful.
6970
*/
70-
Flowable<byte[]> getFileLarge();
71+
Flowable<ByteBuffer> getFileLarge();
7172

7273
/**
7374
* Get a large file.
7475
*
7576
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
7677
* @throws IllegalArgumentException thrown if parameters fail the validation.
77-
* @return the {@link ServiceFuture&lt;Flowable&lt;byte[]&gt;&gt;} object.
78+
* @return the {@link ServiceFuture&lt;Flowable&lt;ByteBuffer&gt;&gt;} object.
7879
*/
79-
ServiceFuture<Flowable<byte[]>> getFileLargeAsync(final ServiceCallback<Flowable<byte[]>> serviceCallback);
80+
ServiceFuture<Flowable<ByteBuffer>> getFileLargeAsync(final ServiceCallback<Flowable<ByteBuffer>> serviceCallback);
8081

8182
/**
8283
* Get a large file.
8384
*
8485
* @throws IllegalArgumentException thrown if parameters fail the validation.
85-
* @return the {@link Single&lt;RestResponse&lt;Void, Flowable&lt;byte[]&gt;&gt;&gt;} object if successful.
86+
* @return the {@link Single&lt;RestResponse&lt;Void, Flowable&lt;ByteBuffer&gt;&gt;&gt;} object if successful.
8687
*/
87-
Single<RestResponse<Void, Flowable<byte[]>>> getFileLargeWithRestResponseAsync();
88+
Single<RestResponse<Void, Flowable<ByteBuffer>>> getFileLargeWithRestResponseAsync();
8889

8990
/**
9091
* Get a large file.
9192
*
9293
* @throws IllegalArgumentException thrown if parameters fail the validation.
93-
* @return the {@link Maybe&lt;Flowable&lt;byte[]&gt;&gt;} object if successful.
94+
* @return the {@link Maybe&lt;Flowable&lt;ByteBuffer&gt;&gt;} object if successful.
9495
*/
95-
Maybe<Flowable<byte[]>> getFileLargeAsync();
96+
Maybe<Flowable<ByteBuffer>> getFileLargeAsync();
9697

9798
/**
9899
* Get empty file.
99100
*
100101
* @throws IllegalArgumentException thrown if parameters fail the validation.
101102
* @throws ErrorException thrown if the request is rejected by server.
102103
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
103-
* @return the Flowable&lt;byte[]&gt; object if successful.
104+
* @return the Flowable&lt;ByteBuffer&gt; object if successful.
104105
*/
105-
Flowable<byte[]> getEmptyFile();
106+
Flowable<ByteBuffer> getEmptyFile();
106107

107108
/**
108109
* Get empty file.
109110
*
110111
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
111112
* @throws IllegalArgumentException thrown if parameters fail the validation.
112-
* @return the {@link ServiceFuture&lt;Flowable&lt;byte[]&gt;&gt;} object.
113+
* @return the {@link ServiceFuture&lt;Flowable&lt;ByteBuffer&gt;&gt;} object.
113114
*/
114-
ServiceFuture<Flowable<byte[]>> getEmptyFileAsync(final ServiceCallback<Flowable<byte[]>> serviceCallback);
115+
ServiceFuture<Flowable<ByteBuffer>> getEmptyFileAsync(final ServiceCallback<Flowable<ByteBuffer>> serviceCallback);
115116

116117
/**
117118
* Get empty file.
118119
*
119120
* @throws IllegalArgumentException thrown if parameters fail the validation.
120-
* @return the {@link Single&lt;RestResponse&lt;Void, Flowable&lt;byte[]&gt;&gt;&gt;} object if successful.
121+
* @return the {@link Single&lt;RestResponse&lt;Void, Flowable&lt;ByteBuffer&gt;&gt;&gt;} object if successful.
121122
*/
122-
Single<RestResponse<Void, Flowable<byte[]>>> getEmptyFileWithRestResponseAsync();
123+
Single<RestResponse<Void, Flowable<ByteBuffer>>> getEmptyFileWithRestResponseAsync();
123124

124125
/**
125126
* Get empty file.
126127
*
127128
* @throws IllegalArgumentException thrown if parameters fail the validation.
128-
* @return the {@link Maybe&lt;Flowable&lt;byte[]&gt;&gt;} object if successful.
129+
* @return the {@link Maybe&lt;Flowable&lt;ByteBuffer&gt;&gt;} object if successful.
129130
*/
130-
Maybe<Flowable<byte[]>> getEmptyFileAsync();
131+
Maybe<Flowable<ByteBuffer>> getEmptyFileAsync();
131132
}

test/vanilla/src/main/java/fixtures/bodyfile/implementation/FilesImpl.java

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.reactivex.Observable;
2626
import io.reactivex.Single;
2727
import io.reactivex.functions.Function;
28+
import java.nio.ByteBuffer;
2829

2930
/**
3031
* An instance of this class provides access to all the operations defined in
@@ -60,17 +61,17 @@ interface FilesService {
6061
@GET("files/stream/nonempty")
6162
@ExpectedResponses({200})
6263
@UnexpectedResponseExceptionType(ErrorException.class)
63-
Single<RestResponse<Void, Flowable<byte[]>>> getFile();
64+
Single<RestResponse<Void, Flowable<ByteBuffer>>> getFile();
6465

6566
@GET("files/stream/verylarge")
6667
@ExpectedResponses({200})
6768
@UnexpectedResponseExceptionType(ErrorException.class)
68-
Single<RestResponse<Void, Flowable<byte[]>>> getFileLarge();
69+
Single<RestResponse<Void, Flowable<ByteBuffer>>> getFileLarge();
6970

7071
@GET("files/stream/empty")
7172
@ExpectedResponses({200})
7273
@UnexpectedResponseExceptionType(ErrorException.class)
73-
Single<RestResponse<Void, Flowable<byte[]>>> getEmptyFile();
74+
Single<RestResponse<Void, Flowable<ByteBuffer>>> getEmptyFile();
7475
}
7576

7677
/**
@@ -79,9 +80,9 @@ interface FilesService {
7980
* @throws IllegalArgumentException thrown if parameters fail the validation.
8081
* @throws ErrorException thrown if the request is rejected by server.
8182
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
82-
* @return the Flowable&lt;byte[]&gt; object if successful.
83+
* @return the Flowable&lt;ByteBuffer&gt; object if successful.
8384
*/
84-
public Flowable<byte[]> getFile() {
85+
public Flowable<ByteBuffer> getFile() {
8586
return getFileAsync().blockingGet();
8687
}
8788

@@ -90,32 +91,32 @@ public Flowable<byte[]> getFile() {
9091
*
9192
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
9293
* @throws IllegalArgumentException thrown if parameters fail the validation.
93-
* @return the {@link ServiceFuture&lt;Flowable&lt;byte[]&gt;&gt;} object.
94+
* @return the {@link ServiceFuture&lt;Flowable&lt;ByteBuffer&gt;&gt;} object.
9495
*/
95-
public ServiceFuture<Flowable<byte[]>> getFileAsync(final ServiceCallback<Flowable<byte[]>> serviceCallback) {
96+
public ServiceFuture<Flowable<ByteBuffer>> getFileAsync(final ServiceCallback<Flowable<ByteBuffer>> serviceCallback) {
9697
return ServiceFuture.fromBody(getFileAsync(), serviceCallback);
9798
}
9899

99100
/**
100101
* Get file.
101102
*
102103
* @throws IllegalArgumentException thrown if parameters fail the validation.
103-
* @return the {@link Single&lt;RestResponse&lt;Void, Flowable&lt;byte[]&gt;&gt;&gt;} object if successful.
104+
* @return the {@link Single&lt;RestResponse&lt;Void, Flowable&lt;ByteBuffer&gt;&gt;&gt;} object if successful.
104105
*/
105-
public Single<RestResponse<Void, Flowable<byte[]>>> getFileWithRestResponseAsync() {
106+
public Single<RestResponse<Void, Flowable<ByteBuffer>>> getFileWithRestResponseAsync() {
106107
return service.getFile();
107108
}
108109

109110
/**
110111
* Get file.
111112
*
112113
* @throws IllegalArgumentException thrown if parameters fail the validation.
113-
* @return the {@link Maybe&lt;Flowable&lt;byte[]&gt;&gt;} object if successful.
114+
* @return the {@link Maybe&lt;Flowable&lt;ByteBuffer&gt;&gt;} object if successful.
114115
*/
115-
public Maybe<Flowable<byte[]>> getFileAsync() {
116+
public Maybe<Flowable<ByteBuffer>> getFileAsync() {
116117
return getFileWithRestResponseAsync()
117-
.flatMapMaybe(new Function<RestResponse<Void, Flowable<byte[]>>, Maybe<Flowable<byte[]>>>() {
118-
public Maybe<Flowable<byte[]>> apply(RestResponse<Void, Flowable<byte[]>> restResponse) {
118+
.flatMapMaybe(new Function<RestResponse<Void, Flowable<ByteBuffer>>, Maybe<Flowable<ByteBuffer>>>() {
119+
public Maybe<Flowable<ByteBuffer>> apply(RestResponse<Void, Flowable<ByteBuffer>> restResponse) {
119120
if (restResponse.body() == null) {
120121
return Maybe.empty();
121122
} else {
@@ -131,9 +132,9 @@ public Maybe<Flowable<byte[]>> apply(RestResponse<Void, Flowable<byte[]>> restRe
131132
* @throws IllegalArgumentException thrown if parameters fail the validation.
132133
* @throws ErrorException thrown if the request is rejected by server.
133134
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
134-
* @return the Flowable&lt;byte[]&gt; object if successful.
135+
* @return the Flowable&lt;ByteBuffer&gt; object if successful.
135136
*/
136-
public Flowable<byte[]> getFileLarge() {
137+
public Flowable<ByteBuffer> getFileLarge() {
137138
return getFileLargeAsync().blockingGet();
138139
}
139140

@@ -142,32 +143,32 @@ public Flowable<byte[]> getFileLarge() {
142143
*
143144
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
144145
* @throws IllegalArgumentException thrown if parameters fail the validation.
145-
* @return the {@link ServiceFuture&lt;Flowable&lt;byte[]&gt;&gt;} object.
146+
* @return the {@link ServiceFuture&lt;Flowable&lt;ByteBuffer&gt;&gt;} object.
146147
*/
147-
public ServiceFuture<Flowable<byte[]>> getFileLargeAsync(final ServiceCallback<Flowable<byte[]>> serviceCallback) {
148+
public ServiceFuture<Flowable<ByteBuffer>> getFileLargeAsync(final ServiceCallback<Flowable<ByteBuffer>> serviceCallback) {
148149
return ServiceFuture.fromBody(getFileLargeAsync(), serviceCallback);
149150
}
150151

151152
/**
152153
* Get a large file.
153154
*
154155
* @throws IllegalArgumentException thrown if parameters fail the validation.
155-
* @return the {@link Single&lt;RestResponse&lt;Void, Flowable&lt;byte[]&gt;&gt;&gt;} object if successful.
156+
* @return the {@link Single&lt;RestResponse&lt;Void, Flowable&lt;ByteBuffer&gt;&gt;&gt;} object if successful.
156157
*/
157-
public Single<RestResponse<Void, Flowable<byte[]>>> getFileLargeWithRestResponseAsync() {
158+
public Single<RestResponse<Void, Flowable<ByteBuffer>>> getFileLargeWithRestResponseAsync() {
158159
return service.getFileLarge();
159160
}
160161

161162
/**
162163
* Get a large file.
163164
*
164165
* @throws IllegalArgumentException thrown if parameters fail the validation.
165-
* @return the {@link Maybe&lt;Flowable&lt;byte[]&gt;&gt;} object if successful.
166+
* @return the {@link Maybe&lt;Flowable&lt;ByteBuffer&gt;&gt;} object if successful.
166167
*/
167-
public Maybe<Flowable<byte[]>> getFileLargeAsync() {
168+
public Maybe<Flowable<ByteBuffer>> getFileLargeAsync() {
168169
return getFileLargeWithRestResponseAsync()
169-
.flatMapMaybe(new Function<RestResponse<Void, Flowable<byte[]>>, Maybe<Flowable<byte[]>>>() {
170-
public Maybe<Flowable<byte[]>> apply(RestResponse<Void, Flowable<byte[]>> restResponse) {
170+
.flatMapMaybe(new Function<RestResponse<Void, Flowable<ByteBuffer>>, Maybe<Flowable<ByteBuffer>>>() {
171+
public Maybe<Flowable<ByteBuffer>> apply(RestResponse<Void, Flowable<ByteBuffer>> restResponse) {
171172
if (restResponse.body() == null) {
172173
return Maybe.empty();
173174
} else {
@@ -183,9 +184,9 @@ public Maybe<Flowable<byte[]>> apply(RestResponse<Void, Flowable<byte[]>> restRe
183184
* @throws IllegalArgumentException thrown if parameters fail the validation.
184185
* @throws ErrorException thrown if the request is rejected by server.
185186
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
186-
* @return the Flowable&lt;byte[]&gt; object if successful.
187+
* @return the Flowable&lt;ByteBuffer&gt; object if successful.
187188
*/
188-
public Flowable<byte[]> getEmptyFile() {
189+
public Flowable<ByteBuffer> getEmptyFile() {
189190
return getEmptyFileAsync().blockingGet();
190191
}
191192

@@ -194,32 +195,32 @@ public Flowable<byte[]> getEmptyFile() {
194195
*
195196
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
196197
* @throws IllegalArgumentException thrown if parameters fail the validation.
197-
* @return the {@link ServiceFuture&lt;Flowable&lt;byte[]&gt;&gt;} object.
198+
* @return the {@link ServiceFuture&lt;Flowable&lt;ByteBuffer&gt;&gt;} object.
198199
*/
199-
public ServiceFuture<Flowable<byte[]>> getEmptyFileAsync(final ServiceCallback<Flowable<byte[]>> serviceCallback) {
200+
public ServiceFuture<Flowable<ByteBuffer>> getEmptyFileAsync(final ServiceCallback<Flowable<ByteBuffer>> serviceCallback) {
200201
return ServiceFuture.fromBody(getEmptyFileAsync(), serviceCallback);
201202
}
202203

203204
/**
204205
* Get empty file.
205206
*
206207
* @throws IllegalArgumentException thrown if parameters fail the validation.
207-
* @return the {@link Single&lt;RestResponse&lt;Void, Flowable&lt;byte[]&gt;&gt;&gt;} object if successful.
208+
* @return the {@link Single&lt;RestResponse&lt;Void, Flowable&lt;ByteBuffer&gt;&gt;&gt;} object if successful.
208209
*/
209-
public Single<RestResponse<Void, Flowable<byte[]>>> getEmptyFileWithRestResponseAsync() {
210+
public Single<RestResponse<Void, Flowable<ByteBuffer>>> getEmptyFileWithRestResponseAsync() {
210211
return service.getEmptyFile();
211212
}
212213

213214
/**
214215
* Get empty file.
215216
*
216217
* @throws IllegalArgumentException thrown if parameters fail the validation.
217-
* @return the {@link Maybe&lt;Flowable&lt;byte[]&gt;&gt;} object if successful.
218+
* @return the {@link Maybe&lt;Flowable&lt;ByteBuffer&gt;&gt;} object if successful.
218219
*/
219-
public Maybe<Flowable<byte[]>> getEmptyFileAsync() {
220+
public Maybe<Flowable<ByteBuffer>> getEmptyFileAsync() {
220221
return getEmptyFileWithRestResponseAsync()
221-
.flatMapMaybe(new Function<RestResponse<Void, Flowable<byte[]>>, Maybe<Flowable<byte[]>>>() {
222-
public Maybe<Flowable<byte[]>> apply(RestResponse<Void, Flowable<byte[]>> restResponse) {
222+
.flatMapMaybe(new Function<RestResponse<Void, Flowable<ByteBuffer>>, Maybe<Flowable<ByteBuffer>>>() {
223+
public Maybe<Flowable<ByteBuffer>> apply(RestResponse<Void, Flowable<ByteBuffer>> restResponse) {
223224
if (restResponse.body() == null) {
224225
return Maybe.empty();
225226
} else {

0 commit comments

Comments
 (0)