mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
8205612: (fc) Files.readAllBytes fails with ClosedByInterruptException when interrupt status set
Reviewed-by: bpb
This commit is contained in:
parent
4e844fe623
commit
807c4ae4a3
4 changed files with 233 additions and 46 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,18 +25,54 @@
|
|||
|
||||
package java.nio.file.spi;
|
||||
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.*;
|
||||
import java.nio.channels.*;
|
||||
import java.nio.channels.AsynchronousFileChannel;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.SeekableByteChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
import java.nio.file.AccessDeniedException;
|
||||
import java.nio.file.AccessMode;
|
||||
import java.nio.file.AtomicMoveNotSupportedException;
|
||||
import java.nio.file.CopyOption;
|
||||
import java.nio.file.DirectoryNotEmptyException;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.FileAlreadyExistsException;
|
||||
import java.nio.file.FileStore;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystemAlreadyExistsException;
|
||||
import java.nio.file.FileSystemNotFoundException;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.LinkOption;
|
||||
import java.nio.file.LinkPermission;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.NotDirectoryException;
|
||||
import java.nio.file.NotLinkException;
|
||||
import java.nio.file.OpenOption;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.net.URI;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.nio.file.attribute.FileAttribute;
|
||||
import java.nio.file.attribute.FileAttributeView;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ServiceConfigurationError;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
import sun.nio.ch.FileChannelImpl;
|
||||
|
||||
/**
|
||||
* Service-provider class for file systems. The methods defined by the {@link
|
||||
* java.nio.file.Files} class will typically delegate to an instance of this
|
||||
|
@ -381,7 +417,11 @@ public abstract class FileSystemProvider {
|
|||
throw new UnsupportedOperationException("'" + opt + "' not allowed");
|
||||
}
|
||||
}
|
||||
return Channels.newInputStream(Files.newByteChannel(path, options));
|
||||
ReadableByteChannel rbc = Files.newByteChannel(path, options);
|
||||
if (rbc instanceof FileChannelImpl) {
|
||||
((FileChannelImpl) rbc).setUninterruptible();
|
||||
}
|
||||
return Channels.newInputStream(rbc);
|
||||
}
|
||||
|
||||
private static final Set<OpenOption> DEFAULT_OPEN_OPTIONS =
|
||||
|
@ -435,7 +475,11 @@ public abstract class FileSystemProvider {
|
|||
}
|
||||
opts.add(StandardOpenOption.WRITE);
|
||||
}
|
||||
return Channels.newOutputStream(newByteChannel(path, opts));
|
||||
WritableByteChannel wbc = newByteChannel(path, opts);
|
||||
if (wbc instanceof FileChannelImpl) {
|
||||
((FileChannelImpl) wbc).setUninterruptible();
|
||||
}
|
||||
return Channels.newOutputStream(wbc);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue