@Test public void testStep3Partial() { ParserStatus expectedStatus = ParserStatus.PARTIAL; int expectedStep = 3; BufferedInputStream testInputStream = new BufferedInputStream( new ByteArrayInputStream(new byte[] { (byte)0x6f, (byte)0x75, (byte)0x4d, (byte)0x19, (byte)0xa4, (byte)0xa1, (byte)0x5c, (byte)0xce, (byte)0x67, (byte)0x06, (byte)0x00, (byte)0x00, (byte)0x04 })); try { assertEquals(expectedStatus, locationParser.parseFile(testInputStream, "testLogFile.bin")); assertEquals(expectedStep, locationParser.getStep()); } catch (FileParserException e) { fail("Unexpected exception: " + e); } }
@Override public ParserStatus parseFile(BufferedInputStream bis, String fileName) throws FileParserException { ParserStatus status = ParserStatus.INIT; try { this.location = new LogLocation(); if (getStep() == 0) { status = parseStep(bis, LOCATION_LAT_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setLatitude(CodecUtils.bytesToInt(readBuffer, 0, LOCATION_LAT_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 1) { status = parseStep(bis, LOCATION_LON_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setLongitude(CodecUtils.bytesToInt(readBuffer, 0, LOCATION_LON_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 2) { status = parseStep(bis, LOCATION_ELEV_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setElevation(CodecUtils.bytesToInt(readBuffer, 0, LOCATION_ELEV_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 3) { status = parseStep(bis, LOCATION_SPEED_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setSpeed(CodecUtils.bytesToShort(readBuffer, 0, LOCATION_SPEED_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 4) { status = parseStep(bis, LOCATION_HEADING_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setHeading(CodecUtils.bytesToShort(readBuffer, 0, LOCATION_HEADING_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; }
LocationParser extends LogFileParser { @Override public ParserStatus parseFile(BufferedInputStream bis, String fileName) throws FileParserException { ParserStatus status = ParserStatus.INIT; try { this.location = new LogLocation(); if (getStep() == 0) { status = parseStep(bis, LOCATION_LAT_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setLatitude(CodecUtils.bytesToInt(readBuffer, 0, LOCATION_LAT_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 1) { status = parseStep(bis, LOCATION_LON_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setLongitude(CodecUtils.bytesToInt(readBuffer, 0, LOCATION_LON_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 2) { status = parseStep(bis, LOCATION_ELEV_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setElevation(CodecUtils.bytesToInt(readBuffer, 0, LOCATION_ELEV_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 3) { status = parseStep(bis, LOCATION_SPEED_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setSpeed(CodecUtils.bytesToShort(readBuffer, 0, LOCATION_SPEED_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 4) { status = parseStep(bis, LOCATION_HEADING_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setHeading(CodecUtils.bytesToShort(readBuffer, 0, LOCATION_HEADING_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; } }
LocationParser extends LogFileParser { @Override public ParserStatus parseFile(BufferedInputStream bis, String fileName) throws FileParserException { ParserStatus status = ParserStatus.INIT; try { this.location = new LogLocation(); if (getStep() == 0) { status = parseStep(bis, LOCATION_LAT_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setLatitude(CodecUtils.bytesToInt(readBuffer, 0, LOCATION_LAT_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 1) { status = parseStep(bis, LOCATION_LON_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setLongitude(CodecUtils.bytesToInt(readBuffer, 0, LOCATION_LON_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 2) { status = parseStep(bis, LOCATION_ELEV_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setElevation(CodecUtils.bytesToInt(readBuffer, 0, LOCATION_ELEV_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 3) { status = parseStep(bis, LOCATION_SPEED_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setSpeed(CodecUtils.bytesToShort(readBuffer, 0, LOCATION_SPEED_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 4) { status = parseStep(bis, LOCATION_HEADING_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setHeading(CodecUtils.bytesToShort(readBuffer, 0, LOCATION_HEADING_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; } LocationParser(); }
LocationParser extends LogFileParser { @Override public ParserStatus parseFile(BufferedInputStream bis, String fileName) throws FileParserException { ParserStatus status = ParserStatus.INIT; try { this.location = new LogLocation(); if (getStep() == 0) { status = parseStep(bis, LOCATION_LAT_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setLatitude(CodecUtils.bytesToInt(readBuffer, 0, LOCATION_LAT_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 1) { status = parseStep(bis, LOCATION_LON_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setLongitude(CodecUtils.bytesToInt(readBuffer, 0, LOCATION_LON_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 2) { status = parseStep(bis, LOCATION_ELEV_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setElevation(CodecUtils.bytesToInt(readBuffer, 0, LOCATION_ELEV_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 3) { status = parseStep(bis, LOCATION_SPEED_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setSpeed(CodecUtils.bytesToShort(readBuffer, 0, LOCATION_SPEED_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 4) { status = parseStep(bis, LOCATION_HEADING_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setHeading(CodecUtils.bytesToShort(readBuffer, 0, LOCATION_HEADING_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; } LocationParser(); @Override ParserStatus parseFile(BufferedInputStream bis, String fileName); LogLocation getLocation(); LocationParser setLocation(LogLocation location); @Override void writeTo(OutputStream os); }
LocationParser extends LogFileParser { @Override public ParserStatus parseFile(BufferedInputStream bis, String fileName) throws FileParserException { ParserStatus status = ParserStatus.INIT; try { this.location = new LogLocation(); if (getStep() == 0) { status = parseStep(bis, LOCATION_LAT_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setLatitude(CodecUtils.bytesToInt(readBuffer, 0, LOCATION_LAT_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 1) { status = parseStep(bis, LOCATION_LON_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setLongitude(CodecUtils.bytesToInt(readBuffer, 0, LOCATION_LON_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 2) { status = parseStep(bis, LOCATION_ELEV_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setElevation(CodecUtils.bytesToInt(readBuffer, 0, LOCATION_ELEV_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 3) { status = parseStep(bis, LOCATION_SPEED_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setSpeed(CodecUtils.bytesToShort(readBuffer, 0, LOCATION_SPEED_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 4) { status = parseStep(bis, LOCATION_HEADING_LENGTH); if (status != ParserStatus.COMPLETE) return status; location.setHeading(CodecUtils.bytesToShort(readBuffer, 0, LOCATION_HEADING_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; } LocationParser(); @Override ParserStatus parseFile(BufferedInputStream bis, String fileName); LogLocation getLocation(); LocationParser setLocation(LogLocation location); @Override void writeTo(OutputStream os); static final int LOCATION_LAT_LENGTH; static final int LOCATION_LON_LENGTH; static final int LOCATION_ELEV_LENGTH; static final int LOCATION_SPEED_LENGTH; static final int LOCATION_HEADING_LENGTH; }