Home | History | Annotate | Download | only in exchange
      1 /*
      2  * Copyright (C) 2008-2009 Marc Blank
      3  * Licensed to The Android Open Source Project.
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 package com.android.exchange;
     19 
     20 import java.io.IOException;
     21 import java.io.InputStream;
     22 
     23 /**
     24  * MockParserStream is an InputStream that feeds pre-generated data into various EasParser
     25  * subclasses.
     26  *
     27  * After parsing is done, the result can be obtained with getResult
     28  *
     29  */
     30 public class MockParserStream extends InputStream {
     31     int[] array;
     32     int pos = 0;
     33     Object value;
     34 
     35     MockParserStream (int[] _array) {
     36         array = _array;
     37     }
     38 
     39     @Override
     40     public int read() throws IOException {
     41         try {
     42             return array[pos++];
     43         } catch (IndexOutOfBoundsException e) {
     44             throw new IOException("End of stream");
     45         }
     46     }
     47 
     48     public void setResult(Object _value) {
     49         value = _value;
     50     }
     51 
     52     public Object getResult() {
     53         return value;
     54     }
     55 }
     56