title: Generate formatted diff output in Java
body: <p>Are there any libraries out there for Java that will accept two strings, and return a string with formatted output as per the *nix diff command?</p>
  
  <p>e.g. feed in </p>
  
  <pre><code>test 1,2,3,4
  test 5,6,7,8
  test 9,10,11,12
  test 13,14,15,16
  </code></pre>
  
  <p>and </p>
  
  <pre><code>test 1,2,3,4
  test 5,6,7,8
  test 9,10,11,12,13
  test 13,14,15,16
  </code></pre>
  
  <p>as input, and it would give you </p>
  
  <pre><code>test 1,2,3,4                                                    test 1,2,3,4
  test 5,6,7,8                                                    test 5,6,7,8
  test 9,10,11,12                                               | test 9,10,11,12,13
  test 13,14,15,16                                                test 13,14,15,16
  </code></pre>
  
  <p>Exactly the same as if I had passed the files to <code>diff -y expected actual</code></p>
  
  <p>I found <a href="https://stackoverflow.com/questions/132478/how-to-perform-string-diffs-in-java">this question</a>, and it gives some good advice on general libraries for giving you programmatic output, but I'm wanting the straight string results.</p>
  
  <p>I could call <code>diff</code> directly as a system call, but this particular app will be running on unix and windows and I can't be sure that the environment will actually have <code>diff</code> available.</p>