Convert InputStream to byte array in Java

前端 未结 30 3573
無奈伤痛
無奈伤痛 2020-11-21 12:08

How do I read an entire InputStream into a byte array?

30条回答
  •  面向向阳花
    2020-11-21 12:53

    We are seeing some delay for few AWS transaction, while converting S3 object to ByteArray.

    Note: S3 Object is PDF document (max size is 3 mb).

    We are using the option #1 (org.apache.commons.io.IOUtils) to convert the S3 object to ByteArray. We have noticed S3 provide the inbuild IOUtils method to convert the S3 object to ByteArray, we are request you to confirm what is the best way to convert the S3 object to ByteArray to avoid the delay.

    Option #1:

    import org.apache.commons.io.IOUtils;
    is = s3object.getObjectContent();
    content =IOUtils.toByteArray(is);
    

    Option #2:

    import com.amazonaws.util.IOUtils;
    is = s3object.getObjectContent();
    content =IOUtils.toByteArray(is);
    

    Also let me know if we have any other better way to convert the s3 object to bytearray

提交回复
热议问题