AndroidPrinter implements Printer { static int adjustEnd(String msg, int start, int originEnd) { if (originEnd == msg.length()) { return originEnd; } if (msg.charAt(originEnd) == '\n') { return originEnd; } int last = originEnd - 1; while (start < last) { if (msg.charAt(last) == '\n') { return last + 1; } last--; } return originEnd; } AndroidPrinter();  AndroidPrinter(int maxChunkSize); @Override void println(int logLevel, String tag, String msg);  }
@Test public void testPrintLongMessage() throws Exception { int messageChunkLength = AndroidPrinter.DEFAULT_MAX_CHUNK_SIZE; int length = (int) (3.6 * messageChunkLength); StringBuilder sb = new StringBuilder(length); for (int i = 0; i < length; i++) { sb.append(RandomUtil.randomAsciiChar()); } String msg = sb.toString(); XLog.d(msg); assertEquals(4, logContainer.size()); int start = 0; int end = 0; for (int i = 0; end < length; i++) { end = AndroidPrinter.adjustEnd(msg, start, Math.min(start + messageChunkLength, length)); String chunk = msg.substring(start, end); AssertUtil.assertHasLog(logContainer, i, chunk); start = end; } }