title: java.io.IOException: Attempted read on closed stream on aws s3 bucket
body: <p>I want to process a file using aws s3 bucket with java.</p>
  
  <p>My Code</p>
  
  <pre><code>AmazonS3 s3 = AmazonS3ClientBuilder.standard().build();
  // Get the object from the event and show its content type
  String srcBucket = event.getRecords().get(0).getS3().getBucket().getName();
  String srcKey = event.getRecords().get(0).getS3().getObject().getKey();
  
  S3Object s3Object = s3.getObject(new GetObjectRequest(srcBucket, srcKey));
  audioInputStream = s3Object.getObjectContent();
  
  processInputStreamMethod1(audioInputStream);
  
  processInputStreamMethod2(audioInputStream);
  </code></pre>
  
  <p>Obviously I get a</p>
  
  <blockquote>
    <p>java.io.IOException: Attempted read on closed stream</p>
  </blockquote>
  
  <p>what is the best way (best practice) to deal with this? Should I copy the Stream with a byte array, close the stream or close the s3Object?</p>
  
  <p>I am new to S3 and InputStreams</p>