test/jdk/java/io/FileDescriptor/Finalize.java
author dholmes
Wed, 06 Nov 2019 21:18:42 -0500
changeset 58956 9a0a5e70eeb2
parent 47216 71c04702a3d5
permissions -rw-r--r--
8233454: Test fails with assert(!is_init_completed(), "should only happen during init") after JDK-8229516 Reviewed-by: jiefu, dcubed
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) 2006, 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
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @bug 6322678
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @summary Test for making sure that FIS/FOS.finalize() will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *          not disturb the FD that is still in use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.nio.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.nio.channels.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
public class Finalize {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    static byte data[] = new byte[] {48, 49, 50, 51, 52, 53, 54, 55, 56, 57,};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    static String inFileName = "fd-in-test.txt";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    static String outFileName = "fd-out-test.txt";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    static File inFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    static File outFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    public static void main(String[] args)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
                throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        Thread.sleep(5000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        inFile= new File(System.getProperty("test.dir", "."),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
                        inFileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        inFile.createNewFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        inFile.deleteOnExit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        writeToInFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        doFileInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        outFile  = new File(System.getProperty("test.dir", "."),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                        outFileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        outFile.createNewFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        outFile.deleteOnExit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        doFileOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        doRandomAccessFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        doFileChannel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static void doFileInputStream() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        /* Create initial FIS for file */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        FileInputStream fis1 = new FileInputStream(inFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
       /* Get the FileDescriptor from the fis */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
       FileDescriptor fd = fis1.getFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
         * Create a new FIS based on the existing FD
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
         *    (so the two FIS's share the same native fd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        FileInputStream fis2 = new FileInputStream(fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        /* allow fis1 to be gc'ed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        fis1 = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        int ret = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        /* encourage gc */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        System.gc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        Thread.sleep(200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        while((ret = fis2.read()) != -1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
             * read from fis2 - when fis1 is gc'ed and finalizer is run,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
             * read should not fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            System.out.println("read from fis2:" + ret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        fis2.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private static void writeToInFile() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        FileOutputStream out = new FileOutputStream(inFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        out.write(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        out.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private static void doFileOutputStream()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        System.out.println("--------FileOutputStream Test Started----------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
       /*Create initial FIS for file */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        FileOutputStream fos1 = new FileOutputStream(outFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
       /* Get the FileDescriptor from the fos */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        FileDescriptor fd = fos1.getFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        FileOutputStream fos2 = new FileOutputStream(fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        /* allow fos1 to be gc'ed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        fos1 = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        /* encourage gc */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        System.gc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        Thread.sleep(200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
         * write to fos2 - when fos1 is gc'ed and finalizer is run,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
         * write to fos2 should not fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        fos2.write(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        System.out.println("wrote:" + data.length + " bytes to fos2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        fos2.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        System.out.println("--------FileOutputStream Test Over----------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    private static void doRandomAccessFile()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        System.out.println("--------RandomAccessFile Read Test Started----------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        // Create initial FIS for file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        RandomAccessFile raf = new RandomAccessFile(inFile, "r");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        /* Get the FileDescriptor from the fis */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        FileDescriptor fd = raf.getFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        /* Create a new FIS based on the existing FD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
         * (so the two FIS's share the same native fd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        FileInputStream fis = new FileInputStream(fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
       /* allow fis to be gc'ed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        fis = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        int ret = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        /* encourage gc */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        System.gc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        Thread.sleep(50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
         * read from raf - when fis is gc'ed and finalizer is run,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
         * read from raf should not fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        while((ret = raf.read()) != -1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            System.out.println("read from raf:" + ret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        raf.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        Thread.sleep(200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        System.out.println("--------RandomAccessFile Write Test Started----------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        raf = new RandomAccessFile(outFile, "rw");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        fd = raf.getFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        FileOutputStream fos = new FileOutputStream(fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        /* allow fos to be gc'ed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        fos = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        /* encourage gc */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        System.gc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        Thread.sleep(200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
         * write to raf - when fos is gc'ed and finalizer is run,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
         * write to raf should not fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        raf.write(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        System.out.println("wrote:" + data.length + " bytes to raf");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        raf.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        System.out.println("--------RandomAccessFile Write Test Over----------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     private static void doFileChannel() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        System.out.println("--------FileChannel Read Test Started----------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        FileInputStream fis1 = new FileInputStream(inFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        /* Get the FileDescriptor from the fis */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        FileDescriptor fd = fis1.getFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        /* Create a new FIS based on the existing FD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
         * (so the two FIS's share the same native fd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        FileInputStream fis2 = new FileInputStream(fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        FileChannel fc2 = fis2.getChannel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
         * Encourage the GC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        fis1 = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        System.gc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        Thread.sleep(200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        int ret = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        ByteBuffer bb = ByteBuffer.allocateDirect(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        ret = fc2.read(bb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        System.out.println("read " + ret + " bytes from fc2:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        fc2.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        System.out.println("--------FileChannel Read Test Over----------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        System.out.println("--------FileChannel Write Test Started----------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        FileOutputStream fos1 = new FileOutputStream(outFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
       /* Get the FileDescriptor from the fos */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        fd = fos1.getFD();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        FileOutputStream fos2 = new FileOutputStream(fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        fc2 = fos2.getChannel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
         * Encourage the GC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        fos1 = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        System.gc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        Thread.sleep(200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
         * write to fc2 - when fos1 is gc'ed and finalizer is run,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
         * write to fc2 should not fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
         */
27292
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 5506
diff changeset
   248
        bb = ByteBuffer.allocateDirect(data.length)
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 5506
diff changeset
   249
                       .put(data)
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 5506
diff changeset
   250
                       .flip();
7ff4b24b33ce 4774077: Use covariant return types in the NIO buffer hierarchy
rwarburton
parents: 5506
diff changeset
   251
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        ret = fc2.write(bb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        System.out.println("Wrote:" +  ret + " bytes to fc2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        fc2.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        System.out.println("--------Channel Write Test Over----------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
}