/** * Осуществляет удобное чтения из буфера * @author Kalter */ public class StringInputStream{ /** * Строковой буфер, откуда производится чтение */ private final String string; /** * Позиция чтения */ private int position; /** * @param string Буфер, откуда будет производится чтение */ public StringInputStream(String string){ this.string=string; position=0; } /** * @return Следующий символ из буфера * @throws IndexOutOfBoundsException При выходе позиции чтения за границы * буфера */ public int read() throws IndexOutOfBoundsException{ int index=position++; if(index>=string.length())throw new IndexOutOfBoundsException("empty"); return string.charAt(index); } /** * @return Строка до символа остановки * @throws IndexOutOfBoundsException При выходе позиции чтения за границы * буфера */ public String readString() throws IndexOutOfBoundsException{ StringBuffer result=new StringBuffer(); int c=read(); while(c!='|'){ result.append((char)c); c=read(); } return result.toString(); } }