Reader class has been improved

This commit is contained in:
Sameer Rahmani 2019-12-10 22:25:01 +00:00
parent 7f06e14ec9
commit aa16324991
1 changed files with 19 additions and 0 deletions

View File

@ -1,7 +1,9 @@
package serene.simple;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PushbackReader;
import java.util.List;
public class Reader {
@ -22,4 +24,21 @@ public class Reader {
return readSymbol(inputStream);
}
}
public static ListNode read(InputStream inputStream) throws IOException {
return read(new PushbackReader(new InputStreamReader(inputStream)));
}
public static ListNode read(PushbackReader inputStream) throws IOException {
List<Node> nodes = new ArrayList<Node>();
skipWhitespaces(inputStream);
char c = inputStream.read();
while ((byte) c != -1) {
inputStream.unread(c);
nodes.add(readNode(inputStream));
skipWhitespaces(inputStream);
c = (char) inputStream.read();
}
}