Source:
protected String getString(SerialMessage serialMessage, int offset) { int charPresentation = serialMessage.getMessagePayloadByte(offset + 1); charPresentation = 0x07 & charPresentation; switch (charPresentation) { case ENCODING_ASCII: logger.info("NODE : Node Name is encoded with standard ASCII codes", this.getNode().getNodeId()); break; case ENCODING_EXTENDED_ASCII: logger.info("NODE : Node Name is encoded with Using standard and OEM Extended ASCII codes", this.getNode().getNodeId()); break; case ENCODING_UTF16: logger.info("NODE : Node Name is encoded with Unicode UTF-16", this.getNode().getNodeId()); break; default: logger.error("NODE : Node Name encodeding is unsupported. Encoding code {}", this.getNode().getNodeId(), charPresentation); return null; } int numBytes = serialMessage.getMessagePayload().length - 3; if(numBytes <= 0) { logger.error("NODE : Node Name report error in message length", this.getNode().getNodeId()); return null; } if( numBytes > MAX_STRING_LENGTH) { logger.warn("NODE : Node Name is too big maximum is characters {}", this.getNode().getNodeId(), MAX_STRING_LENGTH, numBytes); numBytes = MAX_STRING_LENGTH; } byte[] strBuffer = Arrays.copyOfRange(serialMessage.getMessagePayload(), offset + 2, serialMessage.getMessagePayload().length); try { switch(charPresentation) { case ENCODING_ASCII: case ENCODING_EXTENDED_ASCII: return new String(strBuffer, "ASCII"); case ENCODING_UTF16: String sTemp = new String(strBuffer, "UTF-16"); return new String(sTemp.getBytes("UTF-8"),"UTF-8"); } } catch (UnsupportedEncodingException uee ) { System.out.println( "Exception: " + uee); } return null; }

Target:
protected String getString(SerialMessage serialMessage, int offset) { int charPresentation = serialMessage.getMessagePayloadByte(offset + 1); charPresentation = 0x07 & charPresentation; switch (charPresentation) { case ENCODING_ASCII: logger.debug("NODE : Node Name is encoded with standard ASCII codes", this.getNode().getNodeId()); break; case ENCODING_EXTENDED_ASCII: logger.debug("NODE : Node Name is encoded with Using standard and OEM Extended ASCII codes", this.getNode().getNodeId()); break; case ENCODING_UTF16: logger.debug("NODE : Node Name is encoded with Unicode UTF-16", this.getNode().getNodeId()); break; default: logger.error("NODE : Node Name encodeding is unsupported. Encoding code {}", this.getNode().getNodeId(), charPresentation); return null; } int numBytes = serialMessage.getMessagePayload().length - (offset + 2); if(numBytes <= 0) { logger.error("NODE : Node Name report error in message length", this.getNode().getNodeId()); return null; } if( numBytes > MAX_STRING_LENGTH) { logger.warn("NODE : Node Name is too big maximum is characters {}", this.getNode().getNodeId(), MAX_STRING_LENGTH, numBytes); numBytes = MAX_STRING_LENGTH; } byte[] strBuffer = Arrays.copyOfRange(serialMessage.getMessagePayload(), offset + 2, offset + 2 + numBytes); try { switch(charPresentation) { case ENCODING_ASCII: case ENCODING_EXTENDED_ASCII: return new String(strBuffer, "ASCII"); case ENCODING_UTF16: String sTemp = new String(strBuffer, "UTF-16"); return new String(sTemp.getBytes("UTF-8"),"UTF-8"); } } catch (UnsupportedEncodingException uee ) { System.out.println( "Exception: " + uee); } return null; }