Skip to content

Package: DecodeException

DecodeException

nameinstructionbranchcomplexitylinemethod
DecodeException(ByteBuffer, String)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
DecodeException(ByteBuffer, String, Throwable)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
DecodeException(String, String)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
DecodeException(String, String, Throwable)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getBytes()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getText()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 2018, 2019 Oracle and/or its affiliates and others.
3: * All rights reserved.
4: *
5: * This program and the accompanying materials are made available under the
6: * terms of the Eclipse Public License v. 2.0, which is available at
7: * http://www.eclipse.org/legal/epl-2.0.
8: *
9: * This Source Code may also be made available under the following Secondary
10: * Licenses when the conditions for such availability set forth in the
11: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
12: * version 2 with the GNU Classpath Exception, which is available at
13: * https://www.gnu.org/software/classpath/license.html.
14: *
15: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16: */
17:
18: package jakarta.websocket;
19:
20: import java.nio.ByteBuffer;
21:
22: /**
23: * A general exception that occurs when trying to decode a custom object from a text or binary message.
24: *
25: * @author dannycoward
26: */
27: public class DecodeException extends Exception {
28: private final ByteBuffer bb;
29: private final String encodedString;
30: private static final long serialVersionUID = 006;
31:
32: /**
33: * Constructor with the binary data that could not be decoded, and the reason why it failed to be, and the cause.
34: * The buffer may represent the whole message, or the part of the message most relevant to the decoding error,
35: * depending whether the application is using one of the streaming methods or not.
36: *
37: * @param bb the byte buffer containing the (part of) the message that could not be decoded.
38: * @param message the reason for the failure.
39: * @param cause the cause of the error.
40: */
41: public DecodeException(ByteBuffer bb, String message, Throwable cause) {
42: super(message, cause);
43: this.encodedString = null;
44: this.bb = bb;
45: }
46:
47: /**
48: * Constructor with the text data that could not be decoded, and the reason why it failed to be, and the cause. The
49: * encoded string may represent the whole message, or the part of the message most relevant to the decoding error,
50: * depending whether the application is using one of the streaming methods or not.
51: *
52: * @param encodedString the string representing the (part of) the message that could not be decoded.
53: * @param message the reason for the failure.
54: * @param cause the cause of the error.
55: */
56: public DecodeException(String encodedString, String message, Throwable cause) {
57: super(message, cause);
58: this.encodedString = encodedString;
59: this.bb = null;
60: }
61:
62: /**
63: * Constructs a DecodedException with the given ByteBuffer that cannot be decoded, and reason why. The buffer may
64: * represent the whole message, or the part of the message most relevant to the decoding error, depending whether
65: * the application is using one of the streaming methods or not.
66: *
67: * @param bb the byte buffer containing the (part of) the message that could not be decoded.
68: * @param message the reason for the failure.
69: */
70: public DecodeException(ByteBuffer bb, String message) {
71: super(message);
72: this.encodedString = null;
73: this.bb = bb;
74: }
75:
76: /**
77: * Constructs a DecodedException with the given encoded string that cannot be decoded, and reason why. The encoded
78: * string may represent the whole message, or the part of the message most relevant to the decoding error, depending
79: * whether the application is using one of the streaming methods or not.
80: *
81: * @param encodedString the string representing the (part of) the message that could not be decoded.
82: * @param message the reason for the failure.
83: */
84: public DecodeException(String encodedString, String message) {
85: super(message);
86: this.encodedString = encodedString;
87: this.bb = null;
88: }
89:
90: /**
91: * Return the ByteBuffer containing either the whole message, or the partial message, that could not be decoded, or
92: * {@code null} if this exception arose from a failure to decode a text message.
93: *
94: * @return the binary data not decoded or {@code null} for text message failures.
95: */
96: public ByteBuffer getBytes() {
97: return this.bb;
98: }
99:
100: /**
101: * Return the encoded string that is either the whole message, or the partial message that could not be decoded, or
102: * {@code null} if this exception arose from a failure to decode a binary message..
103: *
104: * @return the text not decoded or {@code null} for binary message failures.
105: */
106: public String getText() {
107: return this.encodedString;
108: }
109: }