code: private void serializeMasterState(MasterState state, DataOutputStream dos) throws IOException {
  		// magic number for error detection
  		dos.writeInt(MASTER_STATE_MAGIC_NUMBER);
  
  		// for safety, we serialize first into an array and then write the array and its
  		// length into the checkpoint
  		final ByteArrayOutputStream baos = new ByteArrayOutputStream();
  		final DataOutputStream out = new DataOutputStream(baos);
  
  		out.writeInt(state.version());
  		out.writeUTF(state.name());
  
  		final byte[] bytes = state.bytes();
  		out.writeInt(bytes.length);
  		out.write(bytes, 0, bytes.length);
  
  		out.close();
  		byte[] data = baos.toByteArray();
  
  		dos.writeInt(data.length);
  		dos.write(data, 0, data.length);
  	}
docs: ------------------------------------------------------------------------