package code.kalter.longflight; import java.io.IOException; import java.io.InputStream; /** * Для удобного чтения строк и других типов из файла. Является не более, чем * обёрткой для Inputstream * * @author KalterFive */ public class StringReader { private final InputStream inputStream; public StringReader(InputStream inputStream) { this.inputStream = inputStream; } public String nextString() throws IOException { StringBuffer stringBuffer = new StringBuffer(); int c = inputStream.read(); while (c != '\r' && c != -1) { stringBuffer.append((char) c); c = inputStream.read(); } inputStream.read(); return stringBuffer.toString(); } // читает true or false public boolean nextBool() throws IOException { String line = nextString(); if (line.equals("true")) { return true; } else if (line.equals("false")) { return false; } else { throw new IllegalArgumentException(line); } } public byte nextByte() throws IOException { return Byte.parseByte(nextString()); } public short nextShort() throws IOException { return Short.parseShort(nextString()); } public int nextInt() throws IOException { return Integer.parseInt(nextString()); } public long nextLong() throws IOException { return Long.parseLong(nextString()); } public float nextFloat() throws IOException { return Float.parseFloat(nextString()); } public double nextDouble() throws IOException { return Double.parseDouble(nextString()); } public void close() throws IOException { inputStream.close(); } }