From 8d0a08d949d0cb7729319d34ea60d7a8e628c02c Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Fri, 31 Jan 2025 14:46:29 +0100 Subject: error correction for unicode TLBs with wrong length indication --- .../org/uic/barcode/staticFrame/UTLAYDataRecord.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/org/uic/barcode/staticFrame/UTLAYDataRecord.java b/src/main/java/org/uic/barcode/staticFrame/UTLAYDataRecord.java index f2363c3..9794ed8 100644 --- a/src/main/java/org/uic/barcode/staticFrame/UTLAYDataRecord.java +++ b/src/main/java/org/uic/barcode/staticFrame/UTLAYDataRecord.java @@ -22,6 +22,8 @@ public class UTLAYDataRecord extends DataRecord { /** The ticket layout. */ private TicketLayout layout; + private int length = 0; + /** * Instantiates a new empty UTLAY data record. */ @@ -103,6 +105,7 @@ public class UTLAYDataRecord extends DataRecord { /** * Decode content. + * @return * * @throws IOException Signals that an I/O exception has occurred. * @throws EncodingFormatException the encoding format exception @@ -130,18 +133,23 @@ public class UTLAYDataRecord extends DataRecord { //Do Nothing } + int offsetBeforeFields = offset; try { decodeFields(elements, offset); } catch(Exception e) { + + offset = offsetBeforeFields; if (!decodeUtf8FieldsWithCharacterLengthSucceeded(elements, offset)) { throw e; } } + + this.length = offset; } @@ -246,6 +254,8 @@ public class UTLAYDataRecord extends DataRecord { int remainingBytes = content.length - offset; + remainingBytes = Math.min(characterLength * 4, remainingBytes); + String utf8String = null; for (int i = characterLength ; i < remainingBytes ;i++){ @@ -405,4 +415,14 @@ public class UTLAYDataRecord extends DataRecord { return layout; } + /* + * get the length of the data + * + * This is needed to fix encoding errors made due to wrong length descriptions on unicode content. + * + */ + public int getLength() { + return length; + } + } -- cgit v1.2.3