GsmUtil { static public byte[] getShortMessageUserData(byte[] shortMessage) throws IllegalArgumentException { if (shortMessage == null) { return null; } if (shortMessage.length == 0) { return shortMessage; } int userDataHeaderLength = ByteUtil.decodeUnsigned(shortMessage[0]) + 1; if (userDataHeaderLength > shortMessage.length) { throw new IllegalArgumentException("User data header length exceeds short message length [shortMessageLength=" + shortMessage.length + ", userDataHeaderLength=" + userDataHeaderLength + "]"); } int newShortMessageLength = shortMessage.length - userDataHeaderLength; byte[] newShortMessage = new byte[newShortMessageLength]; System.arraycopy(shortMessage, userDataHeaderLength, newShortMessage, 0, newShortMessageLength); return newShortMessage; }  static byte[] toBcd(String address); static byte toSubmitInfo(boolean replyPath, boolean udhIndicator,
            boolean deliveryReceipt, int validityPeriodFormat, boolean rejectDuplicates); static byte[] removeUserDataHeader(byte[] shortMessage); static byte[] getShortMessageUserData(byte[] shortMessage); static byte[] getShortMessageUserDataHeader(byte[] shortMessage); static byte[][] createConcatenatedBinaryShortMessages(byte[] binaryShortMessage, byte referenceNum);  }
@Test public void getShortMessageUserData() { Assert.assertNull(GsmUtil.getShortMessageUserData(null)); Assert.assertArrayEquals(HexUtil.toByteArray(""), GsmUtil.getShortMessageUserData(HexUtil.toByteArray(""))); Assert.assertArrayEquals(HexUtil.toByteArray("02"), GsmUtil.getShortMessageUserData(HexUtil.toByteArray("0002"))); Assert.assertArrayEquals(HexUtil.toByteArray(""), GsmUtil.getShortMessageUserData(HexUtil.toByteArray("0102"))); Assert.assertArrayEquals(HexUtil.toByteArray("0304050607"), GsmUtil.getShortMessageUserData(HexUtil.toByteArray("01020304050607"))); Assert.assertArrayEquals(HexUtil.toByteArray("08"), GsmUtil.getShortMessageUserData(HexUtil.toByteArray("80000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708090001020304050607080900010203040506070809000102030405060708"))); try { Assert.assertArrayEquals(HexUtil.toByteArray("01"), GsmUtil.getShortMessageUserData(HexUtil.toByteArray("01"))); Assert.fail(); } catch (IllegalArgumentException e) { } }