blob: 853a597ca7c2dda95bd26f6dbb0c443d4439decc [file] [log] [blame]
Madan Jampanic27b6b22016-02-05 11:36:31 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Madan Jampanic27b6b22016-02-05 11:36:31 -08003 *
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 */
16package org.onlab.util;
17
18import org.jboss.netty.buffer.ChannelBuffer;
19import org.slf4j.Logger;
20import org.slf4j.LoggerFactory;
21
22/**
23 * HexDump class an utility to dump buffer in hex format.
Yuta HIGUCHI385348e2017-05-21 00:30:16 -070024 *
25 * @deprecated in 1.11.0
Madan Jampanic27b6b22016-02-05 11:36:31 -080026 */
Yuta HIGUCHI385348e2017-05-21 00:30:16 -070027@Deprecated
Madan Jampanic27b6b22016-02-05 11:36:31 -080028public final class HexDump {
Ray Milkey9c9cde42018-01-12 14:22:06 -080029 private static final Logger log = LoggerFactory.getLogger(HexDump.class);
Madan Jampanic27b6b22016-02-05 11:36:31 -080030
31 private HexDump() {
32 }
33
34 /**
35 * Dump the buffer content in hex format.
36 *
37 * @param buff buffer content to dump in hex format
38 */
39 public static void dump(ChannelBuffer buff) {
40 buff.markReaderIndex();
41 try {
42 do {
43 StringBuilder sb = new StringBuilder();
44 for (int k = 0; (k < 16) && (buff.readableBytes() != 0); ++k) {
45 if (0 == k % 4) {
Ray Milkey42b62032018-02-01 11:15:31 -080046 sb.append(" "); // blank after 4 bytes
Madan Jampanic27b6b22016-02-05 11:36:31 -080047 }
48 sb.append(String.format("%02X ", buff.readByte()));
49 }
50 log.debug(sb.toString());
51 } while (buff.readableBytes() != 0);
52 } catch (Exception e) {
53 log.error("[HexDump] Invalid buffer: " + e.toString());
54 }
55 buff.resetReaderIndex();
56 }
57}