@Test public void testGoodEventGoodEvent() { String priority = "<10>"; String goodData1 = "Good good good data\n"; SyslogUtils util = new SyslogUtils(false); ChannelBuffer buff = ChannelBuffers.buffer(100); buff.writeBytes((priority+goodData1).getBytes()); String priority2 = "<20>"; String goodData2 = "Good really good data\n"; buff.writeBytes((priority2+goodData2).getBytes()); Event e = util.extractEvent(buff); if(e == null){ throw new NullPointerException("Event is null"); } Map<String, String> headers = e.getHeaders(); Assert.assertEquals("1", headers.get(SyslogUtils.SYSLOG_FACILITY)); Assert.assertEquals("2", headers.get(SyslogUtils.SYSLOG_SEVERITY)); Assert.assertEquals(null, headers.get(SyslogUtils.EVENT_STATUS)); Assert.assertEquals(goodData1.trim(), new String(e.getBody()).trim()); Event e2 = util.extractEvent(buff); if(e2 == null){ throw new NullPointerException("Event is null"); } Map<String, String> headers2 = e2.getHeaders(); Assert.assertEquals("2", headers2.get(SyslogUtils.SYSLOG_FACILITY)); Assert.assertEquals("4", headers2.get(SyslogUtils.SYSLOG_SEVERITY)); Assert.assertEquals(null, headers.get(SyslogUtils.EVENT_STATUS)); Assert.assertEquals(goodData2.trim(), new String(e2.getBody()).trim()); }
public Event extractEvent(ChannelBuffer in){ byte b = 0; Event e = null; boolean doneReading = false; try { while (!doneReading && in.readable()) { b = in.readByte(); switch (m) { case START: if (b == '<') { m = Mode.PRIO; } else if(b == '\n'){ logger.debug("Delimiter found while in START mode, ignoring.."); } else { isBadEvent = true; baos.write(b); m = Mode.DATA; } break; case PRIO: if (b == '>') { m = Mode.DATA; } else { char ch = (char) b; prio.append(ch); if (!Character.isDigit(ch)) { isBadEvent = true; String badPrio = "<"+ prio; baos.write(badPrio.getBytes()); m = Mode.DATA; } } break; case DATA: if (b == '\n') { e = buildEvent(); doneReading = true; } else { baos.write(b); } if(baos.size() == this.maxSize && !doneReading){ isIncompleteEvent = true; e = buildEvent(); doneReading = true; } break; } } if (e == null && isUdp) { doneReading = true; e = buildEvent(); } } catch (IOException e1) { } finally { } return e; }
SyslogUtils { public Event extractEvent(ChannelBuffer in){ byte b = 0; Event e = null; boolean doneReading = false; try { while (!doneReading && in.readable()) { b = in.readByte(); switch (m) { case START: if (b == '<') { m = Mode.PRIO; } else if(b == '\n'){ logger.debug("Delimiter found while in START mode, ignoring.."); } else { isBadEvent = true; baos.write(b); m = Mode.DATA; } break; case PRIO: if (b == '>') { m = Mode.DATA; } else { char ch = (char) b; prio.append(ch); if (!Character.isDigit(ch)) { isBadEvent = true; String badPrio = "<"+ prio; baos.write(badPrio.getBytes()); m = Mode.DATA; } } break; case DATA: if (b == '\n') { e = buildEvent(); doneReading = true; } else { baos.write(b); } if(baos.size() == this.maxSize && !doneReading){ isIncompleteEvent = true; e = buildEvent(); doneReading = true; } break; } } if (e == null && isUdp) { doneReading = true; e = buildEvent(); } } catch (IOException e1) { } finally { } return e; } }
SyslogUtils { public Event extractEvent(ChannelBuffer in){ byte b = 0; Event e = null; boolean doneReading = false; try { while (!doneReading && in.readable()) { b = in.readByte(); switch (m) { case START: if (b == '<') { m = Mode.PRIO; } else if(b == '\n'){ logger.debug("Delimiter found while in START mode, ignoring.."); } else { isBadEvent = true; baos.write(b); m = Mode.DATA; } break; case PRIO: if (b == '>') { m = Mode.DATA; } else { char ch = (char) b; prio.append(ch); if (!Character.isDigit(ch)) { isBadEvent = true; String badPrio = "<"+ prio; baos.write(badPrio.getBytes()); m = Mode.DATA; } } break; case DATA: if (b == '\n') { e = buildEvent(); doneReading = true; } else { baos.write(b); } if(baos.size() == this.maxSize && !doneReading){ isIncompleteEvent = true; e = buildEvent(); doneReading = true; } break; } } if (e == null && isUdp) { doneReading = true; e = buildEvent(); } } catch (IOException e1) { } finally { } return e; } SyslogUtils();  SyslogUtils(boolean isUdp);  SyslogUtils(Integer eventSize, boolean keepFields, boolean isUdp); }
SyslogUtils { public Event extractEvent(ChannelBuffer in){ byte b = 0; Event e = null; boolean doneReading = false; try { while (!doneReading && in.readable()) { b = in.readByte(); switch (m) { case START: if (b == '<') { m = Mode.PRIO; } else if(b == '\n'){ logger.debug("Delimiter found while in START mode, ignoring.."); } else { isBadEvent = true; baos.write(b); m = Mode.DATA; } break; case PRIO: if (b == '>') { m = Mode.DATA; } else { char ch = (char) b; prio.append(ch); if (!Character.isDigit(ch)) { isBadEvent = true; String badPrio = "<"+ prio; baos.write(badPrio.getBytes()); m = Mode.DATA; } } break; case DATA: if (b == '\n') { e = buildEvent(); doneReading = true; } else { baos.write(b); } if(baos.size() == this.maxSize && !doneReading){ isIncompleteEvent = true; e = buildEvent(); doneReading = true; } break; } } if (e == null && isUdp) { doneReading = true; e = buildEvent(); } } catch (IOException e1) { } finally { } return e; } SyslogUtils();  SyslogUtils(boolean isUdp);  SyslogUtils(Integer eventSize, boolean keepFields, boolean isUdp); void addFormats(Map<String, String> formatProp); Event extractEvent(ChannelBuffer in); Integer getEventSize(); void setEventSize(Integer eventSize); void setKeepFields(Boolean keepFields); }
SyslogUtils { public Event extractEvent(ChannelBuffer in){ byte b = 0; Event e = null; boolean doneReading = false; try { while (!doneReading && in.readable()) { b = in.readByte(); switch (m) { case START: if (b == '<') { m = Mode.PRIO; } else if(b == '\n'){ logger.debug("Delimiter found while in START mode, ignoring.."); } else { isBadEvent = true; baos.write(b); m = Mode.DATA; } break; case PRIO: if (b == '>') { m = Mode.DATA; } else { char ch = (char) b; prio.append(ch); if (!Character.isDigit(ch)) { isBadEvent = true; String badPrio = "<"+ prio; baos.write(badPrio.getBytes()); m = Mode.DATA; } } break; case DATA: if (b == '\n') { e = buildEvent(); doneReading = true; } else { baos.write(b); } if(baos.size() == this.maxSize && !doneReading){ isIncompleteEvent = true; e = buildEvent(); doneReading = true; } break; } } if (e == null && isUdp) { doneReading = true; e = buildEvent(); } } catch (IOException e1) { } finally { } return e; } SyslogUtils();  SyslogUtils(boolean isUdp);  SyslogUtils(Integer eventSize, boolean keepFields, boolean isUdp); void addFormats(Map<String, String> formatProp); Event extractEvent(ChannelBuffer in); Integer getEventSize(); void setEventSize(Integer eventSize); void setKeepFields(Boolean keepFields); final static String SYSLOG_TIMESTAMP_FORMAT_RFC5424_2; final static String SYSLOG_TIMESTAMP_FORMAT_RFC5424_1; final static String SYSLOG_TIMESTAMP_FORMAT_RFC5424_3; final static String SYSLOG_TIMESTAMP_FORMAT_RFC5424_4; final static String SYSLOG_TIMESTAMP_FORMAT_RFC3164_1; final static String SYSLOG_MSG_RFC5424_0; final static String SYSLOG_MSG_RFC3164_0; final static int SYSLOG_TIMESTAMP_POS; final static int SYSLOG_HOSTNAME_POS; final static int SYSLOG_BODY_POS; final static String SYSLOG_FACILITY; final static String SYSLOG_SEVERITY; final static String EVENT_STATUS; final static Integer MIN_SIZE; final static Integer DEFAULT_SIZE; }