2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2001, 2003, Oracle and/or its affiliates. All rights reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
5506
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
2
|
22 |
*/
|
|
23 |
|
|
24 |
/* @test
|
|
25 |
@bug 4434115 4802789
|
|
26 |
* @summary Check for regressions in FileChannel.force
|
|
27 |
*/
|
|
28 |
|
|
29 |
import java.io.*;
|
|
30 |
import java.nio.*;
|
|
31 |
import java.nio.channels.*;
|
|
32 |
|
|
33 |
|
|
34 |
public class Force {
|
|
35 |
public static void main(String[] args) throws Exception {
|
|
36 |
writeAfterForce();
|
|
37 |
forceReadableOnly();
|
|
38 |
}
|
|
39 |
|
|
40 |
// 4434115: FileChannel.write() fails when preceded by force() operation
|
|
41 |
private static void writeAfterForce() throws Exception {
|
|
42 |
byte[] srcData = new byte[20];
|
|
43 |
File blah = File.createTempFile("blah", null);
|
|
44 |
blah.deleteOnExit();
|
|
45 |
FileOutputStream fis = new FileOutputStream(blah);
|
|
46 |
FileChannel fc = fis.getChannel();
|
|
47 |
fc.write(ByteBuffer.wrap(srcData));
|
|
48 |
fc.force(false);
|
|
49 |
fc.write(ByteBuffer.wrap(srcData));
|
|
50 |
fc.close();
|
|
51 |
}
|
|
52 |
|
|
53 |
// 4802789: FileChannel.force(true) throws IOException (windows)
|
|
54 |
private static void forceReadableOnly() throws Exception {
|
|
55 |
File f = File.createTempFile("blah", null);
|
|
56 |
f.deleteOnExit();
|
|
57 |
FileInputStream fis = new FileInputStream(f);
|
|
58 |
FileChannel fc = fis.getChannel();
|
|
59 |
fc.force(true);
|
|
60 |
fc.close();
|
|
61 |
fis.close();
|
|
62 |
}
|
|
63 |
}
|