public static void writeByteArrayToFile(File file, byte[] data, boolean append) throws IOException {
        OutputStream out = null;
        try {
            out = openOutputStream(file, append);
            out.write(data);
            out.close(); // don't swallow close Exception if copy completes normally
        } finally {
            try {
                if (out != null) {
                    out.close();
                }
            } catch (IOException e) {
                // ignore
            }
        }
    }
Writes a byte array to a file creating the file if it does not exist.

@param file  the file to write to
@param data  the content to write to the file
@param append if {@code true}, then bytes will be added to the
end of the file rather than overwriting
@throws IOException in case of an I/O error
@since IO 2.1
agent/src/main/java/code/landgrey/copagent/utils/PathUtils.java