test/jdk/java/io/charStreams/BufferedReaderMark.java
author tschatzl
Wed, 24 Jul 2019 11:49:39 +0200
changeset 57508 28ab01c06755
parent 47216 71c04702a3d5
permissions -rw-r--r--
8228388: Add information about dirty/skipped card for Merge HCC in G1 log Summary: Collect and print informatio about the number of processed cards during the Merge HCC phase to improve log output. Reviewed-by: kbarrett, sangheki
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/* @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
   @summary General tests for BufferedReader.mark
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
public class BufferedReaderMark {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    static int bufferSize = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    static int inputSize = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    static String d2(int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
        String s = Integer.toString(n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
        if (s.length() < 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
            return s + " ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
            return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    static void fail(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        throw new RuntimeException(s);
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 main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        PrintStream log = System.err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        if (bufferSize == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            bufferSize = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        if (inputSize == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            inputSize = bufferSize * 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            Reader in = new BufferedReader(new ABCReader(inputSize), bufferSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            char buf[] = new char[bufferSize];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            if (in.read(buf) != bufferSize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                fail("Read failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            in.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            fail("reset() didn't throw");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            if (x.getMessage().equals("Stream not marked"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                log.println("Unmarked-stream test OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                fail(x.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        boolean err = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            Reader in = new BufferedReader(new ABCReader(inputSize), bufferSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            char buf[] = new char[bufferSize];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            if (in.read() == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                fail("Read 1 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            in.mark(bufferSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            while (in.read() != -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            in.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            fail("reset() didn't throw");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            if (x.getMessage().equals("Mark invalid")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                err = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                log.println("Invalid-mark test OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                log.println("Invalid-mark test failed: " + x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                fail(x.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (! err)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            fail("Invalid-mark test failed: Exception not thrown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        int c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        for (int off = 0; off < bufferSize * 2; off++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            for (int ra = 0; ra <= inputSize + 2; ra++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                Reader in = new BufferedReader(new ABCReader(inputSize), bufferSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                log.print(d2(off) + ", " + d2(ra) + "  mark: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                for (int i = 0; i < off; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                    if ((c = in.read()) == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                        log.print("<EOF>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                    log.print((char) c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                in.mark(ra);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                for (int i = 0; i < ra; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                    if ((c = in.read()) == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                        log.print("<EOF>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                    log.print((char) c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                log.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                log.print(d2(off) + ", " + d2(ra) + " reset: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                in.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                for (int i = 0; i < off; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                    log.print(' ');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                    if ((c = in.read()) == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                        log.print("<EOF>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                    log.print((char) c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                log.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            }
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
}