title: At what point does wrapping a FileOutputStream with a BufferedOutputStream make sense, in terms of performance?
body: <p>I have a module that is responsible for reading, processing, and writing bytes to disk. The bytes come in over UDP and, after the individual datagrams are assembled, the final byte array that gets processed and written to disk is typically between 200 bytes and 500,000 bytes. Occassionally, there will be byte arrays that, after assembly, are over 500,000 bytes, but these are relatively rare.</p>
  
  <p>I'm currently using the <a href="http://docs.oracle.com/javase/6/docs/api/java/io/FileOutputStream.html" rel="noreferrer"><code>FileOutputStream</code></a>'s <a href="http://docs.oracle.com/javase/6/docs/api/java/io/FileOutputStream.html#write%28byte%5B%5D%29" rel="noreferrer"><code>write(byte\[\])</code> method</a>. I'm also experimenting with wrapping the <code>FileOutputStream</code> in a <a href="http://docs.oracle.com/javase/6/docs/api/java/io/BufferedOutputStream.html" rel="noreferrer"><code>BufferedOutputStream</code></a>, including using <a href="http://docs.oracle.com/javase/6/docs/api/java/io/BufferedOutputStream.html#BufferedOutputStream%28java.io.OutputStream,%20int%29" rel="noreferrer">the constructor that accepts a buffer size as a parameter</a>.</p>
  
  <p>It appears that using the <code>BufferedOutputStream</code> is tending toward slightly better performance, but I've only just begun to experiment with different buffer sizes. I only have a limited set of sample data to work with (two data sets from sample runs that I can pipe through my application). Is there a general rule-of-thumb that I might be able to apply to try to calculate the optimal buffer sizes to reduce disk writes and maximize the performance of the disk writing given the information that I know about the data I'm writing?</p>