/** Reads the next key/value pair from the input for processing. */ public boolean next(Text key, SequencedFragment value) throws IOException { if (pos >= end) return false; // past end of slice int bytesRead = 0; boolean goodRecord; do { bytesRead = lowLevelQseqRead(key, value); // if bytesRead <= 0 EOF has been reached goodRecord = (bytesRead > 0) && (!filterFailedQC || value.getFilterPassed() == null || value.getFilterPassed()); } while (bytesRead > 0 && !goodRecord); if (goodRecord) // post process the record only if it's going to be used { try { postProcessSequencedFragment(value); } catch (FormatException e) { throw new FormatException( e.getMessage() + " Position: " + makePositionMessage(this.pos - bytesRead) + "; line: " + buffer); // last line read is still in the buffer } } return goodRecord; }
boolean nextCommand() { System.out.print( "\n[" + calc.getBase().getName() + "," + calc.getFormat().getName() + "," + calc.firstOperand() + ", " + calc.secondOperand() + "] >"); // Print huidige waarden van calc. try { // reads the command from the keyboard String command = lineReader.readLine(); // Lees input. while (command == null) { // if (prevReader != null) { lineReader = prevReader; prevReader = null; command = lineReader.readLine(); } else { return false; } } /* * Acties die uitgevoerd worden bij herkenning van een operator. */ if (command.equals("+")) calc.add(); else if (command.equals("-")) calc.subtract(); else if (command.equals("*")) calc.multiply(); else if (command.equals("/")) calc.divide(); else if (command.equals("dec")) calc.setBase(new DecimalBase()); else if (command.equals("bin")) calc.setBase(new BinaryBase()); else if (command.equals("oct")) calc.setBase(new OctalBase()); else if (command.equals("hex")) calc.setBase(new HexBase()); else if (command.equals("rat")) calc.setFormat(new RationalFormat()); else if (command.equals("fixed")) calc.setFormat(new FixedPointFormat()); else if (command.equals("float")) calc.setFormat(new FloatingPointFormat()); else if (command.equals("del")) calc.delete(); else if (command.indexOf("op") >= 0) { command = command.substring(2).trim(); try { calc.addOperand(command); } catch (FormatException e) { System.out.println("Wrong operand: " + e.getMessage()); } } else if (command.indexOf("read") >= 0) { try { BufferedReader file = new BufferedReader(new FileReader(command.substring(4).trim())); prevReader = lineReader; lineReader = file; System.out.println("Reading from file " + command.substring(4).trim()); } catch (Exception e) { System.out.println("Cannot open file " + command.substring(4).trim()); } } else if (command.equals("help")) { printHelp(); } else if (command.equals("exit")) return false; else { System.out.println("Error! Not a valid command"); } } catch (IOException ioe) { ioe.printStackTrace(); } return true; }