@@ -331,18 +331,15 @@ public ServiceCall<Ranking> rank(final String rankerID, final File answers, Inte
331331 Validator .notNull (answers , "answers file cannot be null" );
332332 Validator .isTrue (answers .exists (), "answers file: " + answers .getAbsolutePath () + " not found" );
333333
334- final JsonObject contentJson = new JsonObject ();
335- contentJson .addProperty (ANSWERS , ((topAnswers != null ) && (topAnswers > 0 )) ? topAnswers : 10 );
336-
337- okhttp3 .MultipartBody .Builder builder = new MultipartBody .Builder ()
334+ final okhttp3 .MultipartBody .Builder builder = new MultipartBody .Builder ()
338335 .setType (MultipartBody .FORM )
339336 .addPart (Headers .of (
340337 HttpHeaders .CONTENT_DISPOSITION , "form-data; name=\" answer_data\" " ),
341- RequestBody .create (HttpMediaType .BINARY_FILE , answers )
342- );
338+ RequestBody .create (HttpMediaType .BINARY_FILE , answers ));
343339
344- if (topAnswers != null )
340+ if (topAnswers != null ) {
345341 builder .addFormDataPart (ANSWERS , topAnswers .toString ());
342+ }
346343
347344 final String path = String .format (PATH_RANK , rankerID );
348345 final Request request = RequestBuilder .post (path ).body (builder .build ()).build ();
@@ -361,9 +358,6 @@ public ServiceCall<Ranking> rank(final String rankerID, final InputStream answer
361358 Validator .isTrue ((rankerID != null ) && !rankerID .isEmpty (), "rankerID cannot be null or empty" );
362359 Validator .notNull (answers , "answers file cannot be null" );
363360
364- final JsonObject contentJson = new JsonObject ();
365- contentJson .addProperty (ANSWERS , ((topAnswers != null ) && (topAnswers > 0 )) ? topAnswers : 10 );
366-
367361 final ByteArrayOutputStream answersBuffer = new ByteArrayOutputStream ();
368362 int bytesRead ;
369363 final byte [] data = new byte [10000 ];
@@ -375,15 +369,18 @@ public ServiceCall<Ranking> rank(final String rankerID, final InputStream answer
375369 throw new RuntimeException ("Error reading search results input" , e );
376370 }
377371
378- final RequestBody body = new MultipartBody .Builder ().setType (MultipartBody .FORM )
379- .addPart (Headers .of (HttpHeaders .CONTENT_DISPOSITION , "form-data; name=\" answer_data\" " ),
380- RequestBody .create (HttpMediaType .BINARY_FILE , answersBuffer .toByteArray ()))
381- .addPart (Headers .of (HttpHeaders .CONTENT_DISPOSITION , "form-data; name=\" answer_metadata\" " ),
382- RequestBody .create (HttpMediaType .TEXT , contentJson .toString ()))
383- .build ();
372+ final okhttp3 .MultipartBody .Builder builder = new MultipartBody .Builder ()
373+ .setType (MultipartBody .FORM )
374+ .addPart (Headers .of (
375+ HttpHeaders .CONTENT_DISPOSITION , "form-data; name=\" answer_data\" " ),
376+ RequestBody .create (HttpMediaType .BINARY_FILE , answersBuffer .toByteArray ()));
377+
378+ if (topAnswers != null ) {
379+ builder .addFormDataPart (ANSWERS , topAnswers .toString ());
380+ }
384381
385382 final String path = String .format (PATH_RANK , rankerID );
386- final Request request = RequestBuilder .post (path ).body (body ).build ();
383+ final Request request = RequestBuilder .post (path ).body (builder . build () ).build ();
387384 return createServiceCall (request , ResponseConverterUtils .getObject (Ranking .class ));
388385 }
389386
0 commit comments