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.common.ByteBuffer;
    23
    24  /**
    25   * An exception that is thrown when {@link ProtocolDecoder}
    26   * cannot understand or failed to validate the specified {@link ByteBuffer}
    27   * content.
    28   *
    29   * @author The Apache Directory Project (mina-dev@directory.apache.org)
    30   * @version $Rev: 555855 $, $Date: 2007-07-13 12:19:00 +0900 (Fri, 13 Jul 2007) $
    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      public String getMessage() {
    69          String message = super.getMessage();
    70
    71          if (message == null) {
    72              message = "";
    73          }
    74
    75          if (hexdump != null) {
    76              return message + ((message.length() > 0) ? " " : "") + "(Hexdump: "
    77                      + hexdump + ')';
    78          } else {
    79              return message;
    80          }
    81      }
    82
    83      /**
    84       * Returns the hexdump of the unknown message part.
    85       */
    86      public String getHexdump() {
    87          return hexdump;
    88      }
    89
    90      /**
    91       * Sets the hexdump of the unknown message part.
    92       */
    93      public void setHexdump(String hexdump) {
    94          if (this.hexdump != null) {
    95              throw new IllegalStateException(
    96                      "Hexdump cannot be set more than once.");
    97          }
    98          this.hexdump = hexdump;
    99      }
    100 }