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 ac...@apache.org on 2012/03/10 02:56:36 UTC
svn commit: r1299142 - in /hadoop/common/branches/branch-1: CHANGES.txt
src/contrib/streaming/src/java/org/apache/hadoop/typedbytes/TypedBytesInput.java
src/contrib/streaming/src/test/org/apache/hadoop/typedbytes/TestIO.java
Author: acmurthy
Date: Sat Mar 10 01:56:36 2012
New Revision: 1299142
URL: http://svn.apache.org/viewvc?rev=1299142&view=rev
Log:
MAPREDUCE-764. Fix TypedBytesInput.readRaw to preserve custom type codes. Contributed by Klaas Bosteels.
Modified:
hadoop/common/branches/branch-1/CHANGES.txt
hadoop/common/branches/branch-1/src/contrib/streaming/src/java/org/apache/hadoop/typedbytes/TypedBytesInput.java
hadoop/common/branches/branch-1/src/contrib/streaming/src/test/org/apache/hadoop/typedbytes/TestIO.java
Modified: hadoop/common/branches/branch-1/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/CHANGES.txt?rev=1299142&r1=1299141&r2=1299142&view=diff
==============================================================================
--- hadoop/common/branches/branch-1/CHANGES.txt (original)
+++ hadoop/common/branches/branch-1/CHANGES.txt Sat Mar 10 01:56:36 2012
@@ -190,6 +190,9 @@ Release 1.0.2 - unreleased
HDFS-3006. In WebHDFS, when the return body is empty, set the Content-Type
to application/octet-stream instead of application/json. (szetszwo)
+ MAPREDUCE-764. Fix TypedBytesInput.readRaw to preserve custom type codes.
+ (Klaas Bosteels via acmurthy)
+
Release 1.0.1 - 2012.02.14
NEW FEATURES
Modified: hadoop/common/branches/branch-1/src/contrib/streaming/src/java/org/apache/hadoop/typedbytes/TypedBytesInput.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/src/contrib/streaming/src/java/org/apache/hadoop/typedbytes/TypedBytesInput.java?rev=1299142&r1=1299141&r2=1299142&view=diff
==============================================================================
--- hadoop/common/branches/branch-1/src/contrib/streaming/src/java/org/apache/hadoop/typedbytes/TypedBytesInput.java (original)
+++ hadoop/common/branches/branch-1/src/contrib/streaming/src/java/org/apache/hadoop/typedbytes/TypedBytesInput.java Sat Mar 10 01:56:36 2012
@@ -149,7 +149,7 @@ public class TypedBytesInput {
} else if (code == Type.MARKER.code) {
return null;
} else if (50 <= code && code <= 200) { // application-specific typecodes
- return readRawBytes();
+ return readRawBytes(code);
} else {
throw new RuntimeException("unknown type");
}
@@ -202,14 +202,15 @@ public class TypedBytesInput {
}
/**
- * Reads the raw bytes following a <code>Type.BYTES</code> code.
+ * Reads the raw bytes following a custom code.
+ * @param code the custom type code
* @return the obtained bytes sequence
* @throws IOException
*/
- public byte[] readRawBytes() throws IOException {
+ public byte[] readRawBytes(int code) throws IOException {
int length = in.readInt();
byte[] bytes = new byte[5 + length];
- bytes[0] = (byte) Type.BYTES.code;
+ bytes[0] = (byte) code;
bytes[1] = (byte) (0xff & (length >> 24));
bytes[2] = (byte) (0xff & (length >> 16));
bytes[3] = (byte) (0xff & (length >> 8));
@@ -217,6 +218,15 @@ public class TypedBytesInput {
in.readFully(bytes, 5, length);
return bytes;
}
+
+ /**
+ * Reads the raw bytes following a <code>Type.BYTES</code> code.
+ * @return the obtained bytes sequence
+ * @throws IOException
+ */
+ public byte[] readRawBytes() throws IOException {
+ return readRawBytes(Type.BYTES.code);
+ }
/**
* Reads the byte following a <code>Type.BYTE</code> code.
Modified: hadoop/common/branches/branch-1/src/contrib/streaming/src/test/org/apache/hadoop/typedbytes/TestIO.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1/src/contrib/streaming/src/test/org/apache/hadoop/typedbytes/TestIO.java?rev=1299142&r1=1299141&r2=1299142&view=diff
==============================================================================
--- hadoop/common/branches/branch-1/src/contrib/streaming/src/test/org/apache/hadoop/typedbytes/TestIO.java (original)
+++ hadoop/common/branches/branch-1/src/contrib/streaming/src/test/org/apache/hadoop/typedbytes/TestIO.java Sat Mar 10 01:56:36 2012
@@ -27,6 +27,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@@ -125,6 +126,24 @@ public class TestIO extends TestCase {
istream.close();
}
+ public void testCustomTypesIO() throws IOException {
+ byte[] rawBytes = new byte[] { 100, 0, 0, 0, 3, 1, 2, 3 };
+
+ FileOutputStream ostream = new FileOutputStream(tmpfile);
+ DataOutputStream dostream = new DataOutputStream(ostream);
+ TypedBytesOutput out = new TypedBytesOutput(dostream);
+ out.writeRaw(rawBytes);
+ dostream.close();
+ ostream.close();
+
+ FileInputStream istream = new FileInputStream(tmpfile);
+ DataInputStream distream = new DataInputStream(istream);
+ TypedBytesInput in = new TypedBytesInput(distream);
+ assertTrue(Arrays.equals(rawBytes, in.readRaw()));
+ distream.close();
+ istream.close();
+ }
+
public void testRecordIO() throws IOException {
RecRecord1 r1 = new RecRecord1();
r1.setBoolVal(true);