You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mapreduce-commits@hadoop.apache.org by dd...@apache.org on 2009/08/10 19:40:44 UTC
svn commit: r802869 - in /hadoop/mapreduce/trunk: CHANGES.txt
src/contrib/streaming/src/java/org/apache/hadoop/typedbytes/TypedBytesOutput.java
src/contrib/streaming/src/test/org/apache/hadoop/typedbytes/TestIO.java
Author: ddas
Date: Mon Aug 10 17:40:44 2009
New Revision: 802869
URL: http://svn.apache.org/viewvc?rev=802869&view=rev
Log:
MAPREDUCE-808. Fixes a serialization problem in TypedBytes. Contributed by Klaas Bosteels.
Modified:
hadoop/mapreduce/trunk/CHANGES.txt
hadoop/mapreduce/trunk/src/contrib/streaming/src/java/org/apache/hadoop/typedbytes/TypedBytesOutput.java
hadoop/mapreduce/trunk/src/contrib/streaming/src/test/org/apache/hadoop/typedbytes/TestIO.java
Modified: hadoop/mapreduce/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/CHANGES.txt?rev=802869&r1=802868&r2=802869&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/CHANGES.txt (original)
+++ hadoop/mapreduce/trunk/CHANGES.txt Mon Aug 10 17:40:44 2009
@@ -331,3 +331,6 @@
MAPREDUCE-796. Fixes a ClassCastException in an exception log in
MultiThreadedMapRunner. (Amar Kamat via ddas)
+
+ MAPREDUCE-808. Fixes a serialization problem in TypedBytes.
+ (Klaas Bosteels via ddas)
Modified: hadoop/mapreduce/trunk/src/contrib/streaming/src/java/org/apache/hadoop/typedbytes/TypedBytesOutput.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/contrib/streaming/src/java/org/apache/hadoop/typedbytes/TypedBytesOutput.java?rev=802869&r1=802868&r2=802869&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/src/contrib/streaming/src/java/org/apache/hadoop/typedbytes/TypedBytesOutput.java (original)
+++ hadoop/mapreduce/trunk/src/contrib/streaming/src/java/org/apache/hadoop/typedbytes/TypedBytesOutput.java Mon Aug 10 17:40:44 2009
@@ -74,7 +74,7 @@
*/
public void write(Object obj) throws IOException {
if (obj instanceof Buffer) {
- writeBytes(((Buffer) obj).get());
+ writeBytes((Buffer) obj);
} else if (obj instanceof Byte) {
writeByte((Byte) obj);
} else if (obj instanceof Boolean) {
@@ -124,6 +124,21 @@
}
/**
+ * Writes a bytes array as a typed bytes sequence, using a given typecode
+ * and length.
+ *
+ * @param bytes the bytes array to be written
+ * @param code the typecode to use
+ * @param length the number of bytes to write, starting from position 0
+ * @throws IOException
+ */
+ public void writeBytes(byte[] bytes, int code, int length) throws IOException {
+ out.write(code);
+ out.writeInt(length);
+ out.write(bytes, 0, length);
+ }
+
+ /**
* Writes a bytes array as a typed bytes sequence, using a given typecode.
*
* @param bytes the bytes array to be written
@@ -131,9 +146,7 @@
* @throws IOException
*/
public void writeBytes(byte[] bytes, int code) throws IOException {
- out.write(code);
- out.writeInt(bytes.length);
- out.write(bytes);
+ writeBytes(bytes, code, bytes.length);
}
/**
@@ -145,6 +158,16 @@
public void writeBytes(byte[] bytes) throws IOException {
writeBytes(bytes, Type.BYTES.code);
}
+
+ /**
+ * Writes a bytes buffer as a typed bytes sequence.
+ *
+ * @param buffer the bytes buffer to be written
+ * @throws IOException
+ */
+ public void writeBytes(Buffer buffer) throws IOException {
+ writeBytes(buffer.get(), Type.BYTES.code, buffer.getCount());
+ }
/**
* Writes a byte as a typed bytes sequence.
Modified: hadoop/mapreduce/trunk/src/contrib/streaming/src/test/org/apache/hadoop/typedbytes/TestIO.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/contrib/streaming/src/test/org/apache/hadoop/typedbytes/TestIO.java?rev=802869&r1=802868&r2=802869&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/src/contrib/streaming/src/test/org/apache/hadoop/typedbytes/TestIO.java (original)
+++ hadoop/mapreduce/trunk/src/contrib/streaming/src/test/org/apache/hadoop/typedbytes/TestIO.java Mon Aug 10 17:40:44 2009
@@ -75,8 +75,10 @@
Map<Object, Object> map = new HashMap<Object, Object>();
map.put("one", 1);
map.put("vector", vector);
+ Buffer buffer = new Buffer(new byte[] { 1, 2, 3, 4 });
+ buffer.setCapacity(10);
Object[] objects = new Object[] {
- new Buffer(new byte[] { 1, 2, 3, 4 }),
+ buffer,
(byte) 123, true, 12345, 123456789L, (float) 1.2, 1.234,
"random string", vector, list, map
};