@Test public void testStep0() { String testFileName = "testLogFile.bin"; ParserStatus expectedStatus = ParserStatus.EOF; int expectedStep = 1; BufferedInputStream testInputStream = new BufferedInputStream(new ByteArrayInputStream(new byte[0])); try { assertEquals(expectedStatus, testDriverAlertFileParser.parseFile(testInputStream, "testLogFile.bin")); assertEquals(testFileName, testDriverAlertFileParser.getFilename()); assertEquals(expectedStep, testDriverAlertFileParser.getStep()); } catch (FileParserException e) { fail("Unexpected exception: " + e); } }
@Override public ParserStatus parseFile(BufferedInputStream bis, String fileName) throws FileParserException { ParserStatus status; try { status = super.parseFile(bis, fileName); if (status != ParserStatus.COMPLETE) return status; if (getStep() == 1) { status = nextStep(bis, fileName, locationParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 2) { status = nextStep(bis, fileName, timeParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 3) { status = nextStep(bis, fileName, payloadParser); if (status != ParserStatus.COMPLETE) return status; setAlert(payloadParser.getPayload()); } resetStep(); status = ParserStatus.COMPLETE; } catch (Exception e) { throw new FileParserException(String.format("Error parsing %s on step %d", fileName, getStep()), e); } return status; }
DriverAlertFileParser extends LogFileParser { @Override public ParserStatus parseFile(BufferedInputStream bis, String fileName) throws FileParserException { ParserStatus status; try { status = super.parseFile(bis, fileName); if (status != ParserStatus.COMPLETE) return status; if (getStep() == 1) { status = nextStep(bis, fileName, locationParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 2) { status = nextStep(bis, fileName, timeParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 3) { status = nextStep(bis, fileName, payloadParser); if (status != ParserStatus.COMPLETE) return status; setAlert(payloadParser.getPayload()); } resetStep(); status = ParserStatus.COMPLETE; } catch (Exception e) { throw new FileParserException(String.format("Error parsing %s on step %d", fileName, getStep()), e); } return status; } }
DriverAlertFileParser extends LogFileParser { @Override public ParserStatus parseFile(BufferedInputStream bis, String fileName) throws FileParserException { ParserStatus status; try { status = super.parseFile(bis, fileName); if (status != ParserStatus.COMPLETE) return status; if (getStep() == 1) { status = nextStep(bis, fileName, locationParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 2) { status = nextStep(bis, fileName, timeParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 3) { status = nextStep(bis, fileName, payloadParser); if (status != ParserStatus.COMPLETE) return status; setAlert(payloadParser.getPayload()); } resetStep(); status = ParserStatus.COMPLETE; } catch (Exception e) { throw new FileParserException(String.format("Error parsing %s on step %d", fileName, getStep()), e); } return status; } DriverAlertFileParser(); }
DriverAlertFileParser extends LogFileParser { @Override public ParserStatus parseFile(BufferedInputStream bis, String fileName) throws FileParserException { ParserStatus status; try { status = super.parseFile(bis, fileName); if (status != ParserStatus.COMPLETE) return status; if (getStep() == 1) { status = nextStep(bis, fileName, locationParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 2) { status = nextStep(bis, fileName, timeParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 3) { status = nextStep(bis, fileName, payloadParser); if (status != ParserStatus.COMPLETE) return status; setAlert(payloadParser.getPayload()); } resetStep(); status = ParserStatus.COMPLETE; } catch (Exception e) { throw new FileParserException(String.format("Error parsing %s on step %d", fileName, getStep()), e); } return status; } DriverAlertFileParser(); @Override ParserStatus parseFile(BufferedInputStream bis, String fileName); String getAlert(); void setAlert(byte[] alert); @Override void writeTo(OutputStream os); }
DriverAlertFileParser extends LogFileParser { @Override public ParserStatus parseFile(BufferedInputStream bis, String fileName) throws FileParserException { ParserStatus status; try { status = super.parseFile(bis, fileName); if (status != ParserStatus.COMPLETE) return status; if (getStep() == 1) { status = nextStep(bis, fileName, locationParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 2) { status = nextStep(bis, fileName, timeParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 3) { status = nextStep(bis, fileName, payloadParser); if (status != ParserStatus.COMPLETE) return status; setAlert(payloadParser.getPayload()); } resetStep(); status = ParserStatus.COMPLETE; } catch (Exception e) { throw new FileParserException(String.format("Error parsing %s on step %d", fileName, getStep()), e); } return status; } DriverAlertFileParser(); @Override ParserStatus parseFile(BufferedInputStream bis, String fileName); String getAlert(); void setAlert(byte[] alert); @Override void writeTo(OutputStream os);  }