@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, testRxMsgFileParser.parseFile(testInputStream, "testLogFile.bin")); assertEquals(testFileName, testRxMsgFileParser.getFilename()); assertEquals(expectedStep, testRxMsgFileParser.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 = parseStep(bis, RX_SOURCE_LENGTH); if (status != ParserStatus.COMPLETE) return status; try { setRxSource(RxSource.values()[readBuffer[0]]); } catch (Exception e) { setRxSource(RxSource.UNKNOWN); } } if (getStep() == 2) { status = nextStep(bis, fileName, locationParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 3) { status = nextStep(bis, fileName, timeParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 4) { status = nextStep(bis, fileName, secResCodeParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 5) { status = nextStep(bis, fileName, payloadParser); if (status != ParserStatus.COMPLETE) return status; } resetStep(); status = ParserStatus.COMPLETE; } catch (Exception e) { throw new FileParserException(String.format("Error parsing %s on step %d", fileName, getStep()), e); } return status; }
RxMsgFileParser 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 = parseStep(bis, RX_SOURCE_LENGTH); if (status != ParserStatus.COMPLETE) return status; try { setRxSource(RxSource.values()[readBuffer[0]]); } catch (Exception e) { setRxSource(RxSource.UNKNOWN); } } if (getStep() == 2) { status = nextStep(bis, fileName, locationParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 3) { status = nextStep(bis, fileName, timeParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 4) { status = nextStep(bis, fileName, secResCodeParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 5) { status = nextStep(bis, fileName, payloadParser); if (status != ParserStatus.COMPLETE) return status; } resetStep(); status = ParserStatus.COMPLETE; } catch (Exception e) { throw new FileParserException(String.format("Error parsing %s on step %d", fileName, getStep()), e); } return status; } }
RxMsgFileParser 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 = parseStep(bis, RX_SOURCE_LENGTH); if (status != ParserStatus.COMPLETE) return status; try { setRxSource(RxSource.values()[readBuffer[0]]); } catch (Exception e) { setRxSource(RxSource.UNKNOWN); } } if (getStep() == 2) { status = nextStep(bis, fileName, locationParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 3) { status = nextStep(bis, fileName, timeParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 4) { status = nextStep(bis, fileName, secResCodeParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 5) { status = nextStep(bis, fileName, payloadParser); if (status != ParserStatus.COMPLETE) return status; } resetStep(); status = ParserStatus.COMPLETE; } catch (Exception e) { throw new FileParserException(String.format("Error parsing %s on step %d", fileName, getStep()), e); } return status; } RxMsgFileParser(); }
RxMsgFileParser 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 = parseStep(bis, RX_SOURCE_LENGTH); if (status != ParserStatus.COMPLETE) return status; try { setRxSource(RxSource.values()[readBuffer[0]]); } catch (Exception e) { setRxSource(RxSource.UNKNOWN); } } if (getStep() == 2) { status = nextStep(bis, fileName, locationParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 3) { status = nextStep(bis, fileName, timeParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 4) { status = nextStep(bis, fileName, secResCodeParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 5) { status = nextStep(bis, fileName, payloadParser); if (status != ParserStatus.COMPLETE) return status; } resetStep(); status = ParserStatus.COMPLETE; } catch (Exception e) { throw new FileParserException(String.format("Error parsing %s on step %d", fileName, getStep()), e); } return status; } RxMsgFileParser(); @Override ParserStatus parseFile(BufferedInputStream bis, String fileName); RxSource getRxSource(); void setRxSource(RxSource rxSource); void setRxSource(int rxSourceOrdinal); @Override void writeTo(OutputStream os); }
RxMsgFileParser 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 = parseStep(bis, RX_SOURCE_LENGTH); if (status != ParserStatus.COMPLETE) return status; try { setRxSource(RxSource.values()[readBuffer[0]]); } catch (Exception e) { setRxSource(RxSource.UNKNOWN); } } if (getStep() == 2) { status = nextStep(bis, fileName, locationParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 3) { status = nextStep(bis, fileName, timeParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 4) { status = nextStep(bis, fileName, secResCodeParser); if (status != ParserStatus.COMPLETE) return status; } if (getStep() == 5) { status = nextStep(bis, fileName, payloadParser); if (status != ParserStatus.COMPLETE) return status; } resetStep(); status = ParserStatus.COMPLETE; } catch (Exception e) { throw new FileParserException(String.format("Error parsing %s on step %d", fileName, getStep()), e); } return status; } RxMsgFileParser(); @Override ParserStatus parseFile(BufferedInputStream bis, String fileName); RxSource getRxSource(); void setRxSource(RxSource rxSource); void setRxSource(int rxSourceOrdinal); @Override void writeTo(OutputStream os);  }