From c4a3ff3076531873e1faf1bb6a172bebb7204ccd Mon Sep 17 00:00:00 2001 From: Max Schenkelberg Date: Mon, 17 Sep 2012 12:59:10 -0500 Subject: [PATCH] Issue #626 update WMOHeaderRemover to remove any extra bytes before wmo header found from WMOHeaderFinder. Change-Id: I836fbc496c2dd2da610dbdd16b6bea0428a7966a Former-commit-id: 5f580a3989a9f08c20e829ae60318dcf2964ee6d --- .../common/util/header/WMOHeaderRemover.java | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/edexOsgi/com.raytheon.uf.common.util/src/com/raytheon/uf/common/util/header/WMOHeaderRemover.java b/edexOsgi/com.raytheon.uf.common.util/src/com/raytheon/uf/common/util/header/WMOHeaderRemover.java index 82f2287046..4de88b678a 100644 --- a/edexOsgi/com.raytheon.uf.common.util/src/com/raytheon/uf/common/util/header/WMOHeaderRemover.java +++ b/edexOsgi/com.raytheon.uf.common.util/src/com/raytheon/uf/common/util/header/WMOHeaderRemover.java @@ -48,25 +48,30 @@ public class WMOHeaderRemover { return data; } + // A header we can remove was found. Will discard any data before header byte[] headerBytes = header.getBytes(); - boolean equal = false; - // Do < since there should be something after the header - if (headerBytes.length < data.length) { - equal = true; - for (int i = 0; i < headerBytes.length; ++i) { - if (headerBytes[i] != data[i]) { - equal = false; + // Must be data after header + int endLength = data.length - headerBytes.length; + for (int i = 0; i < endLength; ++i) { + if (data[i] == headerBytes[0]) { + // First byte matches + int tmpI = i; + for (int j = 0; j < headerBytes.length; ++j, ++tmpI) { + if (data[tmpI] != headerBytes[j]) { + tmpI = -1; + break; + } + } + if (tmpI > 0) { + // Copy data and break + byte[] newData = new byte[data.length - tmpI]; + System.arraycopy(data, tmpI, newData, 0, newData.length); + data = newData; break; } } } - if (equal) { - byte[] newData = new byte[data.length - headerBytes.length]; - System.arraycopy(data, headerBytes.length, newData, 0, - newData.length); - data = newData; - } return data; } }