@Test public void testSplitMessage8Bit() throws Exception { final String message = "Test sms gateway long smss, Test sms gateway long smss, Test sms gateway long smss, Test sms gateway long smss, Test sms gateway long smss, Test sms gateway long smss, Test sms gateway long smss, Test sms gateway long smss, Test sms gateway long smss, Test sms gatew"; final byte[][] splittedMsg = LongSMS.splitMessage8Bit(message.getBytes("US-ASCII")); Assert.assertEquals(266, (message.getBytes().length)); Assert.assertEquals(140, splittedMsg[0].length); Assert.assertEquals(140, splittedMsg[1].length); for (int i = 0; i < splittedMsg.length; i++) { Assert.assertEquals("UDH length", 0x06, splittedMsg[i][0]); Assert.assertEquals("IE identifier", 0x08, splittedMsg[i][1]); Assert.assertEquals("IE length", 0x04, splittedMsg[i][2]); Assert.assertEquals("The referencenumber differs", OctetUtil.bytesToShort(splittedMsg[0], 3), OctetUtil.bytesToShort(splittedMsg[i], 3)); Assert.assertEquals("Total of segments differs", splittedMsg.length, splittedMsg[i][5]); Assert.assertEquals("The segmentnumber differs", i + 1, splittedMsg[i][6]); } }
public static byte[][] splitMessage8Bit(byte[] aMessage) { int segmentNum = aMessage.length / MAX_MESSAGE_SEGMENT_8BIT; int messageLength = aMessage.length; if (segmentNum > 255) { segmentNum = 255; messageLength = segmentNum * MAX_MESSAGE_SEGMENT_8BIT; } if ((messageLength % MAX_MESSAGE_SEGMENT_8BIT) > 0) segmentNum++; byte[][] segments = new byte[segmentNum][]; int lengthOfData; byte[] referenceNumber = copyShort2Bytes(getReferenceNumber()); for (int i = 0; i < segmentNum; i++) { logger.debug("i = {}", i); if (segmentNum - i == 1) lengthOfData = messageLength - i * MAX_MESSAGE_SEGMENT_8BIT; else lengthOfData = MAX_MESSAGE_SEGMENT_8BIT; logger.debug("Length of data = {}", lengthOfData); segments[i] = new byte[7 + lengthOfData]; logger.debug("segments[{}].length = {}", i, segments[i].length); segments[i][0] = 6; segments[i][1] = UDHIE_IDENTIFIER_SAR; segments[i][2] = UDHIE_SAR_LENGTH; System.arraycopy(referenceNumber, 0, segments[i], 3, 2); segments[i][5] = (byte) segmentNum; segments[i][6] = (byte) (i + 1); System.arraycopy(aMessage, i * MAX_MESSAGE_SEGMENT_8BIT, segments[i], 7, lengthOfData); } return segments; }
LongSMS { public static byte[][] splitMessage8Bit(byte[] aMessage) { int segmentNum = aMessage.length / MAX_MESSAGE_SEGMENT_8BIT; int messageLength = aMessage.length; if (segmentNum > 255) { segmentNum = 255; messageLength = segmentNum * MAX_MESSAGE_SEGMENT_8BIT; } if ((messageLength % MAX_MESSAGE_SEGMENT_8BIT) > 0) segmentNum++; byte[][] segments = new byte[segmentNum][]; int lengthOfData; byte[] referenceNumber = copyShort2Bytes(getReferenceNumber()); for (int i = 0; i < segmentNum; i++) { logger.debug("i = {}", i); if (segmentNum - i == 1) lengthOfData = messageLength - i * MAX_MESSAGE_SEGMENT_8BIT; else lengthOfData = MAX_MESSAGE_SEGMENT_8BIT; logger.debug("Length of data = {}", lengthOfData); segments[i] = new byte[7 + lengthOfData]; logger.debug("segments[{}].length = {}", i, segments[i].length); segments[i][0] = 6; segments[i][1] = UDHIE_IDENTIFIER_SAR; segments[i][2] = UDHIE_SAR_LENGTH; System.arraycopy(referenceNumber, 0, segments[i], 3, 2); segments[i][5] = (byte) segmentNum; segments[i][6] = (byte) (i + 1); System.arraycopy(aMessage, i * MAX_MESSAGE_SEGMENT_8BIT, segments[i], 7, lengthOfData); } return segments; } }
LongSMS { public static byte[][] splitMessage8Bit(byte[] aMessage) { int segmentNum = aMessage.length / MAX_MESSAGE_SEGMENT_8BIT; int messageLength = aMessage.length; if (segmentNum > 255) { segmentNum = 255; messageLength = segmentNum * MAX_MESSAGE_SEGMENT_8BIT; } if ((messageLength % MAX_MESSAGE_SEGMENT_8BIT) > 0) segmentNum++; byte[][] segments = new byte[segmentNum][]; int lengthOfData; byte[] referenceNumber = copyShort2Bytes(getReferenceNumber()); for (int i = 0; i < segmentNum; i++) { logger.debug("i = {}", i); if (segmentNum - i == 1) lengthOfData = messageLength - i * MAX_MESSAGE_SEGMENT_8BIT; else lengthOfData = MAX_MESSAGE_SEGMENT_8BIT; logger.debug("Length of data = {}", lengthOfData); segments[i] = new byte[7 + lengthOfData]; logger.debug("segments[{}].length = {}", i, segments[i].length); segments[i][0] = 6; segments[i][1] = UDHIE_IDENTIFIER_SAR; segments[i][2] = UDHIE_SAR_LENGTH; System.arraycopy(referenceNumber, 0, segments[i], 3, 2); segments[i][5] = (byte) segmentNum; segments[i][6] = (byte) (i + 1); System.arraycopy(aMessage, i * MAX_MESSAGE_SEGMENT_8BIT, segments[i], 7, lengthOfData); } return segments; } private  LongSMS(); }
LongSMS { public static byte[][] splitMessage8Bit(byte[] aMessage) { int segmentNum = aMessage.length / MAX_MESSAGE_SEGMENT_8BIT; int messageLength = aMessage.length; if (segmentNum > 255) { segmentNum = 255; messageLength = segmentNum * MAX_MESSAGE_SEGMENT_8BIT; } if ((messageLength % MAX_MESSAGE_SEGMENT_8BIT) > 0) segmentNum++; byte[][] segments = new byte[segmentNum][]; int lengthOfData; byte[] referenceNumber = copyShort2Bytes(getReferenceNumber()); for (int i = 0; i < segmentNum; i++) { logger.debug("i = {}", i); if (segmentNum - i == 1) lengthOfData = messageLength - i * MAX_MESSAGE_SEGMENT_8BIT; else lengthOfData = MAX_MESSAGE_SEGMENT_8BIT; logger.debug("Length of data = {}", lengthOfData); segments[i] = new byte[7 + lengthOfData]; logger.debug("segments[{}].length = {}", i, segments[i].length); segments[i][0] = 6; segments[i][1] = UDHIE_IDENTIFIER_SAR; segments[i][2] = UDHIE_SAR_LENGTH; System.arraycopy(referenceNumber, 0, segments[i], 3, 2); segments[i][5] = (byte) segmentNum; segments[i][6] = (byte) (i + 1); System.arraycopy(aMessage, i * MAX_MESSAGE_SEGMENT_8BIT, segments[i], 7, lengthOfData); } return segments; } private  LongSMS(); static byte[][] splitMessage8Bit(byte[] aMessage); }
LongSMS { public static byte[][] splitMessage8Bit(byte[] aMessage) { int segmentNum = aMessage.length / MAX_MESSAGE_SEGMENT_8BIT; int messageLength = aMessage.length; if (segmentNum > 255) { segmentNum = 255; messageLength = segmentNum * MAX_MESSAGE_SEGMENT_8BIT; } if ((messageLength % MAX_MESSAGE_SEGMENT_8BIT) > 0) segmentNum++; byte[][] segments = new byte[segmentNum][]; int lengthOfData; byte[] referenceNumber = copyShort2Bytes(getReferenceNumber()); for (int i = 0; i < segmentNum; i++) { logger.debug("i = {}", i); if (segmentNum - i == 1) lengthOfData = messageLength - i * MAX_MESSAGE_SEGMENT_8BIT; else lengthOfData = MAX_MESSAGE_SEGMENT_8BIT; logger.debug("Length of data = {}", lengthOfData); segments[i] = new byte[7 + lengthOfData]; logger.debug("segments[{}].length = {}", i, segments[i].length); segments[i][0] = 6; segments[i][1] = UDHIE_IDENTIFIER_SAR; segments[i][2] = UDHIE_SAR_LENGTH; System.arraycopy(referenceNumber, 0, segments[i], 3, 2); segments[i][5] = (byte) segmentNum; segments[i][6] = (byte) (i + 1); System.arraycopy(aMessage, i * MAX_MESSAGE_SEGMENT_8BIT, segments[i], 7, lengthOfData); } return segments; } private  LongSMS(); static byte[][] splitMessage8Bit(byte[] aMessage);  }