jdk/src/java.base/share/classes/sun/security/ssl/Debug.java
author xuelei
Wed, 23 Mar 2016 12:25:08 +0000
changeset 36661 044bf6a5474a
parent 34687 d302ed125dc9
child 37593 824750ada3d6
permissions -rw-r--r--
8149017: Delayed provider selection broken in RSA client key exchange Reviewed-by: coffeys
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
     2
 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4236
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4236
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4236
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4236
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4236
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.security.ssl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.security.AccessController;
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
    30
import java.util.Locale;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
34687
d302ed125dc9 8144995: Move sun.misc.HexDumpEncoder to sun.security.util
chegar
parents: 30904
diff changeset
    32
import sun.security.util.HexDumpEncoder;
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    33
import java.nio.ByteBuffer;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    34
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.security.action.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * This class has be shamefully lifted from sun.security.util.Debug
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @author Gary Ellison
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class Debug {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private String prefix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private static String args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        args = java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            new GetPropertyAction("javax.net.debug", ""));
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
    51
        args = args.toLowerCase(Locale.ENGLISH);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        if (args.equals("help")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            Help();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public static void Help()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        System.err.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        System.err.println("all            turn on all debugging");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        System.err.println("ssl            turn on ssl debugging");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        System.err.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        System.err.println("The following can be used with ssl:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        System.err.println("\trecord       enable per-record tracing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        System.err.println("\thandshake    print each handshake message");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        System.err.println("\tkeygen       print key generation data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        System.err.println("\tsession      print session activity");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        System.err.println("\tdefaultctx   print default SSL initialization");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        System.err.println("\tsslctx       print SSLContext tracing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        System.err.println("\tsessioncache print session cache tracing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        System.err.println("\tkeymanager   print key manager tracing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        System.err.println("\ttrustmanager print trust manager tracing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        System.err.println("\tpluggability print pluggability tracing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        System.err.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        System.err.println("\thandshake debugging can be widened with:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        System.err.println("\tdata         hex dump of each handshake message");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        System.err.println("\tverbose      verbose handshake message printing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        System.err.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        System.err.println("\trecord debugging can be widened with:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        System.err.println("\tplaintext    hex dump of record plaintext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        System.err.println("\tpacket       print raw SSL/TLS packets");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        System.err.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        System.exit(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Get a Debug object corresponding to whether or not the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * option is set. Set the prefix to be the same as option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public static Debug getInstance(String option)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        return getInstance(option, option);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Get a Debug object corresponding to whether or not the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * option is set. Set the prefix to be prefix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public static Debug getInstance(String option, String prefix)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        if (isOn(option)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            Debug d = new Debug();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            d.prefix = prefix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * True if the property "javax.net.debug" contains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * string "option".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public static boolean isOn(String option)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        if (args == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            int n = 0;
7039
6464c8e62a18 4873188: Support TLS 1.1
xuelei
parents: 5506
diff changeset
   121
            option = option.toLowerCase(Locale.ENGLISH);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            if (args.indexOf("all") != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            } else if ((n = args.indexOf("ssl")) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                if (args.indexOf("sslctx", n) == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                    // don't enable data and plaintext options by default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    if (!(option.equals("data")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                        || option.equals("packet")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                        || option.equals("plaintext"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            return (args.indexOf(option) != -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * print a message to stderr that is prefixed with the prefix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * created from the call to getInstance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public void println(String message)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        System.err.println(prefix + ": "+message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * print a blank line to stderr that is prefixed with the prefix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public void println()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        System.err.println(prefix + ":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * print a message to stderr that is prefixed with the prefix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public static void println(String prefix, String message)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        System.err.println(prefix + ": "+message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
4236
02f52c723b79 6894643: Separate out dependency on Kerberos
vinnie
parents: 2
diff changeset
   167
    public static void println(PrintStream s, String name, byte[] data) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        s.print(name + ":  { ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (data == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            s.print("null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            for (int i = 0; i < data.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                if (i != 0) s.print(", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                s.print(data[i] & 0x0ff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        s.println(" }");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Return the value of the boolean System property propName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * Note use of doPrivileged(). Do make accessible to applications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    static boolean getBooleanProperty(String propName, boolean defaultValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        // if set, require value of either true or false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        String b = AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                new GetPropertyAction(propName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (b == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            return defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        } else if (b.equalsIgnoreCase("false")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        } else if (b.equalsIgnoreCase("true")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            throw new RuntimeException("Value of " + propName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                + " must either be 'true' or 'false'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    static String toString(byte[] b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return sun.security.util.Debug.toString(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   204
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   205
    static void printHex(String prefix, byte[] bytes) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   206
        HexDumpEncoder dump = new HexDumpEncoder();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   207
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   208
        synchronized (System.out) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   209
            System.out.println(prefix);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   210
            try {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   211
                dump.encodeBuffer(bytes, System.out);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   212
            } catch (Exception e) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   213
                // ignore
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   214
            }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   215
            System.out.flush();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   216
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   217
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   218
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   219
    static void printHex(String prefix, ByteBuffer bb) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   220
        HexDumpEncoder dump = new HexDumpEncoder();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   221
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   222
        synchronized (System.out) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   223
            System.out.println(prefix);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   224
            try {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   225
                dump.encodeBuffer(bb.slice(), System.out);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   226
            } catch (Exception e) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   227
                // ignore
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   228
            }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   229
            System.out.flush();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   230
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   231
    }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   232
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   233
    static void printHex(String prefix, byte[] bytes, int offset, int length) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   234
        HexDumpEncoder dump = new HexDumpEncoder();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   235
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   236
        synchronized (System.out) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   237
            System.out.println(prefix);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   238
            try {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   239
                ByteBuffer bb = ByteBuffer.wrap(bytes, offset, length);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   240
                dump.encodeBuffer(bb, System.out);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   241
            } catch (Exception e) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   242
                // ignore
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   243
            }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   244
            System.out.flush();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   245
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   246
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
}