@@ -94,38 +94,29 @@ static int s_aws_input_stream_read(struct aws_input_stream *stream, struct aws_b
9494 }
9595
9696 size_t out_remaining = dest -> capacity - dest -> len ;
97- int result = AWS_OP_SUCCESS ;
97+ size_t chunk_size = 1024 ;
9898 /* Newer updates allow part sizes up to 5GB. Since number of bytes required for a 5GB part is
9999 greater than INT_MAX, it would cause a bug where the java does not allocate memory and return a null buffer
100- since Java natively does not support direct allocation of buffers of capacity > Integer.MAX_VALUE. */
101- while ( out_remaining > 0 ) {
102- size_t chunk_size = INT_MAX ;
103- if (out_remaining <= chunk_size ) {
104- chunk_size = out_remaining ;
105- }
100+ since Java natively does not support direct allocation of buffers of capacity > Integer.MAX_VALUE.
101+ Since C handles recursively calling for more data, we read up to chunk size or out_remaining (whichever is lower)
102+ and return the C. */
103+ if (out_remaining <= chunk_size ) {
104+ chunk_size = out_remaining ;
105+ }
106106
107- jobject direct_buffer = aws_jni_direct_byte_buffer_from_raw_ptr (env , dest -> buffer + dest -> len , chunk_size );
107+ jobject direct_buffer = aws_jni_direct_byte_buffer_from_raw_ptr (env , dest -> buffer + dest -> len , chunk_size );
108108
109- impl -> body_done = (* env )-> CallBooleanMethod (
110- env , impl -> http_request_body_stream , http_request_body_stream_properties .send_outgoing_body , direct_buffer );
111-
112- if (aws_jni_check_and_clear_exception (env )) {
113- result = aws_raise_error (AWS_ERROR_HTTP_CALLBACK_FAILURE );
114- (* env )-> DeleteLocalRef (env , direct_buffer );
115- break ;
116- }
117-
118- size_t amt_written = aws_jni_byte_buffer_get_position (env , direct_buffer );
119- if (amt_written == 0 ) {
120- (* env )-> DeleteLocalRef (env , direct_buffer );
121- break ;
122- }
123- dest -> len += amt_written ;
124- out_remaining -= amt_written ;
109+ impl -> body_done = (* env )-> CallBooleanMethod (
110+ env , impl -> http_request_body_stream , http_request_body_stream_properties .send_outgoing_body , direct_buffer );
125111
112+ if (aws_jni_check_and_clear_exception (env )) {
113+ result = aws_raise_error (AWS_ERROR_HTTP_CALLBACK_FAILURE );
126114 (* env )-> DeleteLocalRef (env , direct_buffer );
115+ break ;
127116 }
128117
118+ (* env )-> DeleteLocalRef (env , direct_buffer );
119+
129120 aws_jni_release_thread_env (impl -> jvm , & jvm_env_context );
130121 /********** JNI ENV RELEASE **********/
131122
0 commit comments