test/jdk/com/sun/jdi/RedefineNestmateAttr/NamedBuffer.java
author mbaesken
Tue, 03 Sep 2019 16:52:55 +0200
changeset 58000 62926eb5e40e
parent 50735 2f2af62dfac7
permissions -rw-r--r--
8230485: add handling of aix tar in configure Reviewed-by: erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
     1
/*
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
     2
 * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
     4
 *
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
     8
 *
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    13
 * accompanied this code).
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    14
 *
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    18
 *
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    21
 * questions.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    22
 */
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    23
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    24
import  java.io.*;
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    25
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    26
/*
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    27
 * Copyright 2003 Wily Technology, Inc.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    28
 */
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    29
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    30
public class NamedBuffer
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    31
{
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    32
    private final String    fName;
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    33
    private final byte[]    fBuffer;
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    34
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    35
    public
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    36
    NamedBuffer(    String  name,
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    37
                    byte[]  buffer)
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    38
        {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    39
        fName =     name;
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    40
        fBuffer =   buffer;
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    41
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    42
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    43
    public
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    44
    NamedBuffer(    String      name,
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    45
                    InputStream stream)
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    46
        throws IOException
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    47
        {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    48
        this(   name,
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    49
                loadBufferFromStream(stream));
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    50
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    51
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    52
    public String
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    53
    getName()
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    54
        {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    55
        return fName;
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    56
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    57
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    58
    public byte[]
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    59
    getBuffer()
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    60
        {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    61
        return fBuffer;
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    62
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    63
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    64
    public static byte[]
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    65
    loadBufferFromStream(InputStream stream)
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    66
        throws IOException
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    67
        {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    68
        // hack for now, just assume the stream will fit in our reasonable size buffer.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    69
        // if not, panic
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    70
        int bufferLimit = 200 * 1024;
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    71
        byte[]  readBuffer = new byte[bufferLimit];
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    72
        int actualSize = stream.read(readBuffer);
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    73
        if ( actualSize >= bufferLimit )
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    74
            {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    75
            // if there might be more bytes, just surrender
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    76
            throw new IOException("too big for buffer");
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    77
            }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    78
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    79
        byte[] resultBuffer = new byte[actualSize];
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    80
        System.arraycopy(   readBuffer,
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    81
                            0,
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    82
                            resultBuffer,
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    83
                            0,
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    84
                            actualSize);
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    85
        return resultBuffer;
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    86
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    87
}