Convert object attributes to always-same-length string
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/5783393/object-attributes-to-same-length-representation-for-faster-reading">Object attributes to same-length representation for faster reading</a>  </p>
</blockquote>



<p>I want to write my objects to a file where each object's representation is the same length, so I can jump to a section of the file to read without having to read the whole file.</p>

<p>This is necessary as the file will be read by many VMs and will be TBs in size. What's the best way of doing this? I've tried putting them in an array of ints to try to achieve this, but it seems this step must be unnecessary. I am passing each object back one at a time to be written by a different writer object. Cheers</p>

<pre><code>// Convert Person attributes to integers and put in an array
int[] person = new int[8];
person[0] = age;
if (gender.equals("m")) {person[1] = 1;}
else {person[1] = 0;}
person[2] = children;
person[3] = goodHealth? 1:0;
person[4] = cars;
person[5] = avgWeekShopping;
person[6] = salary;
person[7] = smoker? 1:0;

return person;
</code></pre>
