001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.transport.tcp.util;
038:
039: import java.nio.ByteBuffer;
040:
041: /**
042: * @author Alexey Stashok
043: */
044: public final class DumpUtils {
045: public static String dumpBytes(final ByteBuffer[] bb) {
046: final StringBuffer stringBuffer = new StringBuffer();
047: for (int i = 0; i < bb.length; i++) {
048: stringBuffer.append(dumpBytes(bb[i]));
049: }
050:
051: return stringBuffer.toString();
052: }
053:
054: public static String dumpBytes(final ByteBuffer buffer) {
055: return dumpBytes(buffer, buffer.position(), buffer.limit()
056: - buffer.position());
057: }
058:
059: public static String dumpBytes(final ByteBuffer buffer,
060: final int offset, final int length) {
061: final byte[] array = new byte[length];
062: final int position = buffer.position();
063: buffer.position(offset);
064: buffer.get(array);
065: buffer.position(position);
066: return dumpBytes(array);
067: }
068:
069: public static String dumpOctets(final ByteBuffer[] bb) {
070: final StringBuffer stringBuffer = new StringBuffer();
071: for (int i = 0; i < bb.length; i++) {
072: stringBuffer.append(dumpOctets(bb[i]));
073: }
074:
075: return stringBuffer.toString();
076: }
077:
078: public static String dumpOctets(final ByteBuffer buffer) {
079: return dumpOctets(buffer, buffer.position(), buffer.limit()
080: - buffer.position());
081: }
082:
083: public static String dumpOctets(final ByteBuffer buffer,
084: final int offset, final int length) {
085: final byte[] array = new byte[length];
086: final int position = buffer.position();
087: buffer.position(offset);
088: buffer.get(array);
089: buffer.position(position);
090: return dumpBytes(array);
091: }
092:
093: public static String dump(final ByteBuffer[] bb) {
094: final StringBuffer stringBuffer = new StringBuffer();
095: for (int i = 0; i < bb.length; i++) {
096: stringBuffer.append(dump(bb[i]));
097: }
098:
099: return stringBuffer.toString();
100: }
101:
102: public static String dump(final ByteBuffer buffer) {
103: return dump(buffer, buffer.position(), buffer.limit()
104: - buffer.position());
105: }
106:
107: public static String dump(final ByteBuffer buffer,
108: final int offset, final int length) {
109: final byte[] array = new byte[length];
110: final int position = buffer.position();
111: buffer.position(offset);
112: buffer.get(array);
113: buffer.position(position);
114: return dump(array);
115: }
116:
117: public static String dump(final byte[] buffer) {
118: return dump(buffer, 0, buffer.length);
119: }
120:
121: public static String dump(final byte[] buffer, final int offset,
122: final int length) {
123: final StringBuffer stringBuffer = new StringBuffer();
124: for (int i = 0; i < length; i++) {
125: final int value = buffer[offset + i] & 0xFF;
126: final String strValue = Integer.toHexString(value)
127: .toUpperCase();
128: final String str = "00".substring(strValue.length())
129: + strValue;
130: stringBuffer.append(str);
131: stringBuffer.append('(');
132: stringBuffer.append((char) value);
133: stringBuffer.append(')');
134: stringBuffer.append(' ');
135: }
136:
137: return stringBuffer.toString();
138: }
139:
140: public static String dumpOctets(final byte[] buffer) {
141: return dumpOctets(buffer, 0, buffer.length);
142: }
143:
144: public static String dumpOctets(final byte[] buffer,
145: final int offset, final int length) {
146: final StringBuffer stringBuffer = new StringBuffer();
147: for (int i = 0; i < length; i++) {
148: final int value = buffer[offset + i] & 0xFF;
149: final String strValue = Integer.toHexString(value)
150: .toUpperCase();
151: final String str = "00".substring(strValue.length())
152: + strValue;
153: stringBuffer.append(str);
154: stringBuffer.append(' ');
155: }
156:
157: return stringBuffer.toString();
158: }
159:
160: public static String dumpBytes(final byte[] buffer) {
161: return dumpBytes(buffer, 0, buffer.length);
162: }
163:
164: public static String dumpBytes(final byte[] buffer,
165: final int offset, final int length) {
166: final StringBuffer stringBuffer = new StringBuffer();
167: for (int i = 0; i < length; i++) {
168: final int value = buffer[offset + i] & 0xFF;
169: stringBuffer.append((char) value);
170: }
171:
172: return stringBuffer.toString();
173: }
174: }
|