@@ -121,11 +121,11 @@ public void testSendingSmallFilesAndByteArray() throws Exception {
121
121
.addBodyPart (new StringPart ("Name" , "Dominic" ))
122
122
.addBodyPart (new FilePart ("file3" , testResource3File , "text/plain" , UTF_8 ))
123
123
.addBodyPart (new StringPart ("Age" , "3" )).addBodyPart (new StringPart ("Height" , "shrimplike" ))
124
- .addBodyPart (new InputStreamPart ("inputStream3" , inputStreamFile3 , testResource3File .length (), testResource3File .getName (), "text/plain" , UTF_8 ))
125
- .addBodyPart (new InputStreamPart ("inputStream2" , inputStreamFile2 , testResource2File .length (), testResource2File .getName (), "application/x-gzip" , null ))
124
+ .addBodyPart (new InputStreamPart ("inputStream3" , inputStreamFile3 , testResource3File .getName (), testResource3File .length (), "text/plain" , UTF_8 ))
125
+ .addBodyPart (new InputStreamPart ("inputStream2" , inputStreamFile2 , testResource2File .getName (), testResource2File .length (), "application/x-gzip" , null ))
126
126
.addBodyPart (new StringPart ("Hair" , "ridiculous" )).addBodyPart (new ByteArrayPart ("file4" ,
127
127
expectedContents .getBytes (UTF_8 ), "text/plain" , UTF_8 , "bytearray.txt" ))
128
- .addBodyPart (new InputStreamPart ("inputStream1" , inputStreamFile1 , testResource1File .length (), testResource1File .getName (), "text/plain" , UTF_8 ))
128
+ .addBodyPart (new InputStreamPart ("inputStream1" , inputStreamFile1 , testResource1File .getName (), testResource1File .length (), "text/plain" , UTF_8 ))
129
129
.build ();
130
130
131
131
Response res = c .executeRequest (r ).get ();
@@ -157,26 +157,63 @@ public void sendEmptyFileZeroCopy() throws Exception {
157
157
sendEmptyFile0 (false );
158
158
}
159
159
160
- private void sendEmptyFileInputStream0 (boolean disableZeroCopy ) throws Exception {
160
+ private void sendEmptyFileInputStream (boolean disableZeroCopy ) throws Exception {
161
161
File file = getClasspathFile ("empty.txt" );
162
162
try (AsyncHttpClient c = asyncHttpClient (config ().setDisableZeroCopy (disableZeroCopy ))) {
163
163
InputStream inputStream = new BufferedInputStream (new FileInputStream (file ));
164
164
Request r = post ("http://localhost" + ":" + port1 + "/upload" )
165
- .addBodyPart (new InputStreamPart ("file" , inputStream , file .length (), file .getName (), "text/plain" , UTF_8 )).build ();
165
+ .addBodyPart (new InputStreamPart ("file" , inputStream , file .getName (), file .length (), "text/plain" , UTF_8 )).build ();
166
166
167
167
Response res = c .executeRequest (r ).get ();
168
168
assertEquals (res .getStatusCode (), 200 );
169
169
}
170
170
}
171
171
172
172
@ Test
173
- public void sendEmptyFileInputStream () throws Exception {
174
- sendEmptyFileInputStream0 (true );
173
+ public void testSendEmptyFileInputStream () throws Exception {
174
+ sendEmptyFileInputStream (true );
175
175
}
176
176
177
177
@ Test
178
- public void sendEmptyFileInputStreamZeroCopy () throws Exception {
179
- sendEmptyFileInputStream0 (false );
178
+ public void testSendEmptyFileInputStreamZeroCopy () throws Exception {
179
+ sendEmptyFileInputStream (false );
180
+ }
181
+
182
+ private void sendFileInputStream (boolean useContentLength , boolean disableZeroCopy ) throws Exception {
183
+ File file = getClasspathFile ("textfile.txt" );
184
+ try (AsyncHttpClient c = asyncHttpClient (config ().setDisableZeroCopy (disableZeroCopy ))) {
185
+ InputStream inputStream = new BufferedInputStream (new FileInputStream (file ));
186
+ InputStreamPart part ;
187
+ if (useContentLength ) {
188
+ part = new InputStreamPart ("file" , inputStream , file .getName (), file .length ());
189
+ } else {
190
+ part = new InputStreamPart ("file" , inputStream , file .getName ());
191
+ }
192
+ Request r = post ("http://localhost" + ":" + port1 + "/upload" ).addBodyPart (part ).build ();
193
+
194
+ Response res = c .executeRequest (r ).get ();
195
+ assertEquals (res .getStatusCode (), 200 );
196
+ }
197
+ }
198
+
199
+ @ Test
200
+ public void testSendFileInputStreamUnknownContentLength () throws Exception {
201
+ sendFileInputStream (false , true );
202
+ }
203
+
204
+ @ Test
205
+ public void testSendFileInputStreamZeroCopyUnknownContentLength () throws Exception {
206
+ sendFileInputStream (false , false );
207
+ }
208
+
209
+ @ Test
210
+ public void testSendFileInputStreamKnownContentLength () throws Exception {
211
+ sendFileInputStream (true , true );
212
+ }
213
+
214
+ @ Test
215
+ public void testSendFileInputStreamZeroCopyKnownContentLength () throws Exception {
216
+ sendFileInputStream (true , false );
180
217
}
181
218
182
219
/**
0 commit comments