/** Close the visitor */ @Override public void close(Throwable error) throws IOException { out.print(getStatisticsString()); if (error != null) { out.print("EXITING ON ERROR: " + error.toString() + "\n"); } out.close(); }
@Override public void visitOp(FSEditLogOp op) throws IOException { incrementOpCodeCount(op.opCode); }
/** * Checks that the edits file has all opCodes * * @param filename edits file * @return true is edits (filename) has all opCodes */ private boolean hasAllOpCodes(String inFilename) throws IOException { String outFilename = inFilename + ".stats"; FileOutputStream fout = new FileOutputStream(outFilename); StatisticsEditsVisitor visitor = new StatisticsEditsVisitor(fout); OfflineEditsViewer oev = new OfflineEditsViewer(); if (oev.go(inFilename, outFilename, "stats", new Flags(), visitor) != 0) return false; LOG.info("Statistics for " + inFilename + "\n" + visitor.getStatisticsString()); boolean hasAllOpCodes = true; for (FSEditLogOpCodes opCode : FSEditLogOpCodes.values()) { // don't need to test obsolete opCodes if (skippedOps.contains(opCode)) continue; Long count = visitor.getStatistics().get(opCode); if ((count == null) || (count == 0)) { hasAllOpCodes = false; LOG.info("Opcode " + opCode + " not tested in " + inFilename); } } return hasAllOpCodes; }
vis = new XmlEditsVisitor(out); } else if(StringUtils.equalsIgnoreCase("stats", processor)) { vis = new StatisticsEditsVisitor(out); } else { throw new IOException("Unknown proccesor " + processor +
@Override void finish() throws IOException { write(getStatisticsString()); close(); }
@Override void finishAbnormally() throws IOException { close(); }
/** * Factory function that creates an EditsVisitor object * * @param filename output filename * @param tokenizer input tokenizer * @return EditsVisitor for appropriate output format (binary, XML etc.) */ static public EditsVisitor getEditsVisitor(String filename, String processor, Tokenizer tokenizer, boolean printToScreen) throws IOException { if(processor.toLowerCase().equals("xml")) { return new XmlEditsVisitor(filename, tokenizer, printToScreen); } else if(processor.toLowerCase().equals("stats")) { return new StatisticsEditsVisitor(filename, tokenizer, printToScreen); } else if(processor.toLowerCase().equals("binary")) { return new BinaryEditsVisitor(filename, tokenizer, printToScreen); } else { throw new IOException("Unknown proccesor " + processor + " (valid processors: xml, binary, stats)"); } } }
vis = new XmlEditsVisitor(out); } else if(StringUtils.equalsIgnoreCase("stats", processor)) { vis = new StatisticsEditsVisitor(out); } else { throw new IOException("Unknown proccesor " + processor +
/** Close the visitor */ @Override public void close(Throwable error) throws IOException { out.print(getStatisticsString()); if (error != null) { out.print("EXITING ON ERROR: " + error.toString() + "\n"); } out.close(); }
@Override public void visitOp(FSEditLogOp op) throws IOException { incrementOpCodeCount(op.opCode); }
vis = new XmlEditsVisitor(out); } else if(StringUtils.equalsIgnoreCase("stats", processor)) { vis = new StatisticsEditsVisitor(out); } else { throw new IOException("Unknown proccesor " + processor +
/** Close the visitor */ @Override public void close(Throwable error) throws IOException { out.print(getStatisticsString()); if (error != null) { out.print("EXITING ON ERROR: " + error.toString() + "\n"); } out.close(); }
@Override public void visitOp(FSEditLogOp op) throws IOException { incrementOpCodeCount(op.opCode); }
/** * Visit a Token, calculate statistics * * @param value a Token to visit */ @Override Tokenizer.Token visit(Tokenizer.Token value) throws IOException { // count the opCodes if(value.getEditsElement() == EditsElement.OPCODE) { if(value instanceof Tokenizer.ByteToken) { incrementOpCodeCount(((Tokenizer.ByteToken)value).value); } else { throw new IOException("Token for EditsElement.OPCODE should be " + "of type Tokenizer.ByteToken, not " + value.getClass()); } } return value; }