Handle corrupted offline data gracefully and ensure 100% completion #30
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: Handle corrupted offline data gracefully and ensure 100% completion
Problem
When receiving offline stroke data from the pen device, the SDK would encounter issues with corrupted data:
dotCountvalues (e.g., 60484 dots for a single stroke)Root Cause
oRcvDataSizecounter wouldn't always increment properly when errors occurredposition == 2) was received, if there was a small byte discrepancy (e.g., 560 bytes), the progress would never reach 100%Solution
1. Skip corrupted strokes gracefully (
OfflineByteParser.java)dotCountvalues (corrupted header detection)2. Ensure progress reaches 100% (
CommProcessor20.java)oRcvDataSizeafter successful parsing, even if some strokes were corruptedposition == 2), ifoRcvDataSize < oTotalDataSize, force it to 100% completion3. Better error handling
Changes Made
OfflineByteParser.java
hasCorruptedDataflag to track corruption without throwing exceptionsdotCount < 0check to detect corrupted headersrequiredBytes > data.lengthto ensure enough data exists for the strokeparse()to log warnings instead of throwing exceptions when corrupted data is foundCommProcessor20.java
oRcvDataSize += sizeBeforeCompressinside the try block to ensure it always incrementsif (position == 2 && oRcvDataSize < oTotalDataSize)→ set to 100%Testing
Log Output Example
Impact
Technical Details
Offline Data Protocol
The pen sends offline data in chunks with the following structure:
Each stroke in the data has:
Why 560 bytes were missing
The discrepancy between
oTotalDataSize(413683) andoRcvDataSize(413123) occurs because:sizeBeforeCompressvalueThe solution forces completion on the last chunk to handle this edge case gracefully.
Files Modified
NASDK2.0_Studio/app/src/main/java/kr/neolab/sdk/pen/offline/OfflineByteParser.javaNASDK2.0_Studio/app/src/main/java/kr/neolab/sdk/pen/bluetooth/comm/CommProcessor20.java