You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by GitBox <gi...@apache.org> on 2019/03/21 09:28:46 UTC

[GitHub] [hadoop] openinx commented on a change in pull request #597: HDFS-3246: pRead equivalent for direct read path

openinx commented on a change in pull request #597: HDFS-3246: pRead equivalent for direct read path
URL: https://github.com/apache/hadoop/pull/597#discussion_r267674071
 
 

 ##########
 File path: hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoInputStream.java
 ##########
 @@ -341,6 +343,26 @@ public int read(long position, byte[] buffer, int offset, int length)
           "positioned read.");
     }
   }
+
+   /** Positioned read using ByteBuffers. It is thread-safe */
+  @Override
+  public int read(long position, final ByteBuffer buf)
+      throws IOException {
+    checkStream();
+    try {
+      int pos = buf.position();
+      final int n = ((ByteBufferPositionedReadable) in).read(position, buf);
+      if (n > 0) {
+        // This operation does not change the current offset of the file
+        decrypt(position, buf, n, pos);
+      }
+
+      return n;
+    } catch (ClassCastException e) {
 
 Review comment:
   Here we catch the ClassCastException to check whether the inpustream has implemented an ByteBufferPositionedReadable interface ?  I don't think it's a good way, because the catch{...} block need an full stack and not so efficient .  
   How about use the following : 
   
   ```java
   if(in instanceof ByteBufferPositionedReadable){
       //...
   }else{
       throw new UnsupportedOperationException(...)
   }
   ```
    

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org