title: Filter an InputStream line-by-line
body: <p>I am retrieving large gzipped files from Amazon S3. I would like to be able to transform each line of these files on-the-fly and upload the output to another S3 bucket.</p>
  
  <p>The upload API takes an <a href="https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/model/PutObjectRequest.html#PutObjectRequest-java.lang.String-java.lang.String-java.io.InputStream-com.amazonaws.services.s3.model.ObjectMetadata-" rel="nofollow noreferrer"><code>InputStream</code></a> as input.</p>
  
  <pre><code>S3Object s3object = s3.fetch(bucket, key);
  
  InputStream is = new GZIPInputStream(s3object.getObjectContent());
  
  // . . . ?
  
  s3.putObject(new PutObjectRequest(bucket, key, is, metadata));
  </code></pre>
  
  <p>I believe that the most efficient way of doing this is to create my own custom input stream which transforms the original input stream into another input stream. I am not very familiar with this approach and curious to find out more. </p>