hadoop-common-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yih Sun Khoo" <ysk...@gmail.com>
Subject How do I implement a Writable into another Writable?
Date Sun, 19 Oct 2008 07:30:47 GMT
I don't quite know how to write the read and write functions, but I want to
write my own writable, which should have a DoubleWritable/double value
followed by a list of Strings/Text.  This Writable will be used as a value.
Is the code below the best way to go about writing such a writable?

import java.io.DataInput;
import java.io.DataOutput;
import java.io.EOFException;
import java.io.IOException;
import java.util.ArrayList;

import org.apache.hadoop.io.Writable;

public class MyWritable implements Writable {
    private double score;
    private ArrayList<String> nameList;

    public void setScore(double score) {
        this.score= score;

    public void setNameList(ArrayList<String> nameList) {
        this.nameList= nameList;

    public double getScore() {
        return score;

    public ArrayList<String> getNameList() {
        return nameList;

    public void readFields(DataInput in) throws IOException {
        score= in.readDouble();
        try {
            do {
            } while (true);
        } catch (EOFException eofe) {
            // continue; done

    public void write(DataOutput out) throws IOException {
        for (String name: nameList) {

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message