DEADSOFTWARE

README.MD -> README.md
[Lib_rms.git] / src / StringInputStream.java
1 /**
2 * Осуществляет удобное чтения из буфера
3 * @author Kalter
4 */
6 public class StringInputStream{
8 /**
9 * Строковой буфер, откуда производится чтение
10 */
11 private final String string;
13 /**
14 * Позиция чтения
15 */
16 private int position;
18 /**
19 * @param string Буфер, откуда будет производится чтение
20 */
21 public StringInputStream(String string){
23 this.string=string;
24 position=0;
25 }
27 /**
28 * @return Следующий символ из буфера
29 * @throws IndexOutOfBoundsException При выходе позиции чтения за границы
30 * буфера
31 */
32 public int read() throws IndexOutOfBoundsException{
34 int index=position++;
35 if(index>=string.length())throw new IndexOutOfBoundsException("empty");
36 return string.charAt(index);
37 }
39 /**
40 * @return Строка до символа остановки
41 * @throws IndexOutOfBoundsException При выходе позиции чтения за границы
42 * буфера
43 */
44 public String readString() throws IndexOutOfBoundsException{
46 StringBuffer result=new StringBuffer();
47 int c=read();
48 while(c!='|'){
50 result.append((char)c);
51 c=read();
52 }
53 return result.toString();
54 }
55 }