cloud-storage-contrib-nio: Add support for newFileChannel#4718
Conversation
|
Can you please run this: |
Codecov Report
@@ Coverage Diff @@
## master #4718 +/- ##
============================================
+ Coverage 49.66% 50.35% +0.69%
- Complexity 22706 23667 +961
============================================
Files 2158 2233 +75
Lines 213520 225890 +12370
Branches 24206 24958 +752
============================================
+ Hits 106045 113758 +7713
- Misses 99183 103533 +4350
- Partials 8292 8599 +307
Continue to review full report at Codecov.
|
| * @param path The path to the file to open or create | ||
| * @param options The options specifying how the file should be opened, and whether the {@link | ||
| * FileChannel} should be read-only or write-only. | ||
| * @param attrs (not supported, the values will be ignored) |
There was a problem hiding this comment.
Why the null check for attrs below if this is the case? attrs is optional in File.createFile
There was a problem hiding this comment.
I chose to do so to keep it consistent with the other methods in CloudStorageFileSystemProvider that accept an array of FileAtributes as an input parameter. These do the exact same check, even though the input value is ignored.
(See newByteChannel(...)``createDirectory(...))
Furthermore, newFileChannel method can also be used to read an existing file, so it does not always call File.createFile.
| (CloudStorageWriteChannel) newWriteChannel(path, options); | ||
| return new CloudStorageWriteFileChannel(writeChannel); | ||
| } else { | ||
| CloudStorageReadChannel readChannel = (CloudStorageReadChannel) newReadChannel(path, options); |
There was a problem hiding this comment.
Do you need to cast to a CloudStorageReadChannel here? if not perhaps just do this: new CloudStorageReadFileChannel(newReadChannel(path, options));
There was a problem hiding this comment.
Good point, changed.
| @Override | ||
| public long read(ByteBuffer[] dsts, int offset, int length) throws IOException { | ||
| long res = 0L; | ||
| synchronized (this) { |
There was a problem hiding this comment.
You might as well jut put synchronized in the signature.
| @Override | ||
| public long transferTo(long position, long count, WritableByteChannel target) throws IOException { | ||
| long res = 0L; | ||
| synchronized (this) { |
There was a problem hiding this comment.
synchronized in the signature might be clearer.
|
|
||
| @Override | ||
| public int read(ByteBuffer dst, long position) throws IOException { | ||
| synchronized (this) { |
| public int read(ByteBuffer dst, long position) throws IOException { | ||
| synchronized (this) { | ||
| long originalPosition = position(); | ||
| position(position); |
There was a problem hiding this comment.
Isn't this redundant?
long originalPosition = position();
position(position);
Do we actually need position(position);?
There was a problem hiding this comment.
Yes, we need to position the channel where the read should begin. I've changed the name of the parameter to make it clearer.
| public FileChannel position(long newPosition) throws IOException { | ||
| synchronized (this) { | ||
| checkValid(); | ||
| if (newPosition != position()) { |
There was a problem hiding this comment.
There's a call to checkValid() in position(). We don't need two calls. Perhaps just use writeChannel.position()
There was a problem hiding this comment.
There are other places where the double check happens as well, further down.
There was a problem hiding this comment.
I removed the redundant validation checks and changed the method signatures in this class as well to synchronized.
sduskis
left a comment
There was a problem hiding this comment.
Looking good. I think that my last couple request ought to be done, but once they are, please merge this.
| res += bytesRead; | ||
| } | ||
| } | ||
| position(originalPosition); |
There was a problem hiding this comment.
Please put position(originalPosition) in a finally block.
| long originalPosition = position(); | ||
| position(readFromPosition); | ||
| int res = readChannel.read(dst); | ||
| position(originalPosition); |
There was a problem hiding this comment.
Please put position(originalPosition) in a finally block.
Adds support for the method FileSystemProvider.newFileChannel(Path, Set, FileAttribute...) to Google Cloud Storage nio. This enables, among others, users to use google-cloud-storage-nio with Webflux and MultipartFile upload.
Fixes #4702