use of org.apache.hadoop.io.BytesWritable in project hadoop by apache.
the class TestTupleWritable method makeRandomWritables.
private Writable[] makeRandomWritables() {
Random r = new Random();
Writable[] writs = { new BooleanWritable(r.nextBoolean()), new FloatWritable(r.nextFloat()), new FloatWritable(r.nextFloat()), new IntWritable(r.nextInt()), new LongWritable(r.nextLong()), new BytesWritable("dingo".getBytes()), new LongWritable(r.nextLong()), new IntWritable(r.nextInt()), new BytesWritable("yak".getBytes()), new IntWritable(r.nextInt()) };
return writs;
}
use of org.apache.hadoop.io.BytesWritable in project hadoop by apache.
the class TestTupleWritable method testNestedIterable.
@Test
public void testNestedIterable() throws Exception {
Random r = new Random();
Writable[] writs = { new BooleanWritable(r.nextBoolean()), new FloatWritable(r.nextFloat()), new FloatWritable(r.nextFloat()), new IntWritable(r.nextInt()), new LongWritable(r.nextLong()), new BytesWritable("dingo".getBytes()), new LongWritable(r.nextLong()), new IntWritable(r.nextInt()), new BytesWritable("yak".getBytes()), new IntWritable(r.nextInt()) };
TupleWritable sTuple = makeTuple(writs);
assertTrue("Bad count", writs.length == verifIter(writs, sTuple, 0));
}
use of org.apache.hadoop.io.BytesWritable in project hadoop by apache.
the class RawBytesInputWriter method writeRawBytes.
private void writeRawBytes(Writable writable) throws IOException {
if (writable instanceof BytesWritable) {
BytesWritable bw = (BytesWritable) writable;
byte[] bytes = bw.getBytes();
int length = bw.getLength();
clientOut.writeInt(length);
clientOut.write(bytes, 0, length);
} else {
bufferOut.reset();
writable.write(bufferDataOut);
byte[] bytes = bufferOut.toByteArray();
clientOut.writeInt(bytes.length);
clientOut.write(bytes);
}
}
use of org.apache.hadoop.io.BytesWritable in project hadoop by apache.
the class RawBytesOutputReader method initialize.
@Override
public void initialize(PipeMapRed pipeMapRed) throws IOException {
super.initialize(pipeMapRed);
clientIn = pipeMapRed.getClientInput();
key = new BytesWritable();
value = new BytesWritable();
}
use of org.apache.hadoop.io.BytesWritable in project hadoop by apache.
the class TextInputWriter method writeUTF8.
// Write an object to the output stream using UTF-8 encoding
protected void writeUTF8(Object object) throws IOException {
byte[] bval;
int valSize;
if (object instanceof BytesWritable) {
BytesWritable val = (BytesWritable) object;
bval = val.getBytes();
valSize = val.getLength();
} else if (object instanceof Text) {
Text val = (Text) object;
bval = val.getBytes();
valSize = val.getLength();
} else {
String sval = object.toString();
bval = sval.getBytes("UTF-8");
valSize = bval.length;
}
clientOut.write(bval, 0, valSize);
}
Aggregations