test/jdk/java/nio/channels/FileChannel/MapTest.java
author jbhateja
Tue, 26 Nov 2019 16:09:25 +0300
changeset 59278 8375560db76b
parent 55548 1ba68bf27e27
permissions -rw-r--r--
8234394: C2: Dynamic register class support in ADLC Reviewed-by: vlivanov, sviswanathan, thartmann, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
54823
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
     2
 * Copyright (c) 2000, 2019, 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
14401
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    25
 * @bug 4429043 8002180
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @summary Test file mapping with FileChannel
55548
1ba68bf27e27 8224480: (fc) java/nio/channels/FileChannel/MapTest.java fails intermittently
bpb
parents: 54823
diff changeset
    27
 * @run main/othervm/timeout=240 MapTest
30046
cf2c86e1819e 8078334: Mark regression tests using randomness
darcy
parents: 14401
diff changeset
    28
 * @key randomness
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.nio.MappedByteBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.nio.channels.*;
14401
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    34
import java.nio.channels.FileChannel.MapMode;
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    35
import java.nio.file.Files;
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    36
import static java.nio.file.StandardOpenOption.*;
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    37
import static java.nio.charset.StandardCharsets.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Random;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * Testing FileChannel's mapping capabilities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public class MapTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
14401
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    47
    private static PrintStream out = System.out;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static PrintStream err = System.err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private static Random generator = new Random();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private static int CHARS_PER_LINE = File.separatorChar == '/' ? 5 : 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private static File blah;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        blah = File.createTempFile("blah", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        blah.deleteOnExit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        initTestFile(blah);
14401
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    60
        try {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    61
            out.println("Test file " + blah + " initialized");
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    62
            testZero();
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    63
            out.println("Zero size: OK");
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    64
            testRead();
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    65
            out.println("Read: OK");
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    66
            testWrite();
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    67
            out.println("Write: OK");
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    68
            testHighOffset();
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    69
            out.println("High offset: OK");
54823
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
    70
            testForce();
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
    71
            out.println("Force: OK");
14401
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    72
            testExceptions();
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    73
            out.println("Exceptions: OK");
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    74
        } finally {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    75
            blah.delete();
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    76
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Creates file blah:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * 0000
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * 0001
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * 0002
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * 0003
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * .
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * .
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * .
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * 3999
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Blah extends beyond a single page of memory so that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * ability to index into a file of multiple pages is tested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private static void initTestFile(File blah) throws Exception {
14401
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    94
        try (BufferedWriter writer = Files.newBufferedWriter(blah.toPath(), ISO_8859_1)) {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    95
            for (int i=0; i<4000; i++) {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    96
                String number = new Integer(i).toString();
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    97
                for (int h=0; h<4-number.length(); h++)
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    98
                    writer.write("0");
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
    99
                writer.write(""+i);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   100
                writer.newLine();
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   101
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Tests zero size file mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private static void testZero() throws Exception {
14401
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   109
        try (FileInputStream fis = new FileInputStream(blah)) {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   110
            FileChannel fc = fis.getChannel();
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   111
            MappedByteBuffer b = fc.map(MapMode.READ_ONLY, 0, 0);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   112
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Maps blah file with a random offset and checks to see if read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * from the ByteBuffer gets the right line number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private static void testRead() throws Exception {
14401
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   120
        StringBuilder sb = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        sb.setLength(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        for (int x=0; x<1000; x++) {
14401
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   124
            try (FileInputStream fis = new FileInputStream(blah)) {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   125
                FileChannel fc = fis.getChannel();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
14401
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   127
                long offset = generator.nextInt(10000);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   128
                long expectedResult = offset / CHARS_PER_LINE;
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   129
                offset = expectedResult * CHARS_PER_LINE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
14401
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   131
                MappedByteBuffer b = fc.map(MapMode.READ_ONLY,
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   132
                                            offset, 100);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
14401
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   134
                for (int i=0; i<4; i++) {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   135
                    byte aByte = b.get(i);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   136
                    sb.setCharAt(i, (char)aByte);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   137
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
14401
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   139
                int result = Integer.parseInt(sb.toString());
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   140
                if (result != expectedResult) {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   141
                    err.println("I expected "+expectedResult);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   142
                    err.println("I got "+result);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   143
                    throw new Exception("Read test failed");
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   144
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
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
     * Maps blah file with a random offset and checks to see if data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * written out to the file can be read back in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    private static void testWrite() throws Exception {
14401
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   154
        StringBuilder sb = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        sb.setLength(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        for (int x=0; x<1000; x++) {
14401
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   158
            try (RandomAccessFile raf = new RandomAccessFile(blah, "rw")) {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   159
                FileChannel fc = raf.getChannel();
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   160
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   161
                long offset = generator.nextInt(1000);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   162
                MappedByteBuffer b = fc.map(MapMode.READ_WRITE,
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   163
                                            offset, 100);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
14401
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   165
                for (int i=0; i<4; i++) {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   166
                    b.put(i, (byte)('0' + i));
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   167
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
14401
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   169
                for (int i=0; i<4; i++) {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   170
                    byte aByte = b.get(i);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   171
                    sb.setCharAt(i, (char)aByte);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   172
                }
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   173
                if (!sb.toString().equals("0123"))
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   174
                    throw new Exception("Write test failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    private static void testHighOffset() throws Exception {
14401
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   180
        StringBuilder sb = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        sb.setLength(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        for (int x=0; x<1000; x++) {
14401
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   184
            try (RandomAccessFile raf = new RandomAccessFile(blah, "rw")) {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   185
                FileChannel fc = raf.getChannel();
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   186
                long offset = 66000;
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   187
                MappedByteBuffer b = fc.map(MapMode.READ_WRITE,
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   188
                                            offset, 100);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   189
            }
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   190
        }
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   191
    }
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   192
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   193
    /**
54823
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   194
     * Maps blah file, writes some data and forcing writeback of
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   195
     * the data exercising various valid and invalid writeback ranges.
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   196
     */
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   197
    private static void testForce() throws Exception {
55548
1ba68bf27e27 8224480: (fc) java/nio/channels/FileChannel/MapTest.java fails intermittently
bpb
parents: 54823
diff changeset
   198
        for (int x=0; x<50; x++) {
54823
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   199
            try (RandomAccessFile raf = new RandomAccessFile(blah, "rw")) {
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   200
                FileChannel fc = raf.getChannel();
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   201
                final int BLOCK_SIZE = 64;
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   202
                final int BLOCK_COUNT = (4096 * 2)/ BLOCK_SIZE;
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   203
                int offset = 0;
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   204
                MappedByteBuffer b = fc.map(MapMode.READ_WRITE,
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   205
                                            0, BLOCK_SIZE * (BLOCK_COUNT + 1));
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   206
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   207
                for (int blocks = 0; blocks < BLOCK_COUNT; blocks++) {
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   208
                    for (int i = 0; i < BLOCK_SIZE; i++) {
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   209
                        b.put(offset + i, (byte)('0' + i));
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   210
                    }
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   211
                    b.force(offset, BLOCK_SIZE);
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   212
                    offset += BLOCK_SIZE;
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   213
                }
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   214
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   215
                Exception exc = null;
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   216
                try {
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   217
                    // start and end are out of range
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   218
                    b.force(offset + BLOCK_SIZE, BLOCK_SIZE);
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   219
                } catch (IndexOutOfBoundsException e) {
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   220
                    exc = e;
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   221
                }
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   222
                if (exc == null) {
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   223
                    throw new RuntimeException("expected Exception for force beyond buffer extent");
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   224
                }
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   225
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   226
                exc = null;
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   227
                try {
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   228
                    // start is in range but end is out of range
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   229
                    b.force(offset, 2 * BLOCK_SIZE);
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   230
                } catch (IndexOutOfBoundsException e) {
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   231
                    exc = e;
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   232
                }
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   233
                if (exc == null) {
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   234
                    throw new RuntimeException("expected Exception for force beyond write limit");
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   235
                }
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   236
            }
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   237
        }
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   238
    }
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   239
1b940da275d2 8221696: MappedByteBuffer.force method to specify range
adinn
parents: 47216
diff changeset
   240
    /**
14401
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   241
     * Test exceptions specified by map method
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   242
     */
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   243
    private static void testExceptions() throws Exception {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   244
        // check exceptions when channel opened for read access
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   245
        try (FileChannel fc = FileChannel.open(blah.toPath(), READ)) {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   246
            testExceptions(fc);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   247
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   248
            checkException(fc, MapMode.READ_WRITE, 0L, fc.size(),
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   249
                           NonWritableChannelException.class);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   250
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   251
            checkException(fc, MapMode.READ_WRITE, -1L, fc.size(),
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   252
                           NonWritableChannelException.class, IllegalArgumentException.class);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   253
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   254
            checkException(fc, MapMode.READ_WRITE, 0L, -1L,
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   255
                           NonWritableChannelException.class, IllegalArgumentException.class);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   256
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   257
            checkException(fc, MapMode.PRIVATE, 0L, fc.size(),
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   258
                           NonWritableChannelException.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
14401
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   260
            checkException(fc, MapMode.PRIVATE, -1L, fc.size(),
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   261
                           NonWritableChannelException.class, IllegalArgumentException.class);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   262
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   263
            checkException(fc, MapMode.PRIVATE, 0L, -1L,
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   264
                           NonWritableChannelException.class, IllegalArgumentException.class);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   265
        }
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   266
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   267
        // check exceptions when channel opened for write access
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   268
        try (FileChannel fc = FileChannel.open(blah.toPath(), WRITE)) {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   269
            testExceptions(fc);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   270
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   271
            checkException(fc, MapMode.READ_ONLY, 0L, fc.size(),
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   272
                           NonReadableChannelException.class);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   273
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   274
            checkException(fc, MapMode.READ_ONLY, -1L, fc.size(),
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   275
                           NonReadableChannelException.class, IllegalArgumentException.class);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   276
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   277
            /*
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   278
             * implementation/spec mismatch, these tests disabled for now
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   279
             */
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   280
            //checkException(fc, MapMode.READ_WRITE, 0L, fc.size(),
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   281
            //               NonWritableChannelException.class);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   282
            //checkException(fc, MapMode.PRIVATE, 0L, fc.size(),
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   283
            //               NonWritableChannelException.class);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   284
        }
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   285
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   286
        // check exceptions when channel opened for read and write access
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   287
        try (FileChannel fc = FileChannel.open(blah.toPath(), READ, WRITE)) {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   288
            testExceptions(fc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
14401
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   292
    private static void testExceptions(FileChannel fc) throws IOException {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   293
        checkException(fc, null, 0L, fc.size(),
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   294
                       NullPointerException.class);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   295
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   296
        checkException(fc, MapMode.READ_ONLY, -1L, fc.size(),
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   297
                       IllegalArgumentException.class);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   298
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   299
        checkException(fc, null, -1L, fc.size(),
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   300
                       IllegalArgumentException.class, NullPointerException.class);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   301
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   302
        checkException(fc, MapMode.READ_ONLY, 0L, -1L,
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   303
                       IllegalArgumentException.class);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   304
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   305
        checkException(fc, null, 0L, -1L,
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   306
                       IllegalArgumentException.class, NullPointerException.class);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   307
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   308
        checkException(fc, MapMode.READ_ONLY, 0L, Integer.MAX_VALUE + 1L,
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   309
                       IllegalArgumentException.class);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   310
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   311
        checkException(fc, null, 0L, Integer.MAX_VALUE + 1L,
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   312
                       IllegalArgumentException.class, NullPointerException.class);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   313
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   314
        checkException(fc, MapMode.READ_ONLY, Long.MAX_VALUE, 1L,
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   315
                       IllegalArgumentException.class);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   316
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   317
        checkException(fc, null, Long.MAX_VALUE, 1L,
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   318
                       IllegalArgumentException.class, NullPointerException.class);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   319
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   320
    }
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   321
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   322
    /**
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   323
     * Checks that FileChannel map throws one of the expected exceptions
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   324
     * when invoked with the given inputs.
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   325
     */
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   326
    private static void checkException(FileChannel fc,
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   327
                                       MapMode mode,
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   328
                                       long position,
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   329
                                       long size,
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   330
                                       Class<?>... expected)
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   331
        throws IOException
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   332
    {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   333
        Exception exc = null;
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   334
        try {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   335
            fc.map(mode, position, size);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   336
        } catch (Exception actual) {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   337
            exc = actual;
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   338
        }
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   339
        if (exc != null) {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   340
            for (Class<?> clazz: expected) {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   341
                if (clazz.isInstance(exc)) {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   342
                    return;
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   343
                }
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   344
            }
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   345
        }
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   346
        System.err.println("Expected one of");
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   347
        for (Class<?> clazz: expected) {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   348
            System.out.println(clazz);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   349
        }
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   350
        if (exc == null) {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   351
            throw new RuntimeException("No expection thrown");
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   352
        } else {
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   353
            throw new RuntimeException("Unexpected exception thrown", exc);
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   354
        }
1f9a8607f4df 8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents: 7668
diff changeset
   355
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
}