KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > transport > MessageLength


1 /*_############################################################################
2   _##
3   _## SNMP4J - MessageLength.java
4   _##
5   _## Copyright 2003-2007 Frank Fock and Jochen Katz (SNMP4J.org)
6   _##
7   _## Licensed under the Apache License, Version 2.0 (the "License");
8   _## you may not use this file except in compliance with the License.
9   _## You may obtain a copy of the License at
10   _##
11   _## http://www.apache.org/licenses/LICENSE-2.0
12   _##
13   _## Unless required by applicable law or agreed to in writing, software
14   _## distributed under the License is distributed on an "AS IS" BASIS,
15   _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   _## See the License for the specific language governing permissions and
17   _## limitations under the License.
18   _##
19   _##########################################################################*/

20
21 package org.snmp4j.transport;
22
23 import java.io.*;
24
25 /**
26  * The <code>MessageLength</code> object contains information about the
27  * length of a message and the length of its header.
28  *
29  * @author Frank Fock
30  * @version 1.7
31  * @since 1.7
32  */

33 public class MessageLength implements Serializable {
34
35   private static final long serialVersionUID = -2722178759367760246L;
36
37   private int payloadLength;
38   private int headerLength;
39
40   /**
41    * Constructs a MessageLength object.
42    * @param headerLength
43    * the length in bytes of the message header.
44    * @param payloadLength
45    * the length of the payload.
46    */

47   public MessageLength(int headerLength, int payloadLength) {
48     this.payloadLength = payloadLength;
49     this.headerLength = headerLength;
50   }
51
52   /**
53    * Returns the length of the payload.
54    * @return
55    * the length in bytes.
56    */

57   public int getPayloadLength() {
58     return payloadLength;
59   }
60
61   /**
62    * Returns the length of the header.
63    * @return
64    * the length in bytes.
65    */

66   public int getHeaderLength() {
67     return headerLength;
68   }
69
70   /**
71    * Returns the total message length (header+payload).
72    * @return
73    * the sum of {@link #getHeaderLength()} and {@link #getPayloadLength()}.
74    */

75   public int getMessageLength() {
76     return headerLength + payloadLength;
77   }
78
79   public String JavaDoc toString() {
80     return MessageLength.class.getName()+
81         "[headerLength="+headerLength+",payloadLength="+payloadLength+"]";
82   }
83 }
84
Popular Tags