8205612: (fc) Files.readAllBytes fails with ClosedByInterruptException when interrupt status set

Reviewed-by: bpb
This commit is contained in:
Alan Bateman 2018-06-26 08:13:02 +01:00
parent 4e844fe623
commit 807c4ae4a3
4 changed files with 233 additions and 46 deletions

View file

@ -77,6 +77,7 @@ import java.util.function.BiPredicate;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import sun.nio.ch.FileChannelImpl;
import sun.nio.fs.AbstractFileSystemProvider;
/**
@ -3203,10 +3204,11 @@ public final class Files {
public static byte[] readAllBytes(Path path) throws IOException {
try (SeekableByteChannel sbc = Files.newByteChannel(path);
InputStream in = Channels.newInputStream(sbc)) {
if (sbc instanceof FileChannelImpl)
((FileChannelImpl) sbc).setUninterruptible();
long size = sbc.size();
if (size > (long)MAX_BUFFER_SIZE)
if (size > (long) MAX_BUFFER_SIZE)
throw new OutOfMemoryError("Required array size too large");
return read(in, (int)size);
}
}