1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.mina.protocol;
20
21 import org.apache.mina.common.ByteBuffer;
22
23 /***
24 * An exception that is thrown when {@link ProtocolEncoder} cannot understand or
25 * failed to validate the specified message, or when {@link ProtocolDecoder}
26 * cannot understand or failed to validate the specified {@link ByteBuffer}
27 * content.
28 *
29 * @author Trustin Lee (trustin@apache.org)
30 * @version $Rev: 210062 $, $Date: 2005-07-11 12:52:38 +0900 $
31 */
32 public class ProtocolViolationException extends Exception
33 {
34 private static final long serialVersionUID = 3545799879533408565L;
35
36 private ByteBuffer buffer;
37
38 /***
39 * Constructs a new instance.
40 */
41 public ProtocolViolationException()
42 {
43 }
44
45 /***
46 * Constructs a new instance with the specified message.
47 */
48 public ProtocolViolationException( String message )
49 {
50 super( message );
51 }
52
53 /***
54 * Constructs a new instance with the specified cause.
55 */
56 public ProtocolViolationException( Throwable cause )
57 {
58 super( cause );
59 }
60
61 /***
62 * Constructs a new instance with the specified message and the specified
63 * cause.
64 */
65 public ProtocolViolationException( String message, Throwable cause )
66 {
67 super( message, cause );
68 }
69
70 /***
71 * Returns the message and the hexdump of the unknown part.
72 */
73 public String getMessage()
74 {
75 String message = super.getMessage();
76
77 if( message == null )
78 {
79 message = "";
80 }
81
82 if( buffer != null )
83 {
84 return message + ( ( message.length() > 0 ) ? " " : "" )
85 + "(Hexdump: " + buffer.getHexDump() + ')';
86 }
87 else
88 {
89 return message;
90 }
91 }
92
93 /***
94 * Returns unknown message part.
95 */
96 public ByteBuffer getBuffer()
97 {
98 return buffer;
99 }
100
101 /***
102 * Sets unknown message part.
103 */
104 public void setBuffer( ByteBuffer buffer )
105 {
106 this.buffer = buffer;
107 }
108 }