title: Class file's magic value changes during read/write
body: <p>I'm trying to save java classes into a database. To do so I read files as follows:</p>
  
  <pre><code>bytes = com.google.common.io.ByteStreamsByteStreams.toByteArray(url.openStream());
  </code></pre>
  
  <p>Then, those bytes are encoded in base64:</p>
  
  <pre><code>org.apache.hadoop.hbase.util.Base64.encodeBytes(bytes);
  </code></pre>
  
  <p>When loading them again, the same thing happens vice versa:</p>
  
  <pre><code>org.apache.hadoop.hbase.util.Base64.decode(base64);
  </code></pre>
  
  <p>and its written to a file:</p>
  
  <pre><code>com.google.common.io.Files.write(binary, file);
  </code></pre>
  
  <p>However, source and targe files are not identical. Using a binary file viewer shows that they are indeed very similar; just one thing I spotted: The new file begins with</p>
  
  <pre><code>EF BF BD EF BF BD EF BF BD EF BF BD
  </code></pre>
  
  <p>instead of the expected</p>
  
  <pre><code>CA FE BA BE
  </code></pre>
  
  <p>After that, they're identical for at least a few hundert bytes.</p>
  
  <p>As a logical consequence, I get the following error message when trying to load the class form the new file:</p>
  
  <pre><code>java.lang.ClassFormatError: Incompatible magic value 4022320623 in class file ch/unibe/scg/doodle/producerTest/GiantTurtle
  </code></pre>
  
  <p>I have no idea where it breaks, and it's quite hard to debug. My unit tests for file read/write are green. Where could the problem be?</p>