1576b58578e9b42910c91fc9d838188e2673140abMarc Blank/* 2576b58578e9b42910c91fc9d838188e2673140abMarc Blank * Copyright (C) 2008-2009 Marc Blank 3576b58578e9b42910c91fc9d838188e2673140abMarc Blank * Licensed to The Android Open Source Project. 4576b58578e9b42910c91fc9d838188e2673140abMarc Blank * 5576b58578e9b42910c91fc9d838188e2673140abMarc Blank * Licensed under the Apache License, Version 2.0 (the "License"); 6576b58578e9b42910c91fc9d838188e2673140abMarc Blank * you may not use this file except in compliance with the License. 7576b58578e9b42910c91fc9d838188e2673140abMarc Blank * You may obtain a copy of the License at 8576b58578e9b42910c91fc9d838188e2673140abMarc Blank * 9576b58578e9b42910c91fc9d838188e2673140abMarc Blank * http://www.apache.org/licenses/LICENSE-2.0 10576b58578e9b42910c91fc9d838188e2673140abMarc Blank * 11576b58578e9b42910c91fc9d838188e2673140abMarc Blank * Unless required by applicable law or agreed to in writing, software 12576b58578e9b42910c91fc9d838188e2673140abMarc Blank * distributed under the License is distributed on an "AS IS" BASIS, 13576b58578e9b42910c91fc9d838188e2673140abMarc Blank * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14576b58578e9b42910c91fc9d838188e2673140abMarc Blank * See the License for the specific language governing permissions and 15576b58578e9b42910c91fc9d838188e2673140abMarc Blank * limitations under the License. 16576b58578e9b42910c91fc9d838188e2673140abMarc Blank */ 17576b58578e9b42910c91fc9d838188e2673140abMarc Blank 18576b58578e9b42910c91fc9d838188e2673140abMarc Blankpackage com.android.exchange; 19576b58578e9b42910c91fc9d838188e2673140abMarc Blank 20576b58578e9b42910c91fc9d838188e2673140abMarc Blankimport java.io.IOException; 21576b58578e9b42910c91fc9d838188e2673140abMarc Blankimport java.io.InputStream; 22576b58578e9b42910c91fc9d838188e2673140abMarc Blank 23576b58578e9b42910c91fc9d838188e2673140abMarc Blank/** 24576b58578e9b42910c91fc9d838188e2673140abMarc Blank * MockParserStream is an InputStream that feeds pre-generated data into various EasParser 25576b58578e9b42910c91fc9d838188e2673140abMarc Blank * subclasses. 26576b58578e9b42910c91fc9d838188e2673140abMarc Blank * 27576b58578e9b42910c91fc9d838188e2673140abMarc Blank * After parsing is done, the result can be obtained with getResult 28576b58578e9b42910c91fc9d838188e2673140abMarc Blank * 29576b58578e9b42910c91fc9d838188e2673140abMarc Blank */ 30576b58578e9b42910c91fc9d838188e2673140abMarc Blankpublic class MockParserStream extends InputStream { 31576b58578e9b42910c91fc9d838188e2673140abMarc Blank int[] array; 32576b58578e9b42910c91fc9d838188e2673140abMarc Blank int pos = 0; 33576b58578e9b42910c91fc9d838188e2673140abMarc Blank Object value; 34576b58578e9b42910c91fc9d838188e2673140abMarc Blank 35576b58578e9b42910c91fc9d838188e2673140abMarc Blank MockParserStream (int[] _array) { 36576b58578e9b42910c91fc9d838188e2673140abMarc Blank array = _array; 37576b58578e9b42910c91fc9d838188e2673140abMarc Blank } 38576b58578e9b42910c91fc9d838188e2673140abMarc Blank 39576b58578e9b42910c91fc9d838188e2673140abMarc Blank @Override 40576b58578e9b42910c91fc9d838188e2673140abMarc Blank public int read() throws IOException { 41576b58578e9b42910c91fc9d838188e2673140abMarc Blank try { 42576b58578e9b42910c91fc9d838188e2673140abMarc Blank return array[pos++]; 43576b58578e9b42910c91fc9d838188e2673140abMarc Blank } catch (IndexOutOfBoundsException e) { 44576b58578e9b42910c91fc9d838188e2673140abMarc Blank throw new IOException("End of stream"); 45576b58578e9b42910c91fc9d838188e2673140abMarc Blank } 46576b58578e9b42910c91fc9d838188e2673140abMarc Blank } 47576b58578e9b42910c91fc9d838188e2673140abMarc Blank 48576b58578e9b42910c91fc9d838188e2673140abMarc Blank public void setResult(Object _value) { 49576b58578e9b42910c91fc9d838188e2673140abMarc Blank value = _value; 50576b58578e9b42910c91fc9d838188e2673140abMarc Blank } 51576b58578e9b42910c91fc9d838188e2673140abMarc Blank 52576b58578e9b42910c91fc9d838188e2673140abMarc Blank public Object getResult() { 53576b58578e9b42910c91fc9d838188e2673140abMarc Blank return value; 54576b58578e9b42910c91fc9d838188e2673140abMarc Blank } 55576b58578e9b42910c91fc9d838188e2673140abMarc Blank} 56