Skip to content

Package: HexadecimalEncodingAlgorithm

HexadecimalEncodingAlgorithm

nameinstructionbranchcomplexitylinemethod
HexadecimalEncodingAlgorithm()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
convertFromCharacters(char[], int, int)
M: 65 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
convertToCharacters(Object, StringBuffer)
M: 47 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
decodeFromBytes(byte[], int, int)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
decodeFromInputStream(InputStream)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
encodeToBytes(Object, int, int, byte[], int)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
encodeToOutputStream(Object, OutputStream)
M: 15 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getOctetLengthFromPrimitiveLength(int)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getPrimtiveLengthFromOctetLength(int)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 0 C: 291
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3: *
4: * Copyright (c) 2004-2018 Oracle and/or its affiliates. All rights reserved.
5: *
6: * Oracle licenses this file to You under the Apache License, Version 2.0
7: * (the "License"); you may not use this file except in compliance with
8: * 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, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: package com.sun.xml.fastinfoset.algorithm;
20:
21: import java.io.IOException;
22: import java.io.InputStream;
23: import java.io.OutputStream;
24: import org.jvnet.fastinfoset.EncodingAlgorithmException;
25: import com.sun.xml.fastinfoset.CommonResourceBundle;
26:
27: public class HexadecimalEncodingAlgorithm extends BuiltInEncodingAlgorithm {
28: private static final char NIBBLE_TO_HEXADECIMAL_TABLE[] =
29: { '0','1','2','3','4','5','6','7',
30: '8','9','A','B','C','D','E','F' };
31:
32: private static final int HEXADECIMAL_TO_NIBBLE_TABLE[] = {
33: /*'0'*/ 0,
34: /*'1'*/ 1,
35: /*'2'*/ 2,
36: /*'3'*/ 3,
37: /*'4'*/ 4,
38: /*'5'*/ 5,
39: /*'6'*/ 6,
40: /*'7'*/ 7,
41: /*'8'*/ 8,
42: /*'9'*/ 9, -1, -1, -1, -1, -1, -1, -1,
43: /*'A'*/ 10,
44: /*'B'*/ 11,
45: /*'C'*/ 12,
46: /*'D'*/ 13,
47: /*'E'*/ 14,
48: /*'F'*/ 15,
49: /*'G'-'Z'*/-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
50: /*'[' - '`'*/ -1, -1, -1, -1, -1, -1,
51: /*'a'*/ 10,
52: /*'b'*/ 11,
53: /*'c'*/ 12,
54: /*'d'*/ 13,
55: /*'e'*/ 14,
56: /*'f'*/ 15 };
57:
58: public final Object decodeFromBytes(byte[] b, int start, int length) throws EncodingAlgorithmException {
59: final byte[] data = new byte[length];
60: System.arraycopy(b, start, data, 0, length);
61: return data;
62: }
63:
64: public final Object decodeFromInputStream(InputStream s) throws IOException {
65: throw new UnsupportedOperationException(CommonResourceBundle.getInstance().getString("message.notImplemented"));
66: }
67:
68:
69: public void encodeToOutputStream(Object data, OutputStream s) throws IOException {
70:• if (!(data instanceof byte[])) {
71: throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.dataNotByteArray"));
72: }
73:
74: s.write((byte[])data);
75: }
76:
77: public final Object convertFromCharacters(char[] ch, int start, int length) {
78:• if (length == 0) {
79: return new byte[0];
80: }
81:
82: StringBuilder encodedValue = removeWhitespace(ch, start, length);
83: int encodedLength = encodedValue.length();
84:• if (encodedLength == 0) {
85: return new byte[0];
86: }
87:
88: int valueLength = encodedValue.length() / 2;
89: byte[] value = new byte[valueLength];
90:
91: int encodedIdx = 0;
92:• for (int i = 0; i < valueLength; ++i) {
93: int nibble1 = HEXADECIMAL_TO_NIBBLE_TABLE[encodedValue.charAt(encodedIdx++) - '0'];
94: int nibble2 = HEXADECIMAL_TO_NIBBLE_TABLE[encodedValue.charAt(encodedIdx++) - '0'];
95: value[i] = (byte) ((nibble1 << 4) | nibble2);
96: }
97:
98: return value;
99: }
100:
101: public final void convertToCharacters(Object data, StringBuffer s) {
102:• if (data == null) {
103: return;
104: }
105: final byte[] value = (byte[]) data;
106:• if (value.length == 0) {
107: return;
108: }
109:
110: s.ensureCapacity(value.length * 2);
111:• for (int i = 0; i < value.length; ++i) {
112: s.append(NIBBLE_TO_HEXADECIMAL_TABLE[(value[i] >>> 4) & 0xf]);
113: s.append(NIBBLE_TO_HEXADECIMAL_TABLE[value[i] & 0xf]);
114: }
115: }
116:
117:
118:
119: public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
120: return octetLength * 2;
121: }
122:
123: public int getOctetLengthFromPrimitiveLength(int primitiveLength) {
124: return primitiveLength / 2;
125: }
126:
127: public final void encodeToBytes(Object array, int astart, int alength, byte[] b, int start) {
128: System.arraycopy((byte[])array, astart, b, start, alength);
129: }
130: }