byte[] record = new byte[SBP_RECORD_LENGTH];
ByteBuffer sbpRecordByteBuffer = ByteBuffer.wrap(record);
sbpRecordByteBuffer.order(ByteOrder.LITTLE_ENDIAN);
List<Wgs84Route> result = new ArrayList<Wgs84Route>();
Wgs84Route activeRoute = null;
Wgs84Position position;
Wgs84Position previousPosition = null;
int readBytes = 0, pointCount = 0;
while (source.read(record) == SBP_RECORD_LENGTH) {
readBytes += SBP_RECORD_LENGTH;
do {
sbpRecordByteBuffer.position(0);
position = decodePosition(sbpRecordByteBuffer);
if (!isValidPosition(position, previousPosition)) {
position = null;
int count = readOneByteFromInput(source, record);
readBytes += count;
if (count != 1) {
break;
}
// the first position must inside the first 40 bytes
if (pointCount == 0 && readBytes > 40)
break;
}
} while (position == null);
// at least three positions in the first 100 bytes
if (readBytes > 100 && pointCount < 3)
return;
if ((activeRoute == null || isTrackStart(sbpRecordByteBuffer)) && position != null) {
activeRoute = createRoute(Track,
createDateFormat(TRACK_NAME_DATE_FORMAT).format(position.getTime().getTime()),
new ArrayList<BaseNavigationPosition>());
result.add(activeRoute);
}
if (position != null && activeRoute != null)
activeRoute.getPositions().add(position);
else {
context.appendRoutes(result);
return;
}