@Test public void testSplit() throws Exception { AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(SIMPLE_MSG); SimpleRegexpMessageSplitter splitter = new SimpleRegexpMessageSplitter("\n"); List<AdaptrisMessage> result = splitter.splitMessage(msg); assertEquals(4, result.size()); }
@Override protected ArrayList<String> split(String messagePayload) throws Exception { String batch = messagePayload; compiledSplitPattern = compile(compiledSplitPattern, splitPattern); Matcher splitMatcher = compiledSplitPattern.matcher(batch); Matcher compareMatcher = null; if (compareToPreviousMatch()) { compiledMatchPattern = compile(compiledMatchPattern, matchPattern); compareMatcher = compiledMatchPattern.matcher(batch); } ArrayList<String> splitMessages = new ArrayList(); int splitStart = 0; int splitEnd = 0; StringBuffer currentSplitMsg = new StringBuffer(); String currentMatch = null; if (compareToPreviousMatch()) { try { compareMatcher.find(); currentMatch = compareMatcher.group(1); } catch (Exception e) { throw new Exception("Could not match record comparator [" + e.getMessage() + "]", e); } } while (splitMatcher.find(splitEnd)) { splitEnd = splitMatcher.end(); String thisRecord = batch.substring(splitStart, splitEnd); if (compareToPreviousMatch()) { compareMatcher = compiledMatchPattern.matcher(thisRecord); String newMatch = ""; if (compareMatcher.find()) { newMatch = compareMatcher.group(1); } if (currentMatch.equals(newMatch)) { currentSplitMsg.append(thisRecord); } else { splitMessages.add(currentSplitMsg.toString()); currentSplitMsg.setLength(0); currentSplitMsg.append(thisRecord); currentMatch = newMatch; } } else { splitMessages.add(thisRecord); } splitStart = splitEnd; } String thisRecord = batch.substring(splitStart); if (compareToPreviousMatch()) { compareMatcher = compiledMatchPattern.matcher(thisRecord); String newMatch = ""; if (compareMatcher.find()) { newMatch = compareMatcher.group(1); } if (currentMatch.equals(newMatch)) { currentSplitMsg.append(thisRecord); splitMessages.add(currentSplitMsg.toString()); } else { splitMessages.add(currentSplitMsg.toString()); currentSplitMsg.setLength(0); if (thisRecord.trim().length() > 0) { splitMessages.add(thisRecord); } } } else { if (thisRecord.trim().length() > 0) { splitMessages.add(thisRecord); } } if (ignoreFirstSubMessage()) { splitMessages.remove(0); } return splitMessages; }
SimpleRegexpMessageSplitter extends StringPayloadSplitter { @Override protected ArrayList<String> split(String messagePayload) throws Exception { String batch = messagePayload; compiledSplitPattern = compile(compiledSplitPattern, splitPattern); Matcher splitMatcher = compiledSplitPattern.matcher(batch); Matcher compareMatcher = null; if (compareToPreviousMatch()) { compiledMatchPattern = compile(compiledMatchPattern, matchPattern); compareMatcher = compiledMatchPattern.matcher(batch); } ArrayList<String> splitMessages = new ArrayList(); int splitStart = 0; int splitEnd = 0; StringBuffer currentSplitMsg = new StringBuffer(); String currentMatch = null; if (compareToPreviousMatch()) { try { compareMatcher.find(); currentMatch = compareMatcher.group(1); } catch (Exception e) { throw new Exception("Could not match record comparator [" + e.getMessage() + "]", e); } } while (splitMatcher.find(splitEnd)) { splitEnd = splitMatcher.end(); String thisRecord = batch.substring(splitStart, splitEnd); if (compareToPreviousMatch()) { compareMatcher = compiledMatchPattern.matcher(thisRecord); String newMatch = ""; if (compareMatcher.find()) { newMatch = compareMatcher.group(1); } if (currentMatch.equals(newMatch)) { currentSplitMsg.append(thisRecord); } else { splitMessages.add(currentSplitMsg.toString()); currentSplitMsg.setLength(0); currentSplitMsg.append(thisRecord); currentMatch = newMatch; } } else { splitMessages.add(thisRecord); } splitStart = splitEnd; } String thisRecord = batch.substring(splitStart); if (compareToPreviousMatch()) { compareMatcher = compiledMatchPattern.matcher(thisRecord); String newMatch = ""; if (compareMatcher.find()) { newMatch = compareMatcher.group(1); } if (currentMatch.equals(newMatch)) { currentSplitMsg.append(thisRecord); splitMessages.add(currentSplitMsg.toString()); } else { splitMessages.add(currentSplitMsg.toString()); currentSplitMsg.setLength(0); if (thisRecord.trim().length() > 0) { splitMessages.add(thisRecord); } } } else { if (thisRecord.trim().length() > 0) { splitMessages.add(thisRecord); } } if (ignoreFirstSubMessage()) { splitMessages.remove(0); } return splitMessages; } }
SimpleRegexpMessageSplitter extends StringPayloadSplitter { @Override protected ArrayList<String> split(String messagePayload) throws Exception { String batch = messagePayload; compiledSplitPattern = compile(compiledSplitPattern, splitPattern); Matcher splitMatcher = compiledSplitPattern.matcher(batch); Matcher compareMatcher = null; if (compareToPreviousMatch()) { compiledMatchPattern = compile(compiledMatchPattern, matchPattern); compareMatcher = compiledMatchPattern.matcher(batch); } ArrayList<String> splitMessages = new ArrayList(); int splitStart = 0; int splitEnd = 0; StringBuffer currentSplitMsg = new StringBuffer(); String currentMatch = null; if (compareToPreviousMatch()) { try { compareMatcher.find(); currentMatch = compareMatcher.group(1); } catch (Exception e) { throw new Exception("Could not match record comparator [" + e.getMessage() + "]", e); } } while (splitMatcher.find(splitEnd)) { splitEnd = splitMatcher.end(); String thisRecord = batch.substring(splitStart, splitEnd); if (compareToPreviousMatch()) { compareMatcher = compiledMatchPattern.matcher(thisRecord); String newMatch = ""; if (compareMatcher.find()) { newMatch = compareMatcher.group(1); } if (currentMatch.equals(newMatch)) { currentSplitMsg.append(thisRecord); } else { splitMessages.add(currentSplitMsg.toString()); currentSplitMsg.setLength(0); currentSplitMsg.append(thisRecord); currentMatch = newMatch; } } else { splitMessages.add(thisRecord); } splitStart = splitEnd; } String thisRecord = batch.substring(splitStart); if (compareToPreviousMatch()) { compareMatcher = compiledMatchPattern.matcher(thisRecord); String newMatch = ""; if (compareMatcher.find()) { newMatch = compareMatcher.group(1); } if (currentMatch.equals(newMatch)) { currentSplitMsg.append(thisRecord); splitMessages.add(currentSplitMsg.toString()); } else { splitMessages.add(currentSplitMsg.toString()); currentSplitMsg.setLength(0); if (thisRecord.trim().length() > 0) { splitMessages.add(thisRecord); } } } else { if (thisRecord.trim().length() > 0) { splitMessages.add(thisRecord); } } if (ignoreFirstSubMessage()) { splitMessages.remove(0); } return splitMessages; } SimpleRegexpMessageSplitter();  SimpleRegexpMessageSplitter(String pattern); }
SimpleRegexpMessageSplitter extends StringPayloadSplitter { @Override protected ArrayList<String> split(String messagePayload) throws Exception { String batch = messagePayload; compiledSplitPattern = compile(compiledSplitPattern, splitPattern); Matcher splitMatcher = compiledSplitPattern.matcher(batch); Matcher compareMatcher = null; if (compareToPreviousMatch()) { compiledMatchPattern = compile(compiledMatchPattern, matchPattern); compareMatcher = compiledMatchPattern.matcher(batch); } ArrayList<String> splitMessages = new ArrayList(); int splitStart = 0; int splitEnd = 0; StringBuffer currentSplitMsg = new StringBuffer(); String currentMatch = null; if (compareToPreviousMatch()) { try { compareMatcher.find(); currentMatch = compareMatcher.group(1); } catch (Exception e) { throw new Exception("Could not match record comparator [" + e.getMessage() + "]", e); } } while (splitMatcher.find(splitEnd)) { splitEnd = splitMatcher.end(); String thisRecord = batch.substring(splitStart, splitEnd); if (compareToPreviousMatch()) { compareMatcher = compiledMatchPattern.matcher(thisRecord); String newMatch = ""; if (compareMatcher.find()) { newMatch = compareMatcher.group(1); } if (currentMatch.equals(newMatch)) { currentSplitMsg.append(thisRecord); } else { splitMessages.add(currentSplitMsg.toString()); currentSplitMsg.setLength(0); currentSplitMsg.append(thisRecord); currentMatch = newMatch; } } else { splitMessages.add(thisRecord); } splitStart = splitEnd; } String thisRecord = batch.substring(splitStart); if (compareToPreviousMatch()) { compareMatcher = compiledMatchPattern.matcher(thisRecord); String newMatch = ""; if (compareMatcher.find()) { newMatch = compareMatcher.group(1); } if (currentMatch.equals(newMatch)) { currentSplitMsg.append(thisRecord); splitMessages.add(currentSplitMsg.toString()); } else { splitMessages.add(currentSplitMsg.toString()); currentSplitMsg.setLength(0); if (thisRecord.trim().length() > 0) { splitMessages.add(thisRecord); } } } else { if (thisRecord.trim().length() > 0) { splitMessages.add(thisRecord); } } if (ignoreFirstSubMessage()) { splitMessages.remove(0); } return splitMessages; } SimpleRegexpMessageSplitter();  SimpleRegexpMessageSplitter(String pattern); void setSplitPattern(String pattern); String getSplitPattern(); void setMatchPattern(String pattern); String getMatchPattern(); void setCompareToPreviousMatch(Boolean b); Boolean getCompareToPreviousMatch(); boolean compareToPreviousMatch(); void setIgnoreFirstSubMessage(Boolean b); Boolean getIgnoreFirstSubMessage(); boolean ignoreFirstSubMessage(); }
SimpleRegexpMessageSplitter extends StringPayloadSplitter { @Override protected ArrayList<String> split(String messagePayload) throws Exception { String batch = messagePayload; compiledSplitPattern = compile(compiledSplitPattern, splitPattern); Matcher splitMatcher = compiledSplitPattern.matcher(batch); Matcher compareMatcher = null; if (compareToPreviousMatch()) { compiledMatchPattern = compile(compiledMatchPattern, matchPattern); compareMatcher = compiledMatchPattern.matcher(batch); } ArrayList<String> splitMessages = new ArrayList(); int splitStart = 0; int splitEnd = 0; StringBuffer currentSplitMsg = new StringBuffer(); String currentMatch = null; if (compareToPreviousMatch()) { try { compareMatcher.find(); currentMatch = compareMatcher.group(1); } catch (Exception e) { throw new Exception("Could not match record comparator [" + e.getMessage() + "]", e); } } while (splitMatcher.find(splitEnd)) { splitEnd = splitMatcher.end(); String thisRecord = batch.substring(splitStart, splitEnd); if (compareToPreviousMatch()) { compareMatcher = compiledMatchPattern.matcher(thisRecord); String newMatch = ""; if (compareMatcher.find()) { newMatch = compareMatcher.group(1); } if (currentMatch.equals(newMatch)) { currentSplitMsg.append(thisRecord); } else { splitMessages.add(currentSplitMsg.toString()); currentSplitMsg.setLength(0); currentSplitMsg.append(thisRecord); currentMatch = newMatch; } } else { splitMessages.add(thisRecord); } splitStart = splitEnd; } String thisRecord = batch.substring(splitStart); if (compareToPreviousMatch()) { compareMatcher = compiledMatchPattern.matcher(thisRecord); String newMatch = ""; if (compareMatcher.find()) { newMatch = compareMatcher.group(1); } if (currentMatch.equals(newMatch)) { currentSplitMsg.append(thisRecord); splitMessages.add(currentSplitMsg.toString()); } else { splitMessages.add(currentSplitMsg.toString()); currentSplitMsg.setLength(0); if (thisRecord.trim().length() > 0) { splitMessages.add(thisRecord); } } } else { if (thisRecord.trim().length() > 0) { splitMessages.add(thisRecord); } } if (ignoreFirstSubMessage()) { splitMessages.remove(0); } return splitMessages; } SimpleRegexpMessageSplitter();  SimpleRegexpMessageSplitter(String pattern); void setSplitPattern(String pattern); String getSplitPattern(); void setMatchPattern(String pattern); String getMatchPattern(); void setCompareToPreviousMatch(Boolean b); Boolean getCompareToPreviousMatch(); boolean compareToPreviousMatch(); void setIgnoreFirstSubMessage(Boolean b); Boolean getIgnoreFirstSubMessage(); boolean ignoreFirstSubMessage();  }