You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by cu...@apache.org on 2007/02/07 21:39:09 UTC
svn commit: r504680 - in /lucene/hadoop/trunk: CHANGES.txt
src/java/org/apache/hadoop/io/BytesWritable.java
Author: cutting
Date: Wed Feb 7 12:39:08 2007
New Revision: 504680
URL: http://svn.apache.org/viewvc?view=rev&rev=504680
Log:
HADOOP-982. Add some setters and a toString() method to BytesWritable. Contributed by Owen.
Modified:
lucene/hadoop/trunk/CHANGES.txt
lucene/hadoop/trunk/src/java/org/apache/hadoop/io/BytesWritable.java
Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?view=diff&rev=504680&r1=504679&r2=504680
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Wed Feb 7 12:39:08 2007
@@ -6,6 +6,9 @@
1. HADOOP-975. Separate stdout and stderr from tasks.
(Arun C Murthy via cutting)
+ 2. HADOOP-982. Add some setters and a toString() method to
+ BytesWritable. (omalley via cutting)
+
Branch 0.11 - unreleased
Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/io/BytesWritable.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/io/BytesWritable.java?view=diff&rev=504680&r1=504679&r2=504680
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/io/BytesWritable.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/io/BytesWritable.java Wed Feb 7 12:39:08 2007
@@ -104,7 +104,27 @@
bytes = new_data;
}
}
-
+
+ /**
+ * Set the BytesWritable to the contents of the given newData.
+ * @param newData the value to set this BytesWritable to.
+ */
+ public void set(BytesWritable newData) {
+ set(newData.bytes, 0, newData.size);
+ }
+
+ /**
+ * Set the value to a copy of the given byte range
+ * @param newData the new values to copy in
+ * @param offset the offset in newData to start at
+ * @param length the number of bytes to copy
+ */
+ public void set(byte[] newData, int offset, int length) {
+ setSize(0);
+ setSize(length);
+ System.arraycopy(newData, 0, bytes, 0, size);
+ }
+
// inherit javadoc
public void readFields(DataInput in) throws IOException {
setSize(0); // clear the old data
@@ -144,6 +164,26 @@
return false;
}
+ /**
+ * Generate the stream of bytes as hex pairs separated by ' '.
+ */
+ public String toString() {
+ StringBuffer sb = new StringBuffer(3*size);
+ for (int idx = 0; idx < size; idx++) {
+ // if not the first, put a blank separator in
+ if (idx != 0) {
+ sb.append(' ');
+ }
+ String num = Integer.toHexString((int) bytes[idx]);
+ // if it is only one digit, add a leading 0.
+ if (num.length() < 2) {
+ sb.append('0');
+ }
+ sb.append(num);
+ }
+ return sb.toString();
+ }
+
/** A Comparator optimized for BytesWritable. */
public static class Comparator extends WritableComparator {
public Comparator() {