Class S3ObjectInputStream

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
com.amazonaws.internal.SdkFilterInputStream
com.amazonaws.services.s3.model.S3ObjectInputStream
All Implemented Interfaces:
com.amazonaws.internal.MetricAware, com.amazonaws.internal.Releasable, Closeable, AutoCloseable

public class S3ObjectInputStream extends com.amazonaws.internal.SdkFilterInputStream
Input stream representing the content of an S3Object. In addition to the methods supplied by the InputStream class, S3ObjectInputStream supplies the abort() method, which will terminate an HTTP connection to the S3 object.
  • Constructor Details

    • S3ObjectInputStream

      public S3ObjectInputStream(InputStream in, org.apache.http.client.methods.HttpRequestBase httpRequest)
    • S3ObjectInputStream

      public S3ObjectInputStream(InputStream in, org.apache.http.client.methods.HttpRequestBase httpRequest, boolean collectMetrics)
  • Method Details

    • abort

      public void abort()
      Can be used to provide abortion logic prior to throwing the AbortedException. No-op by default. Aborts the underlying http request without reading any more data and closes the stream.

      By default Apache HttpClient tries to reuse http connections by reading to the end of an attached input stream on InputStream.close(). This is efficient from a socket pool management perspective, but for objects with large payloads can incur significant overhead while bytes are read from s3 and discarded. It's up to clients to decide when to take the performance hit implicit in not reusing an http connection in order to not read unnecessary information from S3.

      Overrides:
      abort in class com.amazonaws.internal.SdkFilterInputStream
      See Also:
      • EofSensorInputStream
    • getHttpRequest

      public org.apache.http.client.methods.HttpRequestBase getHttpRequest()
      Returns the http request from which this input stream is derived.
    • available

      public int available() throws IOException
      Returns super.available() if the value is not zero or else always returns 1. This is necessary to get around a GZIPInputStream bug which would mis-behave in some edge cases upon zero returned from available(), causing file truncation.

      http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7036144

      Reference TT: 0034867351

      Overrides:
      available in class com.amazonaws.internal.SdkFilterInputStream
      Throws:
      IOException
    • read

      public int read() throws IOException
      Overrides:
      read in class com.amazonaws.internal.SdkFilterInputStream
      Throws:
      IOException
    • read

      public int read(byte[] b) throws IOException
      Overrides:
      read in class FilterInputStream
      Throws:
      IOException
    • read

      public int read(byte[] b, int off, int len) throws IOException
      Overrides:
      read in class com.amazonaws.internal.SdkFilterInputStream
      Throws:
      IOException
    • reset

      public void reset() throws IOException
      Overrides:
      reset in class com.amazonaws.internal.SdkFilterInputStream
      Throws:
      IOException
    • close

      public void close() throws IOException
      Delegate to abort() if there is data remaining in the stream. If the stream has been read completely, with no data remaining, safely close the stream.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class com.amazonaws.internal.SdkFilterInputStream
      Throws:
      IOException