Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class FastestScanner {
  4. private InputStreamReader in;
  5. byte curByte = -2;
  6.  
  7. public FastestScanner(InputStream stream) {
  8. in = new InputStreamReader(stream);
  9. }
  10.  
  11. public boolean endOfStream() {
  12. return curByte == -1;
  13. }
  14.  
  15. public void readByte() throws IOException {
  16. curByte = (byte) in.read();
  17. }
  18.  
  19. public boolean endOfLine() {
  20. return curByte < 32;
  21. }
  22.  
  23. public Integer nextInt() throws IOException {
  24. StringBuilder number = new StringBuilder(); int sign = 1;
  25. while (!endOfLine()) {
  26. if (curByte >= '0' && curByte <= '9' || curByte == '-') {
  27. break;
  28. }
  29. curByte = (byte) in.read();
  30. }
  31. if (curByte == '-') {
  32. sign = -1;
  33. curByte = (byte) in.read();
  34. }
  35. while (curByte >= '0' && curByte <= '9') {
  36. number.append((char) curByte);
  37. curByte = (byte) in.read();
  38. }
  39. if (number.length() == 0) {
  40. return null;
  41. } else {
  42. return sign * Integer.parseInt(number.toString());
  43. }
  44. }
  45.  
  46. public void close() throws IOException {
  47. in.close();
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement