View Javadoc

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 The Apache MINA Project (dev@mina.apache.org)
30   * @version $Rev: 671827 $, $Date: 2008-06-26 10:49:48 +0200 (jeu, 26 jun 2008) $
31   */
32  public class ProtocolDecoderException extends ProtocolCodecException {
33      private static final long serialVersionUID = 3545799879533408565L;
34  
35      private String hexdump;
36  
37      /**
38       * Constructs a new instance.
39       */
40      public ProtocolDecoderException() {
41      }
42  
43      /**
44       * Constructs a new instance with the specified message.
45       */
46      public ProtocolDecoderException(String message) {
47          super(message);
48      }
49  
50      /**
51       * Constructs a new instance with the specified cause.
52       */
53      public ProtocolDecoderException(Throwable cause) {
54          super(cause);
55      }
56  
57      /**
58       * Constructs a new instance with the specified message and the specified
59       * cause.
60       */
61      public ProtocolDecoderException(String message, Throwable cause) {
62          super(message, cause);
63      }
64  
65      /**
66       * Returns the message and the hexdump of the unknown part.
67       */
68      @Override
69      public String getMessage() {
70          String message = super.getMessage();
71  
72          if (message == null) {
73              message = "";
74          }
75  
76          if (hexdump != null) {
77              return message + (message.length() > 0 ? " " : "") + "(Hexdump: "
78                      + hexdump + ')';
79          } else {
80              return message;
81          }
82      }
83  
84      /**
85       * Returns the hexdump of the unknown message part.
86       */
87      public String getHexdump() {
88          return hexdump;
89      }
90  
91      /**
92       * Sets the hexdump of the unknown message part.
93       */
94      public void setHexdump(String hexdump) {
95          if (this.hexdump != null) {
96              throw new IllegalStateException(
97                      "Hexdump cannot be set more than once.");
98          }
99          this.hexdump = hexdump;
100     }
101 }