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; 020import java.util.Objects; 021 022import org.apache.logging.log4j.util.Chars; 023 024/** 025 * Wraps messages that are formatted according to RFC 5425. 026 * 027 * @see <a href="https://tools.ietf.org/html/rfc5425">RFC 5425</a> 028 */ 029public class TlsSyslogFrame { 030 private final String message; 031 private final int byteLength; 032 033 public TlsSyslogFrame(final String message) { 034 this.message = message; 035 final byte[] messageBytes = message.getBytes(StandardCharsets.UTF_8); 036 byteLength = messageBytes.length; 037 } 038 039 public String getMessage() { 040 return this.message; 041 } 042 043 @Override 044 public String toString() { 045 return Integer.toString(byteLength) + Chars.SPACE + message; 046 } 047 048 @Override 049 public int hashCode() { 050 return 31 + Objects.hashCode(message); 051 } 052 053 @Override 054 public boolean equals(final Object obj) { 055 if (this == obj) { 056 return true; 057 } 058 if (obj == null) { 059 return false; 060 } 061 if (!(obj instanceof TlsSyslogFrame)) { 062 return false; 063 } 064 final TlsSyslogFrame other = (TlsSyslogFrame) obj; 065 if (!Objects.equals(message, other.message)) { 066 return false; 067 } 068 return true; 069 } 070 071}