Java  1.0
TextIO.java
Go to the documentation of this file.
1 
2 
3 import java.io.*;
4 import java.util.IllegalFormatException;
5 import java.util.regex.Matcher;
6 import java.util.regex.Pattern;
7 
8 import javax.swing.JFileChooser;
9 import javax.swing.JOptionPane;
10 
34 public class TextIO {
35 
36  /* Modified November 2007 to empty the TextIO input buffer when switching from one
37  * input source to another. This fixes a bug that allows input from the previous input
38  * source to be read after the new source has been selected.
39  */
40 
45  public final static char EOF = (char)0xFFFF;
46 
51  public final static char EOLN = '\n'; // The value returned by peek() when at end-of-line.
52 
53 
59  public static void readStandardInput() {
61  return;
62  try {
63  in.close();
64  }
65  catch (Exception e) {
66  }
67  emptyBuffer(); // Added November 2007
68  in = standardInput;
69  inputFileName = null;
70  readingStandardInput = true;
71  inputErrorCount = 0;
72  }
73 
80  public static void readStream(InputStream inputStream) {
81  if (inputStream == null)
83  else
84  readStream(new InputStreamReader(inputStream));
85  }
86 
93  public static void readStream(Reader inputStream) {
94  if (inputStream == null)
96  else {
97  if ( inputStream instanceof BufferedReader)
98  in = (BufferedReader)inputStream;
99  else
100  in = new BufferedReader(inputStream);
101  emptyBuffer(); // Added November 2007
102  inputFileName = null;
103  readingStandardInput = false;
104  inputErrorCount = 0;
105  }
106  }
107 
117  public static void readFile(String fileName) {
118  if (fileName == null) // Go back to reading standard input
120  else {
121  BufferedReader newin;
122  try {
123  newin = new BufferedReader( new FileReader(fileName) );
124  }
125  catch (Exception e) {
126  throw new IllegalArgumentException("Can't open file \"" + fileName + "\" for input.\n"
127  + "(Error :" + e + ")");
128  }
129  if (! readingStandardInput) { // close current input stream
130  try {
131  in.close();
132  }
133  catch (Exception e) {
134  }
135  }
136  emptyBuffer(); // Added November 2007
137  in = newin;
138  readingStandardInput = false;
139  inputErrorCount = 0;
140  inputFileName = fileName;
141  }
142  }
143 
159  public static boolean readUserSelectedFile() {
160  if (fileDialog == null)
161  fileDialog = new JFileChooser();
162  fileDialog.setDialogTitle("Select File for Input");
163  int option = fileDialog.showOpenDialog(null);
164  if (option != JFileChooser.APPROVE_OPTION)
165  return false;
166  File selectedFile = fileDialog.getSelectedFile();
167  BufferedReader newin;
168  try {
169  newin = new BufferedReader( new FileReader(selectedFile) );
170  }
171  catch (Exception e) {
172  throw new IllegalArgumentException("Can't open file \"" + selectedFile.getName() + "\" for input.\n"
173  + "(Error :" + e + ")");
174  }
175  if (!readingStandardInput) { // close current file
176  try {
177  in.close();
178  }
179  catch (Exception e) {
180  }
181  }
182  emptyBuffer(); // Added November 2007
183  in = newin;
184  inputFileName = selectedFile.getName();
185  readingStandardInput = false;
186  inputErrorCount = 0;
187  return true;
188  }
189 
195  public static void writeStandardOutput() {
197  return;
198  try {
199  out.close();
200  }
201  catch (Exception e) {
202  }
203  outputFileName = null;
204  outputErrorCount = 0;
206  writingStandardOutput = true;
207  }
208 
209 
216  public static void writeStream(OutputStream outputStream) {
217  if (outputStream == null)
219  else
220  writeStream(new PrintWriter(outputStream));
221  }
222 
229  public static void writeStream(PrintWriter outputStream) {
230  if (outputStream == null)
232  else {
233  out = outputStream;
234  outputFileName = null;
235  outputErrorCount = 0;
236  writingStandardOutput = false;
237  }
238  }
239 
240 
254  public static void writeFile(String fileName) {
255  if (fileName == null) // Go back to reading standard output
257  else {
258  PrintWriter newout;
259  try {
260  newout = new PrintWriter(new FileWriter(fileName));
261  }
262  catch (Exception e) {
263  throw new IllegalArgumentException("Can't open file \"" + fileName + "\" for output.\n"
264  + "(Error :" + e + ")");
265  }
266  if (!writingStandardOutput) {
267  try {
268  out.close();
269  }
270  catch (Exception e) {
271  }
272  }
273  out = newout;
274  writingStandardOutput = false;
275  outputFileName = fileName;
276  outputErrorCount = 0;
277  }
278  }
279 
291  public static boolean writeUserSelectedFile() {
292  if (fileDialog == null)
293  fileDialog = new JFileChooser();
294  fileDialog.setDialogTitle("Select File for Output");
295  File selectedFile;
296  while (true) {
297  int option = fileDialog.showSaveDialog(null);
298  if (option != JFileChooser.APPROVE_OPTION)
299  return false; // user canceled
300  selectedFile = fileDialog.getSelectedFile();
301  if (selectedFile.exists()) {
302  int response = JOptionPane.showConfirmDialog(null,
303  "The file \"" + selectedFile.getName() + "\" already exists. Do you want to replace it?",
304  "Replace existing file?",
305  JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
306  if (response == JOptionPane.YES_OPTION)
307  break;
308  }
309  else {
310  break;
311  }
312  }
313  PrintWriter newout;
314  try {
315  newout = new PrintWriter(new FileWriter(selectedFile));
316  }
317  catch (Exception e) {
318  throw new IllegalArgumentException("Can't open file \"" + selectedFile.getName() + "\" for output.\n"
319  + "(Error :" + e + ")");
320  }
321  if (!writingStandardOutput) {
322  try {
323  out.close();
324  }
325  catch (Exception e) {
326  }
327  }
328  out = newout;
329  writingStandardOutput = false;
330  outputFileName = selectedFile.getName();
331  outputErrorCount = 0;
332  return true;
333  }
334 
335 
340  public static String getInputFileName() {
341  return inputFileName;
342  }
343 
344 
349  public static String getOutputFileName() {
350  return outputFileName;
351  }
352 
353 
354  // *************************** Output Methods *********************************
355 
361  public static void put(Object x) {
362  out.print(x);
363  out.flush();
364  if (out.checkError())
365  outputError("Error while writing output.");
366  }
367 
379  public static void put(Object x, int minChars) {
380  if (minChars <= 0)
381  out.print(x);
382  else
383  out.printf("%" + minChars + "s", x);
384  out.flush();
385  if (out.checkError())
386  outputError("Error while writing output.");
387  }
388 
392  public static void putln(Object x) {
393  out.println(x);
394  out.flush();
395  if (out.checkError())
396  outputError("Error while writing output.");
397  }
398 
402  public static void putln(Object x, int minChars) {
403  put(x,minChars);
404  out.println();
405  out.flush();
406  if (out.checkError())
407  outputError("Error while writing output.");
408  }
409 
413  public static void putln() {
414  out.println();
415  out.flush();
416  if (out.checkError())
417  outputError("Error while writing output.");
418  }
419 
429  public static void putf(String format, Object... items) {
430  if (format == null)
431  throw new IllegalArgumentException("Null format string in TextIO.putf() method.");
432  try {
433  out.printf(format,items);
434  }
435  catch (IllegalFormatException e) {
436  throw new IllegalArgumentException("Illegal format string in TextIO.putf() method.");
437  }
438  out.flush();
439  if (out.checkError())
440  outputError("Error while writing output.");
441  }
442 
443  // *************************** Input Methods *********************************
444 
450  public static boolean eoln() {
451  return peek() == '\n';
452  }
453 
459  public static boolean eof() {
460  return peek() == EOF;
461  }
462 
471  public static char getAnyChar() {
472  return readChar();
473  }
474 
482  public static char peek() {
483  return lookChar();
484  }
485 
492  public static void skipBlanks() {
493  char ch=lookChar();
494  while (ch != EOF && ch != '\n' && Character.isWhitespace(ch)) {
495  readChar();
496  ch = lookChar();
497  }
498  }
499 
506  private static void skipWhitespace() {
507  char ch=lookChar();
508  while (ch != EOF && Character.isWhitespace(ch)) {
509  readChar();
510  if (ch == '\n' && readingStandardInput && writingStandardOutput) {
511  out.print("? ");
512  out.flush();
513  }
514  ch = lookChar();
515  }
516  }
517 
524  public static byte getlnByte() {
525  byte x=getByte();
526  emptyBuffer();
527  return x;
528  }
529 
536  public static short getlnShort() {
537  short x=getShort();
538  emptyBuffer();
539  return x;
540  }
541 
548  public static int getlnInt() {
549  int x=getInt();
550  emptyBuffer();
551  return x;
552  }
553 
560  public static long getlnLong() {
561  long x=getLong();
562  emptyBuffer();
563  return x;
564  }
565 
572  public static float getlnFloat() {
573  float x=getFloat();
574  emptyBuffer();
575  return x;
576  }
577 
584  public static double getlnDouble() {
585  double x=getDouble();
586  emptyBuffer();
587  return x;
588  }
589 
597  public static char getlnChar() {
598  char x=getChar();
599  emptyBuffer();
600  return x;
601  }
602 
612  public static boolean getlnBoolean() {
613  boolean x=getBoolean();
614  emptyBuffer();
615  return x;
616  }
617 
625  public static String getlnWord() {
626  String x=getWord();
627  emptyBuffer();
628  return x;
629  }
630 
634  public static String getlnString() {
635  return getln();
636  }
637 
645  public static String getln() {
646  StringBuffer s = new StringBuffer(100);
647  char ch = readChar();
648  while (ch != '\n') {
649  s.append(ch);
650  ch = readChar();
651  }
652  return s.toString();
653  }
654 
661  public static byte getByte() {
662  return (byte)readInteger(-128L,127L);
663  }
664 
671  public static short getShort() {
672  return (short)readInteger(-32768L,32767L);
673  }
674 
681  public static int getInt() {
682  return (int)readInteger(Integer.MIN_VALUE, Integer.MAX_VALUE);
683  }
684 
691  public static long getLong() {
692  return readInteger(Long.MIN_VALUE, Long.MAX_VALUE);
693  }
694 
701  public static char getChar() {
702  skipWhitespace();
703  return readChar();
704  }
705 
712  public static float getFloat() {
713  float x = 0.0F;
714  while (true) {
715  String str = readRealString();
716  if (str == null) {
717  errorMessage("Floating point number not found.",
718  "Real number in the range " + (-Float.MAX_VALUE) + " to " + Float.MAX_VALUE);
719  }
720  else {
721  try {
722  x = Float.parseFloat(str);
723  }
724  catch (NumberFormatException e) {
725  errorMessage("Illegal floating point input, " + str + ".",
726  "Real number in the range " + (-Float.MAX_VALUE) + " to " + Float.MAX_VALUE);
727  continue;
728  }
729  if (Float.isInfinite(x)) {
730  errorMessage("Floating point input outside of legal range, " + str + ".",
731  "Real number in the range " + (-Float.MAX_VALUE) + " to " + Float.MAX_VALUE);
732  continue;
733  }
734  break;
735  }
736  }
737  inputErrorCount = 0;
738  return x;
739  }
740 
747  public static double getDouble() {
748  double x = 0.0;
749  while (true) {
750  String str = readRealString();
751  if (str == null) {
752  errorMessage("Floating point number not found.",
753  "Real number in the range " + (-Double.MAX_VALUE) + " to " + Double.MAX_VALUE);
754  }
755  else {
756  try {
757  x = Double.parseDouble(str);
758  }
759  catch (NumberFormatException e) {
760  errorMessage("Illegal floating point input, " + str + ".",
761  "Real number in the range " + (-Double.MAX_VALUE) + " to " + Double.MAX_VALUE);
762  continue;
763  }
764  if (Double.isInfinite(x)) {
765  errorMessage("Floating point input outside of legal range, " + str + ".",
766  "Real number in the range " + (-Double.MAX_VALUE) + " to " + Double.MAX_VALUE);
767  continue;
768  }
769  break;
770  }
771  }
772  inputErrorCount = 0;
773  return x;
774  }
775 
783  public static String getWord() {
784  skipWhitespace();
785  StringBuffer str = new StringBuffer(50);
786  char ch = lookChar();
787  while (ch == EOF || !Character.isWhitespace(ch)) {
788  str.append(readChar());
789  ch = lookChar();
790  }
791  return str.toString();
792  }
793 
803  public static boolean getBoolean() {
804  boolean ans = false;
805  while (true) {
806  String s = getWord();
807  if ( s.equalsIgnoreCase("true") || s.equalsIgnoreCase("t") ||
808  s.equalsIgnoreCase("yes") || s.equalsIgnoreCase("y") ||
809  s.equals("1") ) {
810  ans = true;
811  break;
812  }
813  else if ( s.equalsIgnoreCase("false") || s.equalsIgnoreCase("f") ||
814  s.equalsIgnoreCase("no") || s.equalsIgnoreCase("n") ||
815  s.equals("0") ) {
816  ans = false;
817  break;
818  }
819  else
820  errorMessage("Illegal boolean input value.",
821  "one of: true, false, t, f, yes, no, y, n, 0, or 1");
822  }
823  inputErrorCount = 0;
824  return ans;
825  }
826 
827  // ***************** Everything beyond this point is private implementation detail *******************
828 
829  private static String inputFileName; // Name of file that is the current input source, or null if the source is not a file.
830  private static String outputFileName; // Name of file that is the current output destination, or null if the destination is not a file.
831 
832  private static JFileChooser fileDialog; // Dialog used by readUserSelectedFile() and writeUserSelectedFile()
833 
834  private final static BufferedReader standardInput = new BufferedReader(new InputStreamReader(System.in)); // wraps standard input stream
835  private final static PrintWriter standardOutput = new PrintWriter(System.out); // wraps standard output stream
836 
837  private static BufferedReader in = standardInput; // Stream that data is read from; the current input source.
838  private static PrintWriter out = standardOutput; // Stream that data is written to; the current output destination.
839 
840  private static boolean readingStandardInput = true;
841  private static boolean writingStandardOutput = true;
842 
843  private static int inputErrorCount; // Number of consecutive errors on standard input; reset to 0 when a successful read occurs.
844  private static int outputErrorCount; // Number of errors on standard output since it was selected as the output destination.
845 
846  private static Matcher integerMatcher; // Used for reading integer numbers; created from the integer Regex Pattern.
847  private static Matcher floatMatcher; // Used for reading floating point numbers; created from the floatRegex Pattern.
848  private final static Pattern integerRegex = Pattern.compile("(\\+|-)?[0-9]+");
849  private final static Pattern floatRegex = Pattern.compile("(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))((e|E)(\\+|-)?[0-9]+)?");
850 
851  private static String buffer = null; // One line read from input.
852  private static int pos = 0; // Position of next char in input line that has not yet been processed.
853 
854  private static String readRealString() { // read chars from input following syntax of real numbers
855  skipWhitespace();
856  if (lookChar() == EOF)
857  return null;
858  if (floatMatcher == null)
859  floatMatcher = floatRegex.matcher(buffer);
860  floatMatcher.region(pos,buffer.length());
861  if (floatMatcher.lookingAt()) {
862  String str = floatMatcher.group();
863  pos = floatMatcher.end();
864  return str;
865  }
866  else
867  return null;
868  }
869 
870  private static String readIntegerString() { // read chars from input following syntax of integers
871  skipWhitespace();
872  if (lookChar() == EOF)
873  return null;
874  if (integerMatcher == null)
876  integerMatcher.region(pos,buffer.length());
877  if (integerMatcher.lookingAt()) {
878  String str = integerMatcher.group();
879  pos = integerMatcher.end();
880  return str;
881  }
882  else
883  return null;
884  }
885 
886  private static long readInteger(long min, long max) { // read long integer, limited to specified range
887  long x=0;
888  while (true) {
889  String s = readIntegerString();
890  if (s == null){
891  errorMessage("Integer value not found in input.",
892  "Integer in the range " + min + " to " + max);
893  }
894  else {
895  String str = s.toString();
896  try {
897  x = Long.parseLong(str);
898  }
899  catch (NumberFormatException e) {
900  errorMessage("Illegal integer input, " + str + ".",
901  "Integer in the range " + min + " to " + max);
902  continue;
903  }
904  if (x < min || x > max) {
905  errorMessage("Integer input outside of legal range, " + str + ".",
906  "Integer in the range " + min + " to " + max);
907  continue;
908  }
909  break;
910  }
911  }
912  inputErrorCount = 0;
913  return x;
914  }
915 
916 
917  private static void errorMessage(String message, String expecting) { // Report error on input.
919  // inform user of error and force user to re-enter.
920  out.println();
921  out.print(" *** Error in input: " + message + "\n");
922  out.print(" *** Expecting: " + expecting + "\n");
923  out.print(" *** Discarding Input: ");
924  if (lookChar() == '\n')
925  out.print("(end-of-line)\n\n");
926  else {
927  while (lookChar() != '\n') // Discard and echo remaining chars on the current line of input.
928  out.print(readChar());
929  out.print("\n\n");
930  }
931  out.print("Please re-enter: ");
932  out.flush();
933  readChar(); // discard the end-of-line character
934  inputErrorCount++;
935  if (inputErrorCount >= 10)
936  throw new IllegalArgumentException("Too many input consecutive input errors on standard input.");
937  }
938  else if (inputFileName != null)
939  throw new IllegalArgumentException("Error while reading from file \"" + inputFileName + "\":\n"
940  + message + "\nExpecting " + expecting);
941  else
942  throw new IllegalArgumentException("Error while reading from inptu stream:\n"
943  + message + "\nExpecting " + expecting);
944  }
945 
946  private static char lookChar() { // return next character from input
947  if (buffer == null || pos > buffer.length())
948  fillBuffer();
949  if (buffer == null)
950  return EOF;
951  else if (pos == buffer.length())
952  return '\n';
953  else
954  return buffer.charAt(pos);
955  }
956 
957  private static char readChar() { // return and discard next character from input
958  char ch = lookChar();
959  if (buffer == null) {
961  throw new IllegalArgumentException("Attempt to read past end-of-file in standard input???");
962  else
963  throw new IllegalArgumentException("Attempt to read past end-of-file in file \"" + inputFileName + "\".");
964  }
965  pos++;
966  return ch;
967  }
968 
969  private static void fillBuffer() { // Wait for user to type a line and press return,
970  try {
971  buffer = in.readLine();
972  }
973  catch (Exception e) {
975  throw new IllegalArgumentException("Error while reading standard input???");
976  else if (inputFileName != null)
977  throw new IllegalArgumentException("Error while attempting to read from file \"" + inputFileName + "\".");
978  else
979  throw new IllegalArgumentException("Errow while attempting to read form an input stream.");
980  }
981  pos = 0;
982  floatMatcher = null;
983  integerMatcher = null;
984  }
985 
986  private static void emptyBuffer() { // discard the rest of the current line of input
987  buffer = null;
988  }
989 
990  private static void outputError(String message) { // Report an error on output.
991  if (writingStandardOutput) {
992  System.err.println("Error occurred in TextIO while writing to standard output!!");
994  if (outputErrorCount >= 10) {
995  outputErrorCount = 0;
996  throw new IllegalArgumentException("Too many errors while writing to standard output.");
997  }
998  }
999  else if (outputFileName != null){
1000  throw new IllegalArgumentException("Error occurred while writing to file \""
1001  + outputFileName+ "\":\n " + message);
1002  }
1003  else {
1004  throw new IllegalArgumentException("Error occurred while writing to output stream:\n " + message);
1005  }
1006  }
1007 
1008 } // end of class TextIO
TextIO.writeStandardOutput
static void writeStandardOutput()
After this method is called, output will be written to standard output (as it is in the default state...
Definition: TextIO.java:195
TextIO.getChar
static char getChar()
Skips whitespace characters and then reads a single non-whitespace character from input.
Definition: TextIO.java:701
TextIO.integerMatcher
static Matcher integerMatcher
Definition: TextIO.java:846
TextIO.getLong
static long getLong()
Skips whitespace characters and then reads a value of type long from input.
Definition: TextIO.java:691
TextIO.out
static PrintWriter out
Definition: TextIO.java:838
TextIO.getlnShort
static short getlnShort()
Skips whitespace characters and then reads a value of type short from input, discarding the rest of t...
Definition: TextIO.java:536
TextIO.inputFileName
static String inputFileName
Definition: TextIO.java:829
TextIO.floatMatcher
static Matcher floatMatcher
Definition: TextIO.java:847
TextIO.writeStream
static void writeStream(PrintWriter outputStream)
After this method is called, output will be sent to outputStream, provided it is non-null.
Definition: TextIO.java:229
TextIO.writeUserSelectedFile
static boolean writeUserSelectedFile()
Puts a GUI file-selection dialog box on the screen in which the user can select an output file.
Definition: TextIO.java:291
TextIO.EOLN
static final char EOLN
The value returned by the peek() method when the input is at end-of-line.
Definition: TextIO.java:51
TextIO.getlnString
static String getlnString()
This is identical to getln().
Definition: TextIO.java:634
TextIO.getlnBoolean
static boolean getlnBoolean()
Skips whitespace characters and then reads a value of type boolean from input, discarding the rest of...
Definition: TextIO.java:612
TextIO.readInteger
static long readInteger(long min, long max)
Definition: TextIO.java:886
TextIO.getOutputFileName
static String getOutputFileName()
If TextIO is currently writing to a file, then the return value is the name of the file.
Definition: TextIO.java:349
TextIO.readFile
static void readFile(String fileName)
Opens a file with a specified name for input.
Definition: TextIO.java:117
TextIO.eof
static boolean eof()
Test whether the next character in the current input source is an end-of-file.
Definition: TextIO.java:459
TextIO.putf
static void putf(String format, Object... items)
Writes formatted output values to the current output destination.
Definition: TextIO.java:429
TextIO.writeFile
static void writeFile(String fileName)
Opens a file with a specified name for output.
Definition: TextIO.java:254
TextIO.pos
static int pos
Definition: TextIO.java:852
TextIO.outputFileName
static String outputFileName
Definition: TextIO.java:830
TextIO.put
static void put(Object x)
Write a single value to the current output destination, using the default format and no extra spaces.
Definition: TextIO.java:361
TextIO.putln
static void putln()
Write an end-of-line character to the current output destination.
Definition: TextIO.java:413
TextIO.put
static void put(Object x, int minChars)
Write a single value to the current output destination, using the default format and outputting at le...
Definition: TextIO.java:379
TextIO.writeStream
static void writeStream(OutputStream outputStream)
After this method is called, output will be sent to outputStream, provided it is non-null.
Definition: TextIO.java:216
TextIO.readRealString
static String readRealString()
Definition: TextIO.java:854
TextIO.readChar
static char readChar()
Definition: TextIO.java:957
TextIO.readUserSelectedFile
static boolean readUserSelectedFile()
Puts a GUI file-selection dialog box on the screen in which the user can select an input file.
Definition: TextIO.java:159
TextIO.getInputFileName
static String getInputFileName()
If TextIO is currently reading from a file, then the return value is the name of the file.
Definition: TextIO.java:340
TextIO.in
static BufferedReader in
Definition: TextIO.java:837
TextIO.getFloat
static float getFloat()
Skips whitespace characters and then reads a value of type float from input.
Definition: TextIO.java:712
TextIO.getDouble
static double getDouble()
Skips whitespace characters and then reads a value of type double from input.
Definition: TextIO.java:747
TextIO.outputError
static void outputError(String message)
Definition: TextIO.java:990
TextIO.fileDialog
static JFileChooser fileDialog
Definition: TextIO.java:832
TextIO.writingStandardOutput
static boolean writingStandardOutput
Definition: TextIO.java:841
TextIO.skipBlanks
static void skipBlanks()
Skips over any whitespace characters, except for end-of-lines.
Definition: TextIO.java:492
TextIO.getlnByte
static byte getlnByte()
Skips whitespace characters and then reads a value of type byte from input, discarding the rest of th...
Definition: TextIO.java:524
TextIO
TextIO provides a set of static methods for reading and writing text.
Definition: TextIO.java:34
TextIO.readStandardInput
static void readStandardInput()
After this method is called, input will be read from standard input (as it is in the default state).
Definition: TextIO.java:59
TextIO.errorMessage
static void errorMessage(String message, String expecting)
Definition: TextIO.java:917
TextIO.skipWhitespace
static void skipWhitespace()
Skips over any whitespace characters, including for end-of-lines.
Definition: TextIO.java:506
TextIO.readingStandardInput
static boolean readingStandardInput
Definition: TextIO.java:840
TextIO.emptyBuffer
static void emptyBuffer()
Definition: TextIO.java:986
TextIO.putln
static void putln(Object x)
This is equivalent to put(x), followed by an end-of-line.
Definition: TextIO.java:392
TextIO.getlnLong
static long getlnLong()
Skips whitespace characters and then reads a value of type long from input, discarding the rest of th...
Definition: TextIO.java:560
TextIO.getBoolean
static boolean getBoolean()
Skips whitespace characters and then reads a value of type boolean from input.
Definition: TextIO.java:803
TextIO.getByte
static byte getByte()
Skips whitespace characters and then reads a value of type byte from input.
Definition: TextIO.java:661
TextIO.inputErrorCount
static int inputErrorCount
Definition: TextIO.java:843
TextIO.getlnFloat
static float getlnFloat()
Skips whitespace characters and then reads a value of type float from input, discarding the rest of t...
Definition: TextIO.java:572
TextIO.getShort
static short getShort()
Skips whitespace characters and then reads a value of type short from input.
Definition: TextIO.java:671
TextIO.getWord
static String getWord()
Skips whitespace characters and then reads one "word" from input.
Definition: TextIO.java:783
TextIO.outputErrorCount
static int outputErrorCount
Definition: TextIO.java:844
TextIO.getlnDouble
static double getlnDouble()
Skips whitespace characters and then reads a value of type double from input, discarding the rest of ...
Definition: TextIO.java:584
TextIO.getlnChar
static char getlnChar()
Skips whitespace characters and then reads a value of type char from input, discarding the rest of th...
Definition: TextIO.java:597
TextIO.peek
static char peek()
Returns the next character in the current input source, without actually removing that character from...
Definition: TextIO.java:482
TextIO.lookChar
static char lookChar()
Definition: TextIO.java:946
TextIO.readStream
static void readStream(Reader inputStream)
After this method is called, input will be read from inputStream, provided it is non-null.
Definition: TextIO.java:93
TextIO.standardOutput
static final PrintWriter standardOutput
Definition: TextIO.java:835
TextIO.putln
static void putln(Object x, int minChars)
This is equivalent to put(x,minChars), followed by an end-of-line.
Definition: TextIO.java:402
TextIO.buffer
static String buffer
Definition: TextIO.java:851
TextIO.getlnWord
static String getlnWord()
Skips whitespace characters and then reads one "word" from input, discarding the rest of the current ...
Definition: TextIO.java:625
TextIO.EOF
static final char EOF
The value returned by the peek() method when the input is at end-of-file.
Definition: TextIO.java:45
TextIO.fillBuffer
static void fillBuffer()
Definition: TextIO.java:969
TextIO.getlnInt
static int getlnInt()
Skips whitespace characters and then reads a value of type int from input, discarding the rest of the...
Definition: TextIO.java:548
TextIO.floatRegex
static final Pattern floatRegex
Definition: TextIO.java:849
TextIO.standardInput
static final BufferedReader standardInput
Definition: TextIO.java:834
TextIO.readIntegerString
static String readIntegerString()
Definition: TextIO.java:870
TextIO.getAnyChar
static char getAnyChar()
Reads the next character from the current input source.
Definition: TextIO.java:471
TextIO.integerRegex
static final Pattern integerRegex
Definition: TextIO.java:848
TextIO.readStream
static void readStream(InputStream inputStream)
After this method is called, input will be read from inputStream, provided it is non-null.
Definition: TextIO.java:80
TextIO.getInt
static int getInt()
Skips whitespace characters and then reads a value of type int from input.
Definition: TextIO.java:681
TextIO.eoln
static boolean eoln()
Test whether the next character in the current input source is an end-of-line.
Definition: TextIO.java:450
TextIO.getln
static String getln()
Reads all the characters from the current input source, up to the next end-of-line.
Definition: TextIO.java:645