private void writeDiff(InputStream olderFileIn, InputStream newerFileIn, OutputStream patchOutput) throws IOException {
    if (isCritical()) {
      LOG.info("critical: " + mySource);

      patchOutput.write(RAW);
      Utils.copyStream(newerFileIn, patchOutput);

      return;
    }

    LOG.info(mySource);
    ByteArrayOutputStream diffOutput = new OpenByteArrayOutputStream();
    byte[] newerFileBuffer = JBDiff.bsdiff(olderFileIn, newerFileIn, diffOutput, myPatch.getTimeout());
    diffOutput.close();

    int diffSize = diffOutput.size();
    if (0 < diffSize && diffSize < newerFileBuffer.length) {
      patchOutput.write(COMPRESSED);
      diffOutput.writeTo(patchOutput);
    }
    else {
      patchOutput.write(RAW);
      Utils.writeBytes(newerFileBuffer, newerFileBuffer.length, patchOutput);
      if (diffSize == 0 && newerFileBuffer.length != 0) {
        LOG.warning("*** 'bsdiff' timed out, dumping the file as-is");
      }
    }
  }
private void writeDiff(InputStream olderFileIn, InputStream newerFileIn, OutputStream patchOutput)