Is this true? The fact that SampleValue and Address implement
Serializable should be sufficient to write them out to the stream.
They are not ever written out as keys or values themselves.

On 10/10/07, Matt Kent wrote:
I believe in this case you'll want to make Sample and Address writable as well.
On 10/10/07, Steve Schlosser wrote:
Hello all

Is there a best practice for using my own classes as keys and values?

My first attempt at doing this was successful - I built a
BigIntegerWritable class using IntWritable as a template. It was easy
because BigInteger has methods converting to and from byte arrays,
which I could then write into the DataOutput or read from the

It seems like I should be able to use object serialization to write
to/read from the DataOutput/Input objects and make my own classes
implement the Writable interface. It seems like I should be able to
do something like this:

import java.io.*;

import org.apache.hadoop.io.*;

public class Sample implements Writable {

Address address;
SampleValue value; // sampled value at this point

public Sample(Address a, SampleValue v) {
address = a;
value = v;

public SampleValue getValue() { return value;}
public Address getAddress() { return address; }

public String toString () {
return (address.toString() + " " + value.toString());


public void readFields(DataInput in) throws IOException {
ObjectInputStream oin = new ObjectInputStream((DataInputBuffer)in);

try {
address = (Address)oin.readObject();
value = (SampleValue)oin.readObject();
} catch (ClassNotFoundException e) {
throw new IOException(e.toString());


public void write(DataOutput out) throws IOException {
ObjectOutputStream oout = new ObjectOutputStream((DataOutputBuffer)out);


This code compiles, but throws exceptions at runtime, complaining that
WritableComparator can not access a member of class Sample with
modifiers "". Can someone tell me what this exception is talking

Do I need to implement a WritableComparator for each class that I want
to implement Writable?

Thanks again for the help.


Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 5 of 9 | next ›
Discussion Overview
groupcommon-user @
postedOct 10, '07 at 3:03p
activeOct 11, '07 at 1:29a



site design / logo © 2022 Grokbase