amaliujia commented on a change in pull request #298:
URL: https://github.com/apache/incubator-ratis/pull/298#discussion_r534451623



##########
File path: 
ratis-examples/src/main/java/org/apache/ratis/examples/filestore/FileStore.java
##########
@@ -219,4 +225,67 @@ public void close() {
     reader.shutdownNow();
     deleter.shutdownNow();
   }
+
+  CompletableFuture<StreamWriteReplyProto> streamCommit(String p, long 
bytesWritten) {
+    return CompletableFuture.supplyAsync(() -> {
+      final Path full = buildFullPath(p);
+      try {
+        RandomAccessFile file = new RandomAccessFile(full.toFile(), "r");
+        long len = file.length();
+        return StreamWriteReplyProto.newBuilder().setIsSuccess(len == 
bytesWritten).setByteWritten(len).build();
+      } catch (FileNotFoundException e) {
+        throw new CompletionException("Failed to find " + p, e);
+      } catch (IOException e) {
+        throw new CompletionException("Failed to get length of " + p, e);

Review comment:
       It will:
   
   `RandomAccessFile file = new RandomAccessFile(full.toFile(), "r");` will 
throw FileNotFoundException, thus match the first exception.
   If the file indeed exists, `file.length();` will give IOException if 
anything wrong, thus hit the second exception.
   
   And exception that is matched first gets executed: 
https://stackoverflow.com/questions/10964882/order-of-catching-exceptions-in-java#:~:text=The%20order%20is%20whatever%20matches,is%20matched%20or%20none%20are.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to