4b8793c2e2b5cf78e60d9435a138d26083e69c16
1 package code
.kalter
.longflight
;
3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
7 * Для удобного чтения строк и других типов из файла. Является не более, чем
8 * обёрткой для Inputstream
12 public class StringReader
{
14 private final InputStream inputStream
;
16 public StringReader(InputStream inputStream
) {
17 this.inputStream
= inputStream
;
20 public String
nextString() throws IOException
{
21 StringBuffer stringBuffer
= new StringBuffer();
22 int c
= inputStream
.read();
23 while (c
!= '\r' && c
!= -1) {
24 stringBuffer
.append((char) c
);
25 c
= inputStream
.read();
28 return stringBuffer
.toString();
31 // читает true or false
32 public boolean nextBool() throws IOException
{
33 String line
= nextString();
34 if (line
.equals("true")) {
36 } else if (line
.equals("false")) {
39 throw new IllegalArgumentException(line
);
43 public byte nextByte() throws IOException
{
44 return Byte
.parseByte(nextString());
47 public short nextShort() throws IOException
{
48 return Short
.parseShort(nextString());
51 public int nextInt() throws IOException
{
52 return Integer
.parseInt(nextString());
55 public long nextLong() throws IOException
{
56 return Long
.parseLong(nextString());
59 public float nextFloat() throws IOException
{
60 return Float
.parseFloat(nextString());
63 public double nextDouble() throws IOException
{
64 return Double
.parseDouble(nextString());
67 public void close() throws IOException
{