@Test public void testPartialMSec() { ParserStatus expectedStatus = ParserStatus.PARTIAL; int expectedStep = 1; BufferedInputStream testInputStream = new BufferedInputStream( new ByteArrayInputStream(new byte[] { (byte)0xa9, (byte)0x2c, (byte)0xe2, (byte)0x5a, (byte)0x8f })); try { assertEquals(expectedStatus, timeParser.parseFile(testInputStream, "testLogFile.bin")); assertEquals(expectedStep, timeParser.getStep()); } catch (FileParserException e) { fail("Unexpected exception: " + e); } }
@Override public ParserStatus parseFile(BufferedInputStream bis, String fileName) throws FileParserException { ParserStatus status = ParserStatus.INIT; try { if (getStep() == 0) { status = parseStep(bis, UTC_TIME_IN_SEC_LENGTH); if (status != ParserStatus.COMPLETE) return status; setUtcTimeInSec(CodecUtils.bytesToInt(readBuffer, 0, UTC_TIME_IN_SEC_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 1) { status = parseStep(bis, MSEC_LENGTH); if (status != ParserStatus.COMPLETE) return status; setmSec(CodecUtils.bytesToShort(readBuffer, 0, MSEC_LENGTH, ByteOrder.LITTLE_ENDIAN)); } resetStep(); status = ParserStatus.COMPLETE; } catch (Exception e) { throw new FileParserException(String.format("Error parsing %s on step %d", fileName, getStep()), e); } return status; }
TimeParser extends LogFileParser { @Override public ParserStatus parseFile(BufferedInputStream bis, String fileName) throws FileParserException { ParserStatus status = ParserStatus.INIT; try { if (getStep() == 0) { status = parseStep(bis, UTC_TIME_IN_SEC_LENGTH); if (status != ParserStatus.COMPLETE) return status; setUtcTimeInSec(CodecUtils.bytesToInt(readBuffer, 0, UTC_TIME_IN_SEC_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 1) { status = parseStep(bis, MSEC_LENGTH); if (status != ParserStatus.COMPLETE) return status; setmSec(CodecUtils.bytesToShort(readBuffer, 0, MSEC_LENGTH, ByteOrder.LITTLE_ENDIAN)); } resetStep(); status = ParserStatus.COMPLETE; } catch (Exception e) { throw new FileParserException(String.format("Error parsing %s on step %d", fileName, getStep()), e); } return status; } }
TimeParser extends LogFileParser { @Override public ParserStatus parseFile(BufferedInputStream bis, String fileName) throws FileParserException { ParserStatus status = ParserStatus.INIT; try { if (getStep() == 0) { status = parseStep(bis, UTC_TIME_IN_SEC_LENGTH); if (status != ParserStatus.COMPLETE) return status; setUtcTimeInSec(CodecUtils.bytesToInt(readBuffer, 0, UTC_TIME_IN_SEC_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 1) { status = parseStep(bis, MSEC_LENGTH); if (status != ParserStatus.COMPLETE) return status; setmSec(CodecUtils.bytesToShort(readBuffer, 0, MSEC_LENGTH, ByteOrder.LITTLE_ENDIAN)); } resetStep(); status = ParserStatus.COMPLETE; } catch (Exception e) { throw new FileParserException(String.format("Error parsing %s on step %d", fileName, getStep()), e); } return status; } TimeParser(); }
TimeParser extends LogFileParser { @Override public ParserStatus parseFile(BufferedInputStream bis, String fileName) throws FileParserException { ParserStatus status = ParserStatus.INIT; try { if (getStep() == 0) { status = parseStep(bis, UTC_TIME_IN_SEC_LENGTH); if (status != ParserStatus.COMPLETE) return status; setUtcTimeInSec(CodecUtils.bytesToInt(readBuffer, 0, UTC_TIME_IN_SEC_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 1) { status = parseStep(bis, MSEC_LENGTH); if (status != ParserStatus.COMPLETE) return status; setmSec(CodecUtils.bytesToShort(readBuffer, 0, MSEC_LENGTH, ByteOrder.LITTLE_ENDIAN)); } resetStep(); status = ParserStatus.COMPLETE; } catch (Exception e) { throw new FileParserException(String.format("Error parsing %s on step %d", fileName, getStep()), e); } return status; } TimeParser(); @Override ParserStatus parseFile(BufferedInputStream bis, String fileName); long getUtcTimeInSec(); LogFileParser setUtcTimeInSec(int utcTimeInSec); short getmSec(); LogFileParser setmSec(short mSec); ZonedDateTime getGeneratedAt(); @Override void writeTo(OutputStream os); }
TimeParser extends LogFileParser { @Override public ParserStatus parseFile(BufferedInputStream bis, String fileName) throws FileParserException { ParserStatus status = ParserStatus.INIT; try { if (getStep() == 0) { status = parseStep(bis, UTC_TIME_IN_SEC_LENGTH); if (status != ParserStatus.COMPLETE) return status; setUtcTimeInSec(CodecUtils.bytesToInt(readBuffer, 0, UTC_TIME_IN_SEC_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 1) { status = parseStep(bis, MSEC_LENGTH); if (status != ParserStatus.COMPLETE) return status; setmSec(CodecUtils.bytesToShort(readBuffer, 0, MSEC_LENGTH, ByteOrder.LITTLE_ENDIAN)); } resetStep(); status = ParserStatus.COMPLETE; } catch (Exception e) { throw new FileParserException(String.format("Error parsing %s on step %d", fileName, getStep()), e); } return status; } TimeParser(); @Override ParserStatus parseFile(BufferedInputStream bis, String fileName); long getUtcTimeInSec(); LogFileParser setUtcTimeInSec(int utcTimeInSec); short getmSec(); LogFileParser setmSec(short mSec); ZonedDateTime getGeneratedAt(); @Override void writeTo(OutputStream os); static final int UTC_TIME_IN_SEC_LENGTH; static final int MSEC_LENGTH; }