### Question:
ListenTCP extends AbstractListenEventBatchingProcessor<StandardEvent> { public Map<String, String> unpackContent(String annotation, byte[] data, Charset charset) { Map<String, String> attributes = new HashMap(); int from = 0, to = 0; ArrayList<UnPackingInfo> unpackingInfos = parseUnPackingInfos(annotation); for (int i=0; i<unpackingInfos.size(); i++) { UnPackingInfo info = unpackingInfos.get(i); int length = info.length; to += length; byte[] subArray = Arrays.copyOfRange(data, from, to); attributes.put(info.name, new String(subArray, charset)); from = to; } return attributes; }  @Override @OnScheduled void onScheduled(ProcessContext context); @Override @OnUnscheduled void onUnscheduled(); @OnStopped void onStopped(); Map<String, String> unpackContent(String annotation, byte[] data, Charset charset); static final String TCP_SENDER; static final String TCP_PORT; static final String TCP_MESSAGES; static final String TCP_CONTEXT_ID; static final String TCP_CONTEXT_CHARSET; static final String TCP_RESPONSE_DELIMITER; static final PropertyDescriptor SSL_CONTEXT_SERVICE; static final PropertyDescriptor CLIENT_AUTH; static final PropertyDescriptor RESPONDER_CONTEXT_MAP; }### Answer:
@Test public void testUnPackingData() throws Exception { String charSetName = "UTF-8"; final Charset charSet = Charset.forName(charSetName); ProcessContext processContext = runner.getProcessContext(); ListenTCP processor = (ListenTCP) runner.getProcessor(); byte[] data = TEST_MESSAGE_STRING.getBytes(charSet); Map<String, String> attributes = processor.unpackContent(ANNOTATION_DATA, data, charSet); Assert.assertEquals(12, attributes.get("mobileNo").length()); Assert.assertEquals("18511015637 ", attributes.get("mobileNo")); Assert.assertEquals(5, attributes.get("state").length()); Assert.assertEquals("ok ", attributes.get("state")); Assert.assertEquals(10, attributes.get("message").length()); Assert.assertEquals("Success ", attributes.get("message")); Assert.assertEquals("Success", attributes.get("message").trim()); }
@Test public void testUnPackingDataGBK() throws Exception { String charSetName = "gbk"; final Charset charSet = Charset.forName(charSetName); ProcessContext processContext = runner.getProcessContext(); ListenTCP processor = (ListenTCP) runner.getProcessor(); byte[] data = TEST_MESSAGE_STRING_GBK.getBytes(charSet); Map<String, String> attributes = processor.unpackContent(ANNOTATION_DATA, data, charSet); Assert.assertEquals(12, attributes.get("mobileNo").length()); Assert.assertEquals("18511015637 ", attributes.get("mobileNo")); Assert.assertEquals(5, attributes.get("state").length()); Assert.assertEquals("ok ", attributes.get("state")); Assert.assertEquals(10, attributes.get("message").getBytes("gbk").length); Assert.assertEquals("成功 ", attributes.get("message")); Assert.assertEquals("成功", attributes.get("message").trim()); }