1 /** 2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 * SPDX-License-Identifier: Apache-2.0. 4 */ 5 6 package software.amazon.awssdk.crt.http; 7 8 import java.nio.ByteBuffer; 9 10 /** 11 * Interface that Native code knows how to call when handling Http Request bodies 12 * 13 */ 14 public interface HttpRequestBodyStream { 15 16 17 /** 18 * Called from Native when the Http Request has a Body (Eg PUT/POST requests). 19 * Note that this function may be called many times as Native sends the Request Body. 20 * 21 * Do NOT keep a reference to this ByteBuffer past the lifetime of this function call. The CommonRuntime reserves 22 * the right to use DirectByteBuffers pointing to memory that only lives as long as the function call. 23 * 24 * @param bodyBytesOut The Buffer to write the Request Body Bytes to. 25 * @return True if Request body is complete, false otherwise. 26 */ sendRequestBody(ByteBuffer bodyBytesOut)27 default boolean sendRequestBody(ByteBuffer bodyBytesOut) { 28 /* Optional Callback, return empty request body by default unless user wants to return one. */ 29 return true; 30 } 31 32 /** 33 * Called from native when the processing needs the stream to rewind itself back to its beginning. 34 * If the stream does not support rewinding or the rewind fails, false should be returned 35 * 36 * Signing requires a rewindable stream, but basic http does not. 37 * 38 * @return True if the stream was successfully rewound, false otherwise. 39 */ resetPosition()40 default boolean resetPosition() { return false; } 41 42 /** 43 * Called from native when the processing needs to know the length of the stream. 44 * If the stream does not know/support length, 0 should be returned. 45 * 46 * Signing requires a rewindable stream, but basic http does not. 47 * 48 * @return Stream length, or 0 if unknown stream or length is unsupported 49 */ getLength()50 default long getLength() { return 0; } 51 } 52