Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 3 | * |
| 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 SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 16 | package org.onosproject.pcepio.util; |
| 17 | |
| 18 | import org.jboss.netty.buffer.ChannelBuffer; |
| 19 | import org.slf4j.Logger; |
| 20 | import org.slf4j.LoggerFactory; |
| 21 | |
| 22 | /** |
| 23 | * Provides Hex Dump for debugging. |
| 24 | */ |
| 25 | public final class HexDump { |
Ray Milkey | 9c9cde4 | 2018-01-12 14:22:06 -0800 | [diff] [blame] | 26 | private static final Logger log = LoggerFactory.getLogger(HexDump.class); |
Sho SHIMIZU | e81e4db | 2015-09-03 09:44:38 -0700 | [diff] [blame] | 27 | |
| 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 | } |