code: private static void writeString(String str, DataOutput writer) throws IOException {
  		if (str == null) {
  			writer.writeByte(0);
  		} else {
  			int blocks = str.length() >> 15;
  			// Use smallest number of bytes possible for number of blocks.
  			if (blocks > 0x3FFFFF) {
  				// Need 4 bytes
  				writer.writeByte(0xc0 | (blocks >> 24));
  				writer.writeByte(0xFF & (blocks >> 16));
  				writer.writeByte(0xFF & (blocks >> 8));
  			} else if (blocks > 0x3FFF) {
  				// Need 3 bytes
  				writer.writeByte(0x80 | (blocks >> 16));
  				writer.writeByte(0xFF & (blocks >> 8));
  			} else if (blocks > 0x3F) {
  				// Need 2 bytes
  				writer.writeByte(0x40 | (blocks >> 8));
  			}
  			// Need to add 1 to number of blocks to avoid confusion with 'null'
  			writer.writeByte(0xFF & (blocks+1));
  			int end = 0;
  			for (int i=0; i<blocks; i++) {
  				int start = end;
  				end = (i+1)<<15;
  				writer.writeUTF(str.substring(start, end));
  			}
  			writer.writeUTF(str.substring(end));
  		}
  	}
docs: /*
  Serialize string. Need to take care of <code>null</code> value since
  {@link DataOutput#writeUTF(String)} does not handle it.