You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apex.apache.org by th...@apache.org on 2016/10/28 23:36:45 UTC

apex-malhar git commit: APEXMALHAR-2229 #resolve Added peek and hasNext methods to FileAccess interface

Repository: apex-malhar
Updated Branches:
  refs/heads/master c4f788d5a -> 27272a588


APEXMALHAR-2229 #resolve Added peek and hasNext methods to FileAccess interface


Project: http://git-wip-us.apache.org/repos/asf/apex-malhar/repo
Commit: http://git-wip-us.apache.org/repos/asf/apex-malhar/commit/27272a58
Tree: http://git-wip-us.apache.org/repos/asf/apex-malhar/tree/27272a58
Diff: http://git-wip-us.apache.org/repos/asf/apex-malhar/diff/27272a58

Branch: refs/heads/master
Commit: 27272a588c9a5c7a8ba8afd2ff5b4572b4a0e05e
Parents: c4f788d
Author: David Yan <da...@datatorrent.com>
Authored: Wed Sep 7 12:54:52 2016 -0700
Committer: Thomas Weise <th...@apache.org>
Committed: Fri Oct 28 16:09:23 2016 -0700

----------------------------------------------------------------------
 .../lib/fileaccess/DTFileReader.java            | 20 +++++++++++++--
 .../datatorrent/lib/fileaccess/FileAccess.java  | 26 ++++++++++++++++++--
 .../datatorrent/lib/fileaccess/TFileReader.java | 19 ++++++++++++--
 3 files changed, 59 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/27272a58/library/src/main/java/com/datatorrent/lib/fileaccess/DTFileReader.java
----------------------------------------------------------------------
diff --git a/library/src/main/java/com/datatorrent/lib/fileaccess/DTFileReader.java b/library/src/main/java/com/datatorrent/lib/fileaccess/DTFileReader.java
index ea8f174..f5b51cf 100644
--- a/library/src/main/java/com/datatorrent/lib/fileaccess/DTFileReader.java
+++ b/library/src/main/java/com/datatorrent/lib/fileaccess/DTFileReader.java
@@ -94,7 +94,7 @@ public class DTFileReader implements FileAccess.FileReader
   }
 
   @Override
-  public boolean next(Slice key, Slice value) throws IOException
+  public boolean peek(Slice key, Slice value) throws IOException
   {
     if (scanner.atEnd()) {
       return false;
@@ -109,7 +109,23 @@ public class DTFileReader implements FileAccess.FileReader
     value.offset = en.getValueOffset();
     value.length = en.getValueLength();
 
-    scanner.advance();
     return true;
   }
+
+  @Override
+  public boolean next(Slice key, Slice value) throws IOException
+  {
+    if (peek(key, value)) {
+      scanner.advance();
+      return true;
+    } else {
+      return false;
+    }
+  }
+
+  @Override
+  public boolean hasNext()
+  {
+    return !scanner.atEnd();
+  }
 }

http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/27272a58/library/src/main/java/com/datatorrent/lib/fileaccess/FileAccess.java
----------------------------------------------------------------------
diff --git a/library/src/main/java/com/datatorrent/lib/fileaccess/FileAccess.java b/library/src/main/java/com/datatorrent/lib/fileaccess/FileAccess.java
index f8dd0be..ebe1ef6 100644
--- a/library/src/main/java/com/datatorrent/lib/fileaccess/FileAccess.java
+++ b/library/src/main/java/com/datatorrent/lib/fileaccess/FileAccess.java
@@ -97,14 +97,28 @@ public interface FileAccess extends Closeable
     void reset() throws IOException;
 
     /**
-     * Searches for a matching key, and positions the pointer before the start of the key.
+     * Searches for the minimum key that is greater than or equal to the given key, and positions the pointer before the start of
+     * that key.
+     *
      * @param key Byte array representing the key
      * @throws IOException
-     * @return true if a given key is found
+     * @return true if the pointer points to a key that equals the given key, false if the key is greater than the given key or if there is no key that is greater than or equal to the key
      */
     boolean seek(Slice key) throws IOException;
 
     /**
+     * Reads the key/value pair starting at the current pointer position
+     * into Slice objects.  If pointer is at the end
+     * of the file, false is returned, and Slice objects remains unmodified.
+     *
+     * @param key Empty slice object
+     * @param value Empty slice object
+     * @return True if key/value were successfully read, false otherwise
+     * @throws IOException
+     */
+    boolean peek(Slice key, Slice value) throws IOException;
+
+    /**
      * Reads next available key/value pair starting from the current pointer position
      * into Slice objects and advances pointer to next key.  If pointer is at the end
      * of the file, false is returned, and Slice objects remains unmodified.
@@ -116,6 +130,14 @@ public interface FileAccess extends Closeable
      */
     boolean next(Slice key, Slice value) throws IOException;
 
+    /**
+     * Returns whether the pointer is at the end of the file
+     *
+     * @return True if the pointer is at the end of the file
+     * @throws IOException
+     */
+    boolean hasNext();
+
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/27272a58/library/src/main/java/com/datatorrent/lib/fileaccess/TFileReader.java
----------------------------------------------------------------------
diff --git a/library/src/main/java/com/datatorrent/lib/fileaccess/TFileReader.java b/library/src/main/java/com/datatorrent/lib/fileaccess/TFileReader.java
index 0f0c92a..4592247 100644
--- a/library/src/main/java/com/datatorrent/lib/fileaccess/TFileReader.java
+++ b/library/src/main/java/com/datatorrent/lib/fileaccess/TFileReader.java
@@ -102,7 +102,7 @@ public class TFileReader implements FileAccess.FileReader
   }
 
   @Override
-  public boolean next(Slice key, Slice value) throws IOException
+  public boolean peek(Slice key, Slice value) throws IOException
   {
     if (scanner.atEnd()) {
       return false;
@@ -121,10 +121,25 @@ public class TFileReader implements FileAccess.FileReader
     value.offset = 0;
     value.length = en.getValueLength();
 
-    scanner.advance();
     return true;
   }
 
+  @Override
+  public boolean next(Slice key, Slice value) throws IOException
+  {
+    if (peek(key, value)) {
+      scanner.advance();
+      return true;
+    } else {
+      return false;
+    }
+  }
+
+  @Override
+  public boolean hasNext()
+  {
+    return !scanner.atEnd();
+  }
 }