提交 fca64be7 编写于 作者: D darcy

7013420: Project Coin: remove general expression support from try-with-resources statement

Reviewed-by: alanb
上级 9babcaf2
/* /*
* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -58,10 +58,11 @@ public class Truncate { ...@@ -58,10 +58,11 @@ public class Truncate {
for(int i=0; i<100; i++) { for(int i=0; i<100; i++) {
long testSize = generator.nextInt(1000) + 10; long testSize = generator.nextInt(1000) + 10;
initTestFile(blah, testSize); initTestFile(blah, testSize);
FileChannel fc = (i < 50) ?
try (FileChannel fc = (i < 50) ?
new RandomAccessFile(blah, "rw").getChannel() : new RandomAccessFile(blah, "rw").getChannel() :
FileChannel.open(blah.toPath(), READ, WRITE); FileChannel.open(blah.toPath(), READ, WRITE))
try (fc) { {
if (fc.size() != testSize) if (fc.size() != testSize)
throw new RuntimeException("Size failed"); throw new RuntimeException("Size failed");
...@@ -92,10 +93,10 @@ public class Truncate { ...@@ -92,10 +93,10 @@ public class Truncate {
for (int i=0; i<10; i++) { for (int i=0; i<10; i++) {
long testSize = generator.nextInt(1000) + 10; long testSize = generator.nextInt(1000) + 10;
initTestFile(blah, testSize); initTestFile(blah, testSize);
FileChannel fc = (i < 5) ? try (FileChannel fc = (i < 5) ?
new FileOutputStream(blah, true).getChannel() : new FileOutputStream(blah, true).getChannel() :
FileChannel.open(blah.toPath(), APPEND); FileChannel.open(blah.toPath(), APPEND))
try (fc) { {
// truncate file // truncate file
long newSize = generator.nextInt((int)testSize); long newSize = generator.nextInt((int)testSize);
fc.truncate(newSize); fc.truncate(newSize);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册