Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2014-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   *
   * Licensed under the Apache License, Version 2.0 (the "License").
   * You may not use this file except in compliance with the License.
   * A copy of the License is located at
   *
   *  http://aws.amazon.com/apache2.0
   *
  * or in the "license" file accompanying this file. This file is distributed
  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
 package com.amazonaws.event;
 
 
 
Used for input stream progress tracking purposes.
 
 public abstract class ProgressInputStream extends SdkFilterInputStream {
    
Returns an input stream for request progress tracking purposes. If request/response progress tracking is not enabled, this method simply return the given input stream as is.

Parameters:
is the request content input stream
 
     public static InputStream inputStreamForRequest(InputStream is,
             AmazonWebServiceRequest req) {
         return req == null
              ? is
              : new RequestProgressInputStream(isreq.getGeneralProgressListener());
     }

    
Returns an input stream for response progress tracking purposes. If request/response progress tracking is not enabled, this method simply return the given input stream as is.

Parameters:
is the response content input stream
 
     public static InputStream inputStreamForResponse(InputStream is,
             AmazonWebServiceRequest req) {
         return req == null
              ? is
              : new ResponseProgressInputStream(isreq.getGeneralProgressListener());
     }

    
The threshold of bytes between notifications.
 
     private static final int DEFAULT_NOTIFICATION_THRESHOLD = 8 * 1024;
 
     private final ProgressListener listener;
     private final int notifyThresHold;
    
The number of bytes read that the listener hasn't been notified about yet.
 
     private int unnotifiedByteCount;
     private boolean hasBeenRead;
     private boolean doneEOF;
     private long notifiedByteCount;
 
     public ProgressInputStream(InputStream isProgressListener listener) {
         this(islistener);
     }
 
     public ProgressInputStream(InputStream isProgressListener listenerint notifyThresHold) {
         super(is);
         if (is == null || listener == null)
             throw new IllegalArgumentException();
         this. = notifyThresHold;
         this. = listener;
     }

    
The read method is called for the very first time. Defaults to do nothing.
 
     protected void onFirstRead() {}
    
An end-of-file event is to be notified. Defaults to do nothing.
 
     protected void onEOF() {}

    
Defaults to behave the same as onEOF().
 
     protected void onClose() {
         eof();
     }
    
A reset event is to be notified. Default to do nothing.
    protected void onReset() {}
    
Upon notification of the number of bytes transferred since last notification. Default to do nothing.
    protected void onNotifyBytesRead() {}

    
Upon reading the given number of bytes. The default behavior is to accumulate the byte count and only fire off a notification by invoking onNotifyBytesRead() if the count has exceeded the threshold.
    private void onBytesRead(int bytesRead) {
         += bytesRead;
        if ( >= ) {
            onNotifyBytesRead();
             += ;
             = 0;
        }
    }
    @Override
    public int read() throws IOException {
        if (!) {
            onFirstRead();
             = true;
        }
        int ch = super.read();
        if (ch == -1)
            eof();
        else
            onBytesRead(1);
        return ch;
    }
    @Override
    public void reset() throws IOException {
        super.reset();
        onReset();
         = 0;
         = 0;
    }
    @Override
    public int read(byte[] bint offint lenthrows IOException {
        if (!) {
            onFirstRead();
             = true;
        }
        int bytesRead = super.read(bofflen);
        if (bytesRead == -1)
            eof();
        else
            onBytesRead(bytesRead);
        return bytesRead;
    }
    private void eof() {
        if ()
            return;
        onEOF();
         = 0;
         = true;
    }
    public final InputStream getWrappedInputStream() {
        return ;
    }
    protected final int getUnnotifiedByteCount() {
        return ;
    }
    protected final long getNotifiedByteCount() {
        return ;
    }
    @Override
    public void close() throws IOException {
        onClose(); // report any left over bytes not yet reported
        super.close();
    }
    public final ProgressListener getListener() {
        return ;
    }
New to GrepCode? Check out our FAQ X