blob: b5897d59736cc817d153f437661602718fce4613 [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Thomas Vachuska58de4162015-09-10 16:15:33 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070016package org.onosproject.pcepio.util;
17
18import org.jboss.netty.buffer.ChannelBuffer;
19import org.slf4j.Logger;
20import org.slf4j.LoggerFactory;
21
22/**
23 * Provides Hex Dump for debugging.
24 */
25public final class HexDump {
Ray Milkey9c9cde42018-01-12 14:22:06 -080026 private static final Logger log = LoggerFactory.getLogger(HexDump.class);
Sho SHIMIZUe81e4db2015-09-03 09:44:38 -070027
28 private HexDump() {
29 }
30
31 public static void pcepHexDump(ChannelBuffer buff) {
32
33 log.debug("==================== HEX DUMP ======================");
34 try {
35 byte[] yTemp;
36 yTemp = buff.array();
37
38 int iStartIndex = buff.readerIndex();
39 int iEndIndex = buff.writerIndex();
40 do {
41 StringBuilder sb = new StringBuilder();
42 for (int k = 0; (k < 16) && (iStartIndex < iEndIndex); ++k) {
43 if (0 == k % 4) {
44 sb.append(String.format(" ")); //blank after 4 bytes
45 }
46 sb.append(String.format("%02X ", yTemp[iStartIndex++]));
47 }
48 log.debug(sb.toString());
49 } while (iStartIndex < iEndIndex);
50 } catch (Exception e) {
51 log.error("[HexDump] Invalid buffer: " + e.toString());
52 }
53
54 log.debug("===================================================");
55 }
56}