SizeBasedSplitter extends MessageSplitterImp { public CloseableIterable<AdaptrisMessage> splitMessage(final AdaptrisMessage msg) throws CoreException { logR.debug("SizeBasedSplitter splits every {} bytes", splitSizeBytes()); logExpected(msg); try { return new SplitGenerator(msg.getInputStream(), msg, selectFactory(msg)); } catch (IOException e) { throw new CoreException(e); } } SizeBasedSplitter(); CloseableIterable<AdaptrisMessage> splitMessage(final AdaptrisMessage msg); Integer getSplitSizeBytes(); void setSplitSizeBytes(Integer l); static final int DEFAULT_SPLIT_SIZE; }
@Test public void testSplitMessage() throws Exception { SizeBasedSplitter splitter = new SizeBasedSplitter(); splitter.setSplitSizeBytes(1); splitter.setCopyMetadata(true); splitter.setCopyObjectMetadata(false); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(LINE); msg.addMetadata(METADATA_KEY, METADATA_KEY); msg.addObjectHeader(OBJ_KEY, OBJ_KEY); List<AdaptrisMessage> result = toList(splitter.splitMessage(msg)); assertEquals(LINE.length(), result.size()); String resultString = ""; for (AdaptrisMessage m : result) { assertFalse(m.getObjectHeaders().containsKey(OBJ_KEY)); assertTrue(m.headersContainsKey(METADATA_KEY)); resultString += m.getContent(); } assertEquals(LINE, resultString); }