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.util;
 
 
An internal class used solely for the purpose of testing via failure injection.
 
 public class UnreliableFilterInputStream extends FilterInputStream {
    
Max number of errors that can be triggered.
 
     private int maxNumErrors = 1;
    
Current number of errors that have been triggered.
 
     private int currNumErrors;
     
     private int bytesReadBeforeException = 100;
     private int marked;
     private int position;
     // True to throw a FakeIOException; false to throw a RuntimeException
     private final boolean isFakeIOException;
     private int resetCount// number of times the reset method has been called
     
used to control whether an exception would be thrown based on the reset recurrence; not applicable if set to zero. For example, if resetIntervalBeforeException == n, the exception can only be thrown before the n_th reset (or after the n_th minus 1 reset), 2n_th reset (or after the 2n_th minus 1) reset), etc.
 
     private int resetIntervalBeforeException
 
     public UnreliableFilterInputStream(InputStream inboolean isFakeIOException) {
         super(in);
         this. = isFakeIOException;
     }
 
     @Override
     public int read() throws IOException {
         int read = super.read();
         if (read != -1) ++;
         triggerError();
         return read;
     }
 
     @Override
     public int read(byte[] bint offint lenthrows IOException {
         triggerError();
         int read = super.read(bofflen);
          += read;
         triggerError();
         return read;
     }
 
     @Override
     public void mark(int readlimit) {
         super.mark(readlimit);
          = ;
     }
 
     @Override
     public void reset() throws IOException {
         ++;
         super.reset();
          = ;
     }
 
     private void triggerError() throws FakeIOException {
         if ( >= )
             return;
 
         if ( >= ) {
             if ( > 0
             &&   %  != (-1))
                 return;
             ++;
             if ()
                 throw new FakeIOException("Fake IO error " + 
                     + " on UnreliableFileInputStream: " + this);
             else
                throw new RuntimeException("Injected runtime error " + 
                        + " on UnreliableFileInputStream: " + this);
        }
    }
    public int getCurrNumErrors() {
        return ;
    }
    public int getMaxNumErrors() {
        return ;
    }
    public UnreliableFilterInputStream withMaxNumErrors(int maxNumErrors) {
        this. = maxNumErrors;
        return this
    }
            int bytesReadBeforeException) {
        this. = bytesReadBeforeException;
        return this;
    }
    public int getBytesReadBeforeException() {
        return ;
    }

    

Parameters:
resetIntervalBeforeException used to control whether an exception would be thrown based on the reset recurrence; not applicable if set to zero. For example, if resetIntervalBeforeException == n, the exception can only be thrown before the n_th reset (or after the n_th minus 1 reset), 2n_th reset (or after the 2n_th minus 1) reset), etc.
            int resetIntervalBeforeException) {
        this. = resetIntervalBeforeException;
        return this;
    }
    public int getResetIntervalBeforeException() {
        return ;
    }
 
    public int getMarked() {
        return ;
    }
    public int getPosition() {
        return ;
    }
    public boolean isFakeIOException() {
        return ;
    }
    public int getResetCount() {
        return ;
    }
    
    @Override
    public String toString() {
        return Jackson.toJsonString(this);
    }
New to GrepCode? Check out our FAQ X