1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.logging.log4j.core.net.server;
18
19 import java.io.InputStream;
20 import java.nio.charset.Charset;
21
22 import org.apache.logging.log4j.core.LogEvent;
23 import org.apache.logging.log4j.core.jackson.Log4jXmlObjectMapper;
24
25
26
27
28 public class XmlInputStreamLogEventBridge extends InputStreamLogEventBridge {
29
30 private static final String EVENT_END = "</Event>";
31 private static final String EVENT_START_NS_N = "<Event>";
32 private static final String EVENT_START_NS_Y = "<Event ";
33
34 public XmlInputStreamLogEventBridge() {
35 this(1024, Charset.defaultCharset());
36 }
37
38 public XmlInputStreamLogEventBridge(final int bufferSize, final Charset charset) {
39 super(new Log4jXmlObjectMapper(), bufferSize, charset, EVENT_END);
40 }
41
42 @Override
43 protected int[] getEventIndices(final String text, final int beginIndex) {
44 int start = text.indexOf(EVENT_START_NS_Y, beginIndex);
45 int startLen = EVENT_START_NS_Y.length();
46 if (start < 0) {
47 start = text.indexOf(EVENT_START_NS_N, beginIndex);
48 startLen = EVENT_START_NS_N.length();
49 }
50 final int end = start < 0 ? -1 : text.indexOf(EVENT_END, start + startLen);
51 return new int[] { start, end };
52 }
53
54 }