查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License.
18   *
19   */
20  package org.apache.mina.filter.codec;
21  
22  import org.apache.mina.core.buffer.IoBuffer;
23  
24  /**
25   * An exception that is thrown when {@link ProtocolDecoder}
26   * cannot understand or failed to validate the specified {@link IoBuffer}
27   * content.
28   *
29   * @author <a href="http://mina.apache.org">Apache MINA Project</a>
30   */
31  public class ProtocolDecoderException extends ProtocolCodecException {
32      private static final long serialVersionUID = 3545799879533408565L;
33  
34      private String hexdump;
35  
36      /**
37       * Constructs a new instance.
38       */
39      public ProtocolDecoderException() {
40          // Do nothing
41      }
42  
43      /**
44       * Constructs a new instance with the specified message.
45       * 
46       * @param message The detail message
47       */
48      public ProtocolDecoderException(String message) {
49          super(message);
50      }
51  
52      /**
53       * Constructs a new instance with the specified cause.
54       * 
55       * @param cause The Exception's cause
56       */
57      public ProtocolDecoderException(Throwable cause) {
58          super(cause);
59      }
60  
61      /**
62       * Constructs a new instance with the specified message and the specified
63       * cause.
64       * 
65       * @param message The detail message
66       * @param cause The Exception's cause
67       */
68      public ProtocolDecoderException(String message, Throwable cause) {
69          super(message, cause);
70      }
71  
72      /**
73       * @return the message and the hexdump of the unknown part.
74       */
75      @Override
76      public String getMessage() {
77          String message = super.getMessage();
78  
79          if (message == null) {
80              message = "";
81          }
82  
83          if (hexdump != null) {
84              return message + (message.length() > 0 ? " " : "") + "(Hexdump: " + hexdump + ')';
85          }
86  
87          return message;
88      }
89  
90      /**
91       * @return the hexdump of the unknown message part.
92       */
93      public String getHexdump() {
94          return hexdump;
95      }
96  
97      /**
98       * Sets the hexdump of the unknown message part.
99       * 
100      * @param hexdump The hexadecimal String representation of the message 
101      */
102     public void setHexdump(String hexdump) {
103         if (this.hexdump != null) {
104             throw new IllegalStateException("Hexdump cannot be set more than once.");
105         }
106         
107         this.hexdump = hexdump;
108     }
109 }