2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
25 package org.onap.aai.sparky.util;
28 * The Class RawByteHelper.
30 public class RawByteHelper {
31 private static final byte[] HEX_CHAR =
32 new byte[] {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
37 * @param buffer the buffer
41 * TODO -> DOCUMENT ME!
43 * @param buffer DOCUMENT ME!
45 * @return DOCUMENT ME!
47 public static String dumpBytes(byte[] buffer) {
51 String newLine = System.getProperty("line.separator");
52 StringBuffer sb = new StringBuffer();
54 for (int i = 0; i < buffer.length; i++) {
55 if (i != 0 && i % 16 == 0) {
58 // sb.append("0x").append((char) (HEX_CHAR[(buffer[i] & 0x00F0) >> 4])).append((char)
59 // (HEX_CHAR[buffer[i] & 0x000F])).append(" ");
60 sb.append((char) (HEX_CHAR[(buffer[i] & 0x00F0) >> 4]))
61 .append((char) (HEX_CHAR[buffer[i] & 0x000F])).append(" ");
67 // if you're trying to figure out why or's w/ FF's see:
73 * @param three the three
74 * @param four the four
77 // http://www.darksleep.com/player/JavaAndUnsignedTypes.html
78 public static int bytesToInt(byte one, byte two, byte three, byte four) {
79 return (((0xFF & one) << 24) | ((0xFF & two) << 16) | ((0xFF & three) << 8) | ((0xFF & four)));
89 public static short bytesToShort(byte one, byte two) {
90 return (short) (((0xFF & one) << 8) | (0xFF & two));
99 // short helper functions
100 static byte firstByte(short num) {
101 return (byte) ((num >> 8) & 0xFF);
110 // Int helper functions
111 static byte firstByte(int num) {
112 return (byte) ((num >> 24) & 0xFF);
121 static byte secondByte(short num) {
122 return (byte) (num & 0xFF);
131 static byte secondByte(int num) {
132 return (byte) ((num >> 16) & 0xFF);
141 static byte thirdByte(int num) {
142 return (byte) ((num >> 8) & 0xFF);
151 static byte fourthByte(int num) {
152 return (byte) (num & 0xFF);
158 * @param value the value
161 public static byte intToByte(int value) {
162 return fourthByte(value);
168 * @param value the value
171 public static short intToShort(int value) {
172 return (short) ((value & 0xFF00) | (value & 0xFF));