title: Why is Java/Linux appending 0xa to end of file?
body: <p>I'm writing a file using <code>FileOutputStream</code>, and I'm noticing the hex seems to include a terminating <code>0x0a</code>. Here is the output from the file:</p>
  
  <pre><code>0000000: d100 0b00 0000 4865 6c6c 6f20 776f 726c  ......Hello worl
  0000010: 6429 0043 0500 0000 7072 696e 740a       d).C....print.
  
  (Note hex code comes from vim on Osx Yosimite x64)
  </code></pre>
  
  <p>Notice that the file ends in <code>0x0a</code>. Is this a linux thing (like some sort of EOF character) or is this java/<code>FileOutputStream</code> appending the character?</p>
  
  <p>Edit: Code</p>
  
  <pre><code>public class FileImageOpcodeRenderer implements OpCodeRenderer, AutoCloseable {
    private final FileOutputStream stream;
    private final Iterable&lt;OpCode&gt; opcodes;
    private final List&lt;Byte&gt; data = new ArrayList&lt;&gt;();
  
    public FileImageOpcodeRenderer(Iterable&lt;OpCode&gt; opcodes, String path) {
      this.opcodes = opcodes;
      try {
        this.stream = new FileOutputStream(path);
      } catch (IOException ex) {
        ex.printStackTrace();
  
        throw new CompilerException("Unable to open output file");
      }
    }
  
    public void save() throws Exception {
      List&lt;Byte&gt; renderedContent = renderOpCodes();
      byte[] content = toArray(renderedContent);
      stream.write(content, 0, content.length);
    }
  
    private List&lt;Byte&gt; renderOpCodes() {
      for (OpCode opCode : opcodes) {
        writeInt8(null, opCode.opNumber());
        opCode.render(this);
      }
  
      return this.data;
    }
  
    private byte[] toArray(List&lt;Byte&gt; data) {
      byte[] content = new byte[data.size()];
  
      for (int index = 0; index &lt; data.size(); index++) {
        content[index] = data.get(index);
      }
  
      return content;
    }
  
    @Override
    public void writeInt8(String label, int value) {
      data.add((byte)value);
    }
  
    @Override
    public void writeInt16(String label, int value) {
      writeInt8(null, (byte)(value &amp; 0xFF));
      writeInt8(null, (byte)((value &gt;&gt; 8) &amp; 0xFF));
    }
  
    @Override
    public void writeInt32(String label, int value) {
      writeInt8(null, (byte)(value &amp; 0xFF));
      writeInt8(null, (byte)((value &gt;&gt; 8) &amp; 0xFF));
      writeInt8(null, (byte)((value &gt;&gt; 16) &amp; 0xFF));
      writeInt8(null, (byte)((value &gt;&gt; 24) &amp; 0xFF));
    }
  
    @Override
    public void writeInt64(String label, long value) {
      writeInt8(null, (byte)(value &amp; 0xFF));
      writeInt8(null, (byte)((value &gt;&gt; 8) &amp; 0xFF));
      writeInt8(null, (byte)((value &gt;&gt; 16) &amp; 0xFF));
      writeInt8(null, (byte)((value &gt;&gt; 24) &amp; 0xFF));
      writeInt8(null, (byte)((value &gt;&gt; 32) &amp; 0xFF));
      writeInt8(null, (byte)((value &gt;&gt; 40) &amp; 0xFF));
      writeInt8(null, (byte)((value &gt;&gt; 48) &amp; 0xFF));
      writeInt8(null, (byte)((value &gt;&gt; 56) &amp; 0xFF));
    }
  
    @Override
    public void writeString(String label, String value) {
      writeInt32(null, value.length());
      for (byte letter : value.getBytes()) {
        System.out.println((int)letter);
        writeInt8(null, letter);
      }
    }
  
    @Override
    public void close() throws Exception {
      stream.close();
    }
   }
  </code></pre>
  
  <p>I'm even looking at the raw bytes in <code>save</code> and it ends with <code>0x74</code>, not <code>0x0a</code>.</p>
  
  <p>Update: Moar Code:</p>
  
  <p>So I just wrote this code to load the file in c++:</p>
  
  <pre><code>int main() {
      int fd = open("/Users/sircodesalot/Desktop/image.vbaj", O_RDONLY);
  
      char buffer[256] { };
      int amout = read(fd, buffer, 256);
  
      cout &lt;&lt; amout &lt;&lt; endl;
  
      for (int index = 0; index != 256; ++index) {
          if (index &gt; 0 &amp;&amp; (index % 10 == 0)) cout &lt;&lt; endl;
          cout &lt;&lt; hex &lt;&lt; (int)buffer[index] &lt;&lt; " ";
      }
  
      close(fd);
  }
  </code></pre>
  
  <p>which outputs this:</p>
  
  <pre><code>29
  ffffffd1 0 b 0 0 0 48 65 6c 6c 
  6f 20 77 6f 72 6c 64 29 0 43 
  5 0 0 0 70 72 69 6e 74 0 
  0 0 0 0 0 0 0 0 0 0
  ... (rest of the 256 byte buffer)
  </code></pre>
  
  <p>Look ma, no <code>0xa</code>? What's the deal with that? Maybe some linux convention?</p>