001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache license, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the license for the specific language governing permissions and 015 * limitations under the license. 016 */ 017package org.apache.logging.log4j.core.appender; 018 019import java.nio.charset.StandardCharsets; 020 021import org.apache.logging.log4j.util.Chars; 022 023/** 024 * Wraps messages that are formatted according to RFC 5425. 025 * 026 * @see <a href="https://tools.ietf.org/html/rfc5425">RFC 5425</a> 027 */ 028public class TlsSyslogFrame { 029 private final String message; 030 private final int byteLength; 031 032 public TlsSyslogFrame(final String message) { 033 this.message = message; 034 final byte[] messageBytes = message.getBytes(StandardCharsets.UTF_8); 035 byteLength = messageBytes.length; 036 } 037 038 public String getMessage() { 039 return this.message; 040 } 041 042 @Override 043 public String toString() { 044 return Integer.toString(byteLength) + Chars.SPACE + message; 045 } 046 047 @Override 048 public int hashCode() { 049 final int prime = 31; 050 int result = 1; 051 result = prime * result + ((message == null) ? 0 : message.hashCode()); 052 return result; 053 } 054 055 @Override 056 public boolean equals(final Object obj) { 057 if (this == obj) { 058 return true; 059 } 060 if (obj == null) { 061 return false; 062 } 063 if (!(obj instanceof TlsSyslogFrame)) { 064 return false; 065 } 066 final TlsSyslogFrame other = (TlsSyslogFrame) obj; 067 if (message == null) { 068 if (other.message != null) { 069 return false; 070 } 071 } else if (!message.equals(other.message)) { 072 return false; 073 } 074 return true; 075 } 076 077}