private void writeObject ( Writable obj ) throws IOException { // For Text and BytesWritable, encode them directly, so that they end up // in C++ as the natural translations. if ( obj instanceof Text ) { Text t = ( Text ) obj ; int len = t . getLength ( ) ; WritableUtils . writeVInt ( stream , len ) ; stream . write ( t . getBytes ( ) , 0 , len ) ; } else if ( obj instanceof BytesWritable ) { BytesWritable b = ( BytesWritable ) obj ; int len = b . getLength ( ) ; WritableUtils . writeVInt ( stream , len ) ; stream . write ( b . getBytes ( ) , 0 , len ) ; } else { buffer . reset ( ) ; obj . write ( buffer ) ; int length = buffer . getLength ( ) ; WritableUtils . writeVInt ( stream , length ) ; stream . write ( buffer . getData ( ) , 0 , length ) ; } }
Write the given object to the stream . If it is a Text or BytesWritable write it directly . Otherwise write it to a buffer and then write the length and data to the stream .