/** * Splits an octet stream into the separate parts that would be the payloads of concatenated SMS * messages. * * @param messageBinary * @param sourcePort * @param destinationPort * @return Supplied byte[] split into parts. These parts should reconcatenate to form the original * byte array. Supplying a zero-length byte[] should return a single, empty part. */ public static byte[][] getPayloads(byte[] messageBinary, int sourcePort, int destinationPort) { if (messageBinary.length == 0) return new byte[][] {new byte[0]}; boolean isPorted = sourcePort > 0 || destinationPort > 0; int totalParts = getMessagesNeeded_8bit(messageBinary.length, isPorted); byte[][] payloadParts = new byte[totalParts][]; int udhLength = getUDHSize(true, isPorted, totalParts > 1); String encodedText = HexUtils.encode(messageBinary); for (int i = 0; i < payloadParts.length; i++) { payloadParts[i] = HexUtils.decode(extractPayload(encodedText, i + 1, udhLength)); } return payloadParts; }