Package Org.apache.hadoop.io;
Import Java.io.DataOutput;
Import Java.io.DataInput;
Import java.io.IOException;
/**
* A serializable object which implements a simple, efficient,
A serialized object, this guy implements a simple, efficient, serialized protocol that is based on the two IO objects of the datainput and DataOutput
* protocol, based on {@link datainput} and {@link dataoutput}.
*
* <p>any <code>key</code> or <code>value</code> type in the Hadoop map-reduce
Any data based on the Key-value type in the Hadoop map-reduce framework is an implementation of this interface
* Framework implements this interface.</p>
*
* <p>implementations typically implement a static <code>read (datainput) </code>
* Method which constructs a new instance, calls {@link #readFields (datainput)}
* and returns the instance.</p>
*
* <p>Example:</p>
* <p><blockquote><pre>
* Public class Mywritable implements writable {
*//Some data
* Private int counter;
* Private long timestamp;
*
* public void Write (DataOutput out) throws IOException {
* Out.writeint (counter);
* Out.writelong (timestamp);
* }
*
* public void ReadFields (Datainput in) throws IOException {
* counter = In.readint ();
* timestamp = In.readlong ();
* }
*
* public static mywritable read (Datainput in) throws IOException {
* Mywritable w = new mywritable ();
* W.readfields (in);
* Return w;
* }
* }
* </pre></blockquote></p>
*/
Public interface Writable {
/**
* Serialize The fields of this object to <code>out</code>.
*
* @param out <code>DataOuput</code> to serialize this object into.
* @throws IOException
*/
void Write (DataOutput out) throws IOException;
/**
* Deserialize the fields of this object from <code>in</code>.
*
* <p>for efficiency, implementations should attempt to re-use storage in the
* Existing object where possible.</p>
*
* @param in <code>DataInput</code> to deseriablize the object from.
* @throws IOException
*/
void ReadFields (Datainput in) throws IOException;
}
--------------------------------------------------------------------------------------------------------------- --------------------
int
readInt()
Reads four input bytes and returns a int
value.
long
readLong()
Reads eight input bytes and returns a long
value.
--------------------------------------------------------------------------------------------------------------- --------------------
void
writeInt(int v)
Writes a int
value to the output stream, which consists of four bytes.
void
writeLong(long v)
Writes a long
value to the output stream, which consists of eight bytes.
--------------------------------------------------------------------------------------------------------------- --------------------------
/** A polymorphic Writable that writes an instance with it's class name.
* Handles arrays, strings and primitive types without a writable wrapper.
*/
Public class Objectwritable implements writable, configurable {
Private Class Declaredclass;
Private Object instance;
Private Configuration conf;
--------------------------------------------------------------------------------------------------------------- ----------------------------
Writable writable = Writablefactories.newinstance (Instanceclass, conf);
Writable.readfields (in);
instance = writable;
Stepping on the footprints of predecessors to learn hadoop--serialization, writerable