hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oz...@apache.org
Subject hadoop git commit: HADOOP-10694. Remove synchronized input streams from Writable deserialization. Contributed by Gopal V and Rajesh Balamohan.
Date Wed, 11 May 2016 00:28:34 GMT
Repository: hadoop
Updated Branches:
  refs/heads/branch-2 ba4883443 -> eb4182f8f


HADOOP-10694. Remove synchronized input streams from Writable deserialization. Contributed
by Gopal V and Rajesh Balamohan.

(cherry picked from commit 6e565780315469584c47515be6bd189f07840f1b)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/eb4182f8
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/eb4182f8
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/eb4182f8

Branch: refs/heads/branch-2
Commit: eb4182f8f5f9c4b7d9b108fd887604380948a482
Parents: ba48834
Author: Tsuyoshi Ozawa <ozawa@apache.org>
Authored: Tue May 10 17:27:10 2016 -0700
Committer: Tsuyoshi Ozawa <ozawa@apache.org>
Committed: Tue May 10 17:27:43 2016 -0700

----------------------------------------------------------------------
 .../org/apache/hadoop/io/DataInputBuffer.java   | 81 ++++++++++++++++++--
 1 file changed, 74 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/eb4182f8/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/DataInputBuffer.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/DataInputBuffer.java
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/DataInputBuffer.java
index f0b6726..63c41c2 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/DataInputBuffer.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/DataInputBuffer.java
@@ -18,13 +18,14 @@
 
 package org.apache.hadoop.io;
 
-import java.io.*;
-
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
 
-/** A reusable {@link DataInput} implementation that reads from an in-memory
- * buffer.
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+
+/** A reusable {@link java.io.DataInput} implementation
+ * that reads from an in-memory buffer.
  *
  * <p>This saves memory over creating a new DataInputStream and
  * ByteArrayInputStream each time data is read.
@@ -56,9 +57,75 @@ public class DataInputBuffer extends DataInputStream {
       this.pos = start;
     }
 
-    public byte[] getData() { return buf; }
-    public int getPosition() { return pos; }
-    public int getLength() { return count; }
+    public byte[] getData() {
+      return buf;
+    }
+
+    public int getPosition() {
+      return pos;
+    }
+
+    public int getLength() {
+      return count;
+    }
+
+    /* functions below comes verbatim from
+     hive.common.io.NonSyncByteArrayInputStream */
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int read() {
+      return (pos < count) ? (buf[pos++] & 0xff) : -1;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int read(byte[] b, int off, int len) {
+      if (b == null) {
+        throw new NullPointerException();
+      } else if (off < 0 || len < 0 || len > b.length - off) {
+        throw new IndexOutOfBoundsException();
+      }
+      if (pos >= count) {
+        return -1;
+      }
+      if (pos + len > count) {
+        len = count - pos;
+      }
+      if (len <= 0) {
+        return 0;
+      }
+      System.arraycopy(buf, pos, b, off, len);
+      pos += len;
+      return len;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public long skip(long n) {
+      if (pos + n > count) {
+        n = count - pos;
+      }
+      if (n < 0) {
+        return 0;
+      }
+      pos += n;
+      return n;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int available() {
+      return count - pos;
+    }
   }
 
   private Buffer buffer;


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


Mime
View raw message