/** * If constructor taking a file name as input was used, this method simply * calls the method of the same name in <code>LineByLine</code>; otherwise, * it returns the next element of the array. * * @return The next line of input. **/ protected String readLine() { if (input != null) { if (index < input.length) return input[index++]; return null; } return super.readLine(); }
String line = (String) parser.next(); assert line != null : "File sent to Post constructor contains no lines."; assert line.startsWith("From:") || line.startsWith("Subject:") if (line.startsWith("From:")) fromHeader = line.substring(6); else subjectHeader = line.substring(9); line = (String) parser.next(); assert line != null : "File sent to Post constructor contains no lines."; assert line.startsWith("From:") || line.startsWith("Subject:") assert fromHeader != null && subjectHeader != null : "File set to Post constructor is missing expected headers."; line = (String) parser.next(); for (line = (String) parser.next(); line != null; line = (String) parser.next()) lines.add(line.split(" +"));
/** Sets this parser back to the beginning of the raw data. */ public void reset() { close(); try { in = new BufferedReader(new FileReader(fileName)); } catch (Exception e) { System.err.println("Can't open '" + fileName + "' for input:"); e.printStackTrace(); System.exit(1); } }
String line = (String) parser.next(); String[] a = line.split(" "); maximize = a[0].startsWith("max"); line = (String) parser.next(); if (line.indexOf("subject") != -1) line = (String) parser.next(); for (; line != null; line = (String) parser.next()) { a = line.substring(2).split(" "); int[] variables = new int[a.length / 2 - 1];
/** * Reads a line from the current buffer and returns it. When there are no more lines in the * input file, the stream is closed, and <code>null</code> will be returned by this method * thereafter. Returned strings do not contain line termination characters. * * @return The next line of text from the input file, or <code>null</code> if no more lines * remain. **/ protected String readLine() { if (in == null) return null; String line = null; try { line = in.readLine(); } catch (Exception e) { System.err.println("Can't read from '" + fileName + "':"); e.printStackTrace(); System.exit(1); } if (line == null) { close(); in = null; } return line; }
public City(String file){ LineByLine parser = new LineByLine(file) { public Object next() { return readLine(); } }; String line = null; while((line = (String) parser.next()) != null){ String[] definition = line.split("\\s+"); Integer index = new Integer(definition[0]); Neighborhood n = getNeighborhood(index); for(int i = 1; i < definition.length; i++){ n.addNeighbor(getNeighborhood(new Integer(definition[i]))); } } }
/** * If constructor taking a file name as input was used, this method simply * calls the method of the same name in <code>LineByLine</code>; otherwise, * it returns the next element of the array. * * @return The next line of input. **/ protected String readLine() { if (input != null) { if (index < input.length) return input[index++]; return null; } return super.readLine(); }