IOUtils.copy getting crash if size is more than 200MB, getting exception
[ERR] Resource exhaustion event: the JVM was unable to allocate memory from the heap.
We are using Java version 11 and allocated 2.5GB memory to our app container.
My code:
        InputStream inputStreamm = null;
        S3Object s3Object = null;
        try {
            s3Object = client.getObject(bucket, fileName);
            try (S3ObjectInputStream inputStream = s3Object.getObjectContent()) {
                ByteArrayOutputStream tempOutputStream = new ByteArrayOutputStream();
                IOUtils.copy(inputStream, tempOutputStream );
                inputStreamm = new ByteArrayInputStream(tempOutputStream .toByteArray());
            }
        } catch (Exception e){
            LOG.error(e.getMessage());
        }finally {
            s3Object.close();
        }
How can I solve this?