jdk/src/java.naming/share/classes/com/sun/jndi/ldap/Ber.java
author stefank
Mon, 25 Aug 2014 09:10:13 +0200
changeset 26314 f8bc1966fb30
parent 25859 3317bb8137f4
child 34687 d302ed125dc9
permissions -rw-r--r--
8055416: Several vm/gc/heap/summary "After GC" events emitted for the same GC ID Reviewed-by: brutisso, ehelin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
     2
 * Copyright (c) 1999, 2011, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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 com.sun.jndi.ldap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.ByteArrayInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.misc.HexDumpEncoder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
  * Base class that defines common fields, constants, and debug method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
  * @author Jagane Sundar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public abstract class Ber {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    protected byte buf[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    protected int offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    protected int bufsize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    protected Ber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public static void dumpBER(OutputStream outStream, String tag, byte[] bytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        int from, int to) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            outStream.write('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            outStream.write(tag.getBytes("UTF8"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            new HexDumpEncoder().encodeBuffer(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                new ByteArrayInputStream(bytes, from, to),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                outStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            outStream.write('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                outStream.write(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                    "Ber.dumpBER(): error encountered\n".getBytes("UTF8"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            } catch (IOException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    ////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    // some ASN defines
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    ////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public static final int ASN_BOOLEAN         = 0x01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public static final int ASN_INTEGER         = 0x02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public static final int ASN_BIT_STRING      = 0x03;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public static final int ASN_SIMPLE_STRING   = 0x04;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public static final int ASN_OCTET_STR       = 0x04;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public static final int ASN_NULL            = 0x05;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public static final int ASN_OBJECT_ID       = 0x06;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public static final int ASN_SEQUENCE        = 0x10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public static final int ASN_SET             = 0x11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public static final int ASN_PRIMITIVE       = 0x00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public static final int ASN_UNIVERSAL       = 0x00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static final int ASN_CONSTRUCTOR     = 0x20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public static final int ASN_APPLICATION     = 0x40;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public static final int ASN_CONTEXT         = 0x80;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public static final int ASN_PRIVATE         = 0xC0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public static final int ASN_ENUMERATED      = 0x0a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    final static class EncodeException extends IOException {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    97
        private static final long serialVersionUID = -5247359637775781768L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        EncodeException(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            super(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    final static class DecodeException extends IOException {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   104
        private static final long serialVersionUID = 8735036969244425583L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        DecodeException(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            super(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
}